[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EN0MFN0Z55E5WAWSBQMQQ4":3,"skill-same:01M6EN0MFN0Z55E5WAWSBQMQQ4":85},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":6,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6EN0MFN0Z55E5WAWSBQMQQ4","api-organization",null,"Explains the standardized API organization pattern for this codebase. Use when creating new API endpoints, API clients, or modifying existing API structure. Covers the 5-file system (endpoint-types, endpoints, api-client, admin-api-client, protected-endpoints), role-based access patterns (admin vs regular users), and TypeScript type safety across the API layer. All API code lives in src\u002Flib\u002Fapi\u002F following this exact pattern.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbom-98\u002Fapi-organization\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"api organization","api","organization","use","types","api-client","lib","across","pattern","structure","patterns","typescript","system","src","access","Safety","endpoint","Type Safety","file","code","2026-11-10 10:12:30",false,"---\nname: api-organization\ndescription: Explains the standardized API organization pattern for this codebase. Use when creating new API endpoints, API clients, or modifying existing API structure. Covers the 5-file system (endpoint-types, endpoints, api-client, admin-api-client, protected-endpoints), role-based access patterns (admin vs regular users), and TypeScript type safety across the API layer. All API code lives in src\u002Flib\u002Fapi\u002F following this exact pattern.\n---\n\n# API Organization Pattern\n\nThis skill defines the standardized API organization pattern used throughout this codebase. All external API integrations follow the same 5-file structure for consistency, type safety, and maintainability.\n\n## When to Use This Skill\n\nUse this skill when:\n- Creating new API endpoints or integrations\n- Adding new API categories or domains\n- Implementing role-based API access (admin vs regular users)\n- Modifying existing API structure\n- Setting up authentication for API calls\n- Creating type-safe API wrappers\n\n## Core Principles\n\n1. **Single Source of Truth** - All API URLs defined once in `endpoints.ts`\n2. **Type Safety** - Full TypeScript coverage from params to responses\n3. **Role-Based Access** - Separate clients for regular vs admin endpoints\n4. **Centralized Auth** - Authentication handled automatically by clients\n5. **DRY Code** - Reusable client functions, no duplicate endpoint definitions\n\n## The 5-File System\n\nAll API code lives in `src\u002Flib\u002Fapi\u002F` with exactly these files:\n\n```\nsrc\u002Flib\u002Fapi\u002F\n├── endpoint-types.ts       # TypeScript types for all endpoints\n├── endpoints.ts            # URL definitions organized by domain\n├── api-client.ts           # Generic authenticated API client\n├── admin-api-client.ts     # Admin-only API client with role checks\n└── protected-endpoints.ts  # Type-safe wrapper functions\n```\n\n### File Purposes\n\n**1. endpoint-types.ts**\n- Define all TypeScript interfaces for API data\n- Organize types by domain (e.g., audiences, instances, membership)\n- Include param types, response types, and request body DTOs\n- Provide utility types for extracting types\n\nSee `references\u002Fendpoint-types-pattern.md` for detailed structure.\n\n**2. endpoints.ts**\n- Define all API endpoint URLs in one place\n- Organize by feature\u002Fdomain matching types\n- Use functions that accept parameters and return URLs\n- Support environment variable base URLs\n\nSee `references\u002Fendpoints-pattern.md` for detailed structure.\n\n**3. api-client.ts**\n- Generic API client with automatic authentication\n- Error parsing and handling\n- Support for GET, POST, PUT, DELETE methods\n- Server-side only ('use server')\n\nSee `references\u002Fapi-client-pattern.md` for implementation.\n\n**4. admin-api-client.ts**\n- Admin-specific API client\n- Role validation (Admin\u002FSuperAdmin groups)\n- Permission checking functions\n- Throws AdminAuthError if unauthorized\n\nSee `references\u002Fadmin-api-client-pattern.md` for implementation.\n\n**5. protected-endpoints.ts**\n- Type-safe wrapper functions combining URLs + types + clients\n- Organized to match endpoint-types structure\n- Provides clean import: `import { api } from '@\u002Flib\u002Fapi\u002Fprotected-endpoints'`\n- No 'use server' directive (exports objects)\n\nSee `references\u002Fprotected-endpoints-pattern.md` for detailed structure.\n\n## Authentication System\n\nThis application uses **Supabase Auth** for authentication. All API requests require authentication via Supabase access tokens.\n\n### Supabase Client Structure\n```\nsrc\u002Flib\u002Fsupabase\u002F\n├── client.ts      # Browser-side Supabase client\n├── server.ts      # Server-side Supabase client (RSC, Server Actions)\n└── middleware.ts  # Middleware helper for auth cookie refresh\n```\n\n### Auth Flow\n1. User authenticates via Supabase (email\u002Fpassword, OAuth, etc.)\n2. Supabase stores session in httpOnly cookies\n3. Middleware refreshes session on every request\n4. Server components\u002Factions use `createClient()` from `server.ts`\n5. API client extracts access token from session automatically\n\nSee `references\u002Fsupabase-auth-integration.md` for detailed implementation.\n\n## Role-Based Access Pattern\n\n### Regular User Endpoints\nUse `api-client.ts` functions with automatic Supabase auth:\n```typescript\nimport { apiGet, apiPost } from '@\u002Flib\u002Fapi\u002Fapi-client';\n\n\u002F\u002F Access token extracted from Supabase session automatically\nconst data = await apiGet\u003CResponseType>(url);\n```\n\n### Admin-Only Endpoints\nUse `admin-api-client.ts` functions with role validation:\n```typescript\nimport { adminApiRequest, checkAdminPermission } from '@\u002Flib\u002Fapi\u002Fadmin-api-client';\n\n\u002F\u002F Validate admin access first (checks user role from database)\nawait checkAdminPermission(); \u002F\u002F Throws if not admin\n\n\u002F\u002F Make admin API request\nconst data = await adminApiRequest\u003CResponseType>(url, options);\n```\n\n### Admin Roles\nAdmin roles are stored in the `users` table:\n- `users.role` = `'admin'` - Standard admin access\n- `users.role` = `'member'` - Regular user access\n\nFirst user in a family is automatically assigned admin role.\n\n## Adding New API Endpoints\n\nFollow this exact order when integrating a new API into the application:\n\n### Step 1: Define Types in endpoint-types.ts\n\n```typescript\n\u002F\u002F 1. Define response type(s)\nexport interface ResourceItem {\n  id: string;\n  name: string;\n  \u002F\u002F ... other fields from your API response\n}\n\n\u002F\u002F 2. Define request DTO(s) for mutations\nexport interface CreateResourceDto {\n  name: string;\n  \u002F\u002F ... fields required to create\n}\n\n\u002F\u002F 3. Add parameter types to EndpointParams interface\nexport interface EndpointParams {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    list: void;              \u002F\u002F No params needed\n    get: { id: string };     \u002F\u002F Requires ID\n    create: void;            \u002F\u002F Body in request, not params\n    update: { id: string };\n    delete: { id: string };\n  };\n}\n\n\u002F\u002F 4. Add response types to EndpointResponses interface\nexport interface EndpointResponses {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    list: ResourceItem[];\n    get: ResourceItem;\n    create: ResourceItem;\n    update: ResourceItem;\n    delete: void;\n  };\n}\n\n\u002F\u002F 5. Add request body types to EndpointBodies interface (if needed)\nexport interface EndpointBodies {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    create: CreateResourceDto;\n    update: CreateResourceDto;\n  };\n}\n```\n\n### Step 2: Define URLs in endpoints.ts\n\n```typescript\nexport const API_ENDPOINTS = {\n  \u002F\u002F ... existing categories\n\n  resources: {\n    list: () => `${API_BASE}\u002Fapi\u002Fresources`,\n    get: (id: string) => `${API_BASE}\u002Fapi\u002Fresources\u002F${id}`,\n    create: () => `${API_BASE}\u002Fapi\u002Fresources`,\n    update: (id: string) => `${API_BASE}\u002Fapi\u002Fresources\u002F${id}`,\n    delete: (id: string) => `${API_BASE}\u002Fapi\u002Fresources\u002F${id}`,\n  },\n};\n```\n\n### Step 3: Add Wrapper in protected-endpoints.ts\n\n```typescript\nexport const api = {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    async list(): Promise\u003CResourceItem[]> {\n      return apiGet\u003CResourceItem[]>(\n        API_ENDPOINTS.resources.list()\n      );\n    },\n\n    async get(id: string): Promise\u003CResourceItem> {\n      return apiGet\u003CResourceItem>(\n        API_ENDPOINTS.resources.get(id)\n      );\n    },\n\n    async create(data: CreateResourceDto): Promise\u003CResourceItem> {\n      return apiPost\u003CResourceItem, CreateResourceDto>(\n        API_ENDPOINTS.resources.create(),\n        data\n      );\n    },\n\n    async update(id: string, data: CreateResourceDto): Promise\u003CResourceItem> {\n      return apiPut\u003CResourceItem, CreateResourceDto>(\n        API_ENDPOINTS.resources.update(id),\n        data\n      );\n    },\n\n    async delete(id: string): Promise\u003Cvoid> {\n      return apiDelete\u003Cvoid>(\n        API_ENDPOINTS.resources.delete(id)\n      );\n    },\n  },\n};\n```\n\n### Step 4: Use in Application Code\n\n```typescript\n'use server';\n\nimport { api } from '@\u002Flib\u002Fapi\u002Fprotected-endpoints';\n\n\u002F\u002F In a server component or server action\nconst resources = await api.resources.list();\nconst resource = await api.resources.get(id);\nconst newResource = await api.resources.create({\n  name: 'New Resource'\n});\n```\n\n## Naming Conventions\n\n### Endpoint Operations\n- `list` \u002F `listAll` - GET multiple items\n- `get` - GET single item\n- `create` - POST new item\n- `update` - PUT\u002FPATCH existing item\n- `delete` - DELETE item\n\n### Type Naming\n- Response types: PascalCase describing entity (e.g., `AudienceListItem`)\n- DTOs: PascalCase with suffix (e.g., `CreateUserDto`, `UpdateSettingsDto`)\n- Interfaces match plural for collections, singular for items\n\n## Error Handling\n\nAll API clients handle errors automatically:\n\n```typescript\ntry {\n  const data = await api.myFeature.get(id);\n} catch (error) {\n  \u002F\u002F Error already parsed and formatted\n  console.error('API error:', error.message);\n}\n```\n\nCommon error types:\n- `AdminAuthError` - Admin permission denied\n- `AdminApiError` - Admin API request failed\n- Generic errors from `api-client` with parsed messages\n\n## Authentication Flow\n\n### Regular Endpoints\n1. Client calls protected endpoint wrapper (e.g., `api.resources.list()`)\n2. Wrapper calls apiGet\u002FapiPost\u002Fetc from api-client\n3. api-client calls `getAuthHeaders()`\n4. getAuthHeaders uses Supabase server client to get session:\n   ```typescript\n   const supabase = await createClient();\n   const { data: { session } } = await supabase.auth.getSession();\n   const accessToken = session?.access_token;\n   ```\n5. Access token added to Authorization header\n6. Request sent with automatic authentication\n\n### Admin Endpoints\nSame flow as above, but with additional role check:\n1. Call `checkAdminPermission()` first\n2. checkAdminPermission queries `users` table for current user's role\n3. Throws `AdminAuthError` if role is not 'admin'\n4. Then proceeds with normal authentication flow\n\n## Best Practices\n\n1. **Never hardcode URLs** - Always use `API_ENDPOINTS`\n2. **Always define types first** - Types drive implementation\n3. **One wrapper per endpoint** - Keep protected-endpoints clean\n4. **Group by domain** - Match structure across all 5 files\n5. **Use helper functions** - `apiGet`, `apiPost`, etc. handle auth\n6. **Validate admin access early** - Call `checkAdminPermission()` first\n7. **Document complex endpoints** - Add JSDoc comments\n8. **Handle errors gracefully** - API clients provide good error messages\n\n## Environment Variables\n\n### Required for Supabase Auth\n- `NEXT_PUBLIC_SUPABASE_URL` - Supabase project URL\n- `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY` - Supabase anonymous public key\n\n### Required for API Clients\n- `INSTANCE_API_URL` or `API_URL` - Base URL for external API endpoints\n- `NEXT_PUBLIC_SITE_URL` - Site URL for redirects (optional, defaults to localhost:3000)\n\n### Database\n- Supabase connection is handled automatically via the Supabase client\n- No manual connection strings needed\n\n## Migration from Other Patterns\n\nIf migrating existing API code to this pattern:\n\n1. Extract all endpoint URLs to `endpoints.ts`\n2. Create types in `endpoint-types.ts` for params\u002Fresponses\n3. Replace direct fetch calls with `apiGet`\u002F`apiPost`\u002Fetc\n4. Add wrappers to `protected-endpoints.ts`\n5. Update imports to use `api` object\n\nExample migration:\n```typescript\n\u002F\u002F Before (scattered fetch calls)\nconst response = await fetch(`${API_BASE}\u002Fapi\u002Fresources\u002F${id}`, {\n  headers: { Authorization: `Bearer ${token}` }\n});\nconst resource = await response.json();\n\n\u002F\u002F After (centralized pattern)\nimport { api } from '@\u002Flib\u002Fapi\u002Fprotected-endpoints';\nconst resource = await api.resources.get(id); \u002F\u002F Auth automatic, types included\n```\n\n## References\n\nSee reference files for detailed implementation patterns:\n- `references\u002Fsupabase-auth-integration.md` - Supabase auth setup and integration\n- `references\u002Fendpoint-types-pattern.md` - Type definition structure\n- `references\u002Fendpoints-pattern.md` - URL organization pattern\n- `references\u002Fapi-client-pattern.md` - Generic client implementation with Supabase\n- `references\u002Fadmin-api-client-pattern.md` - Admin client with role-based access\n- `references\u002Fprotected-endpoints-pattern.md` - Wrapper function patterns\n","# API Organization Pattern\n\nThis skill defines the standardized API organization pattern used throughout this codebase. All external API integrations follow the same 5-file structure for consistency, type safety, and maintainability.\n\n## When to Use This Skill\n\nUse this skill when:\n- Creating new API endpoints or integrations\n- Adding new API categories or domains\n- Implementing role-based API access (admin vs regular users)\n- Modifying existing API structure\n- Setting up authentication for API calls\n- Creating type-safe API wrappers\n\n## Core Principles\n\n1. **Single Source of Truth** - All API URLs defined once in `endpoints.ts`\n2. **Type Safety** - Full TypeScript coverage from params to responses\n3. **Role-Based Access** - Separate clients for regular vs admin endpoints\n4. **Centralized Auth** - Authentication handled automatically by clients\n5. **DRY Code** - Reusable client functions, no duplicate endpoint definitions\n\n## The 5-File System\n\nAll API code lives in `src\u002Flib\u002Fapi\u002F` with exactly these files:\n\n```\nsrc\u002Flib\u002Fapi\u002F\n├── endpoint-types.ts       # TypeScript types for all endpoints\n├── endpoints.ts            # URL definitions organized by domain\n├── api-client.ts           # Generic authenticated API client\n├── admin-api-client.ts     # Admin-only API client with role checks\n└── protected-endpoints.ts  # Type-safe wrapper functions\n```\n\n### File Purposes\n\n**1. endpoint-types.ts**\n- Define all TypeScript interfaces for API data\n- Organize types by domain (e.g., audiences, instances, membership)\n- Include param types, response types, and request body DTOs\n- Provide utility types for extracting types\n\nSee `references\u002Fendpoint-types-pattern.md` for detailed structure.\n\n**2. endpoints.ts**\n- Define all API endpoint URLs in one place\n- Organize by feature\u002Fdomain matching types\n- Use functions that accept parameters and return URLs\n- Support environment variable base URLs\n\nSee `references\u002Fendpoints-pattern.md` for detailed structure.\n\n**3. api-client.ts**\n- Generic API client with automatic authentication\n- Error parsing and handling\n- Support for GET, POST, PUT, DELETE methods\n- Server-side only ('use server')\n\nSee `references\u002Fapi-client-pattern.md` for implementation.\n\n**4. admin-api-client.ts**\n- Admin-specific API client\n- Role validation (Admin\u002FSuperAdmin groups)\n- Permission checking functions\n- Throws AdminAuthError if unauthorized\n\nSee `references\u002Fadmin-api-client-pattern.md` for implementation.\n\n**5. protected-endpoints.ts**\n- Type-safe wrapper functions combining URLs + types + clients\n- Organized to match endpoint-types structure\n- Provides clean import: `import { api } from '@\u002Flib\u002Fapi\u002Fprotected-endpoints'`\n- No 'use server' directive (exports objects)\n\nSee `references\u002Fprotected-endpoints-pattern.md` for detailed structure.\n\n## Authentication System\n\nThis application uses **Supabase Auth** for authentication. All API requests require authentication via Supabase access tokens.\n\n### Supabase Client Structure\n```\nsrc\u002Flib\u002Fsupabase\u002F\n├── client.ts      # Browser-side Supabase client\n├── server.ts      # Server-side Supabase client (RSC, Server Actions)\n└── middleware.ts  # Middleware helper for auth cookie refresh\n```\n\n### Auth Flow\n1. User authenticates via Supabase (email\u002Fpassword, OAuth, etc.)\n2. Supabase stores session in httpOnly cookies\n3. Middleware refreshes session on every request\n4. Server components\u002Factions use `createClient()` from `server.ts`\n5. API client extracts access token from session automatically\n\nSee `references\u002Fsupabase-auth-integration.md` for detailed implementation.\n\n## Role-Based Access Pattern\n\n### Regular User Endpoints\nUse `api-client.ts` functions with automatic Supabase auth:\n```typescript\nimport { apiGet, apiPost } from '@\u002Flib\u002Fapi\u002Fapi-client';\n\n\u002F\u002F Access token extracted from Supabase session automatically\nconst data = await apiGet\u003CResponseType>(url);\n```\n\n### Admin-Only Endpoints\nUse `admin-api-client.ts` functions with role validation:\n```typescript\nimport { adminApiRequest, checkAdminPermission } from '@\u002Flib\u002Fapi\u002Fadmin-api-client';\n\n\u002F\u002F Validate admin access first (checks user role from database)\nawait checkAdminPermission(); \u002F\u002F Throws if not admin\n\n\u002F\u002F Make admin API request\nconst data = await adminApiRequest\u003CResponseType>(url, options);\n```\n\n### Admin Roles\nAdmin roles are stored in the `users` table:\n- `users.role` = `'admin'` - Standard admin access\n- `users.role` = `'member'` - Regular user access\n\nFirst user in a family is automatically assigned admin role.\n\n## Adding New API Endpoints\n\nFollow this exact order when integrating a new API into the application:\n\n### Step 1: Define Types in endpoint-types.ts\n\n```typescript\n\u002F\u002F 1. Define response type(s)\nexport interface ResourceItem {\n  id: string;\n  name: string;\n  \u002F\u002F ... other fields from your API response\n}\n\n\u002F\u002F 2. Define request DTO(s) for mutations\nexport interface CreateResourceDto {\n  name: string;\n  \u002F\u002F ... fields required to create\n}\n\n\u002F\u002F 3. Add parameter types to EndpointParams interface\nexport interface EndpointParams {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    list: void;              \u002F\u002F No params needed\n    get: { id: string };     \u002F\u002F Requires ID\n    create: void;            \u002F\u002F Body in request, not params\n    update: { id: string };\n    delete: { id: string };\n  };\n}\n\n\u002F\u002F 4. Add response types to EndpointResponses interface\nexport interface EndpointResponses {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    list: ResourceItem[];\n    get: ResourceItem;\n    create: ResourceItem;\n    update: ResourceItem;\n    delete: void;\n  };\n}\n\n\u002F\u002F 5. Add request body types to EndpointBodies interface (if needed)\nexport interface EndpointBodies {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    create: CreateResourceDto;\n    update: CreateResourceDto;\n  };\n}\n```\n\n### Step 2: Define URLs in endpoints.ts\n\n```typescript\nexport const API_ENDPOINTS = {\n  \u002F\u002F ... existing categories\n\n  resources: {\n    list: () => `${API_BASE}\u002Fapi\u002Fresources`,\n    get: (id: string) => `${API_BASE}\u002Fapi\u002Fresources\u002F${id}`,\n    create: () => `${API_BASE}\u002Fapi\u002Fresources`,\n    update: (id: string) => `${API_BASE}\u002Fapi\u002Fresources\u002F${id}`,\n    delete: (id: string) => `${API_BASE}\u002Fapi\u002Fresources\u002F${id}`,\n  },\n};\n```\n\n### Step 3: Add Wrapper in protected-endpoints.ts\n\n```typescript\nexport const api = {\n  \u002F\u002F ... existing domains\n\n  resources: {\n    async list(): Promise\u003CResourceItem[]> {\n      return apiGet\u003CResourceItem[]>(\n        API_ENDPOINTS.resources.list()\n      );\n    },\n\n    async get(id: string): Promise\u003CResourceItem> {\n      return apiGet\u003CResourceItem>(\n        API_ENDPOINTS.resources.get(id)\n      );\n    },\n\n    async create(data: CreateResourceDto): Promise\u003CResourceItem> {\n      return apiPost\u003CResourceItem, CreateResourceDto>(\n        API_ENDPOINTS.resources.create(),\n        data\n      );\n    },\n\n    async update(id: string, data: CreateResourceDto): Promise\u003CResourceItem> {\n      return apiPut\u003CResourceItem, CreateResourceDto>(\n        API_ENDPOINTS.resources.update(id),\n        data\n      );\n    },\n\n    async delete(id: string): Promise\u003Cvoid> {\n      return apiDelete\u003Cvoid>(\n        API_ENDPOINTS.resources.delete(id)\n      );\n    },\n  },\n};\n```\n\n### Step 4: Use in Application Code\n\n```typescript\n'use server';\n\nimport { api } from '@\u002Flib\u002Fapi\u002Fprotected-endpoints';\n\n\u002F\u002F In a server component or server action\nconst resources = await api.resources.list();\nconst resource = await api.resources.get(id);\nconst newResource = await api.resources.create({\n  name: 'New Resource'\n});\n```\n\n## Naming Conventions\n\n### Endpoint Operations\n- `list` \u002F `listAll` - GET multiple items\n- `get` - GET single item\n- `create` - POST new item\n- `update` - PUT\u002FPATCH existing item\n- `delete` - DELETE item\n\n### Type Naming\n- Response types: PascalCase describing entity (e.g., `AudienceListItem`)\n- DTOs: PascalCase with suffix (e.g., `CreateUserDto`, `UpdateSettingsDto`)\n- Interfaces match plural for collections, singular for items\n\n## Error Handling\n\nAll API clients handle errors automatically:\n\n```typescript\ntry {\n  const data = await api.myFeature.get(id);\n} catch (error) {\n  \u002F\u002F Error already parsed and formatted\n  console.error('API error:', error.message);\n}\n```\n\nCommon error types:\n- `AdminAuthError` - Admin permission denied\n- `AdminApiError` - Admin API request failed\n- Generic errors from `api-client` with parsed messages\n\n## Authentication Flow\n\n### Regular Endpoints\n1. Client calls protected endpoint wrapper (e.g., `api.resources.list()`)\n2. Wrapper calls apiGet\u002FapiPost\u002Fetc from api-client\n3. api-client calls `getAuthHeaders()`\n4. getAuthHeaders uses Supabase server client to get session:\n   ```typescript\n   const supabase = await createClient();\n   const { data: { session } } = await supabase.auth.getSession();\n   const accessToken = session?.access_token;\n   ```\n5. Access token added to Authorization header\n6. Request sent with automatic authentication\n\n### Admin Endpoints\nSame flow as above, but with additional role check:\n1. Call `checkAdminPermission()` first\n2. checkAdminPermission queries `users` table for current user's role\n3. Throws `AdminAuthError` if role is not 'admin'\n4. Then proceeds with normal authentication flow\n\n## Best Practices\n\n1. **Never hardcode URLs** - Always use `API_ENDPOINTS`\n2. **Always define types first** - Types drive implementation\n3. **One wrapper per endpoint** - Keep protected-endpoints clean\n4. **Group by domain** - Match structure across all 5 files\n5. **Use helper functions** - `apiGet`, `apiPost`, etc. handle auth\n6. **Validate admin access early** - Call `checkAdminPermission()` first\n7. **Document complex endpoints** - Add JSDoc comments\n8. **Handle errors gracefully** - API clients provide good error messages\n\n## Environment Variables\n\n### Required for Supabase Auth\n- `NEXT_PUBLIC_SUPABASE_URL` - Supabase project URL\n- `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY` - Supabase anonymous public key\n\n### Required for API Clients\n- `INSTANCE_API_URL` or `API_URL` - Base URL for external API endpoints\n- `NEXT_PUBLIC_SITE_URL` - Site URL for redirects (optional, defaults to localhost:3000)\n\n### Database\n- Supabase connection is handled automatically via the Supabase client\n- No manual connection strings needed\n\n## Migration from Other Patterns\n\nIf migrating existing API code to this pattern:\n\n1. Extract all endpoint URLs to `endpoints.ts`\n2. Create types in `endpoint-types.ts` for params\u002Fresponses\n3. Replace direct fetch calls with `apiGet`\u002F`apiPost`\u002Fetc\n4. Add wrappers to `protected-endpoints.ts`\n5. Update imports to use `api` object\n\nExample migration:\n```typescript\n\u002F\u002F Before (scattered fetch calls)\nconst response = await fetch(`${API_BASE}\u002Fapi\u002Fresources\u002F${id}`, {\n  headers: { Authorization: `Bearer ${token}` }\n});\nconst resource = await response.json();\n\n\u002F\u002F After (centralized pattern)\nimport { api } from '@\u002Flib\u002Fapi\u002Fprotected-endpoints';\nconst resource = await api.resources.get(id); \u002F\u002F Auth automatic, types included\n```\n\n## References\n\nSee reference files for detailed implementation patterns:\n- `references\u002Fsupabase-auth-integration.md` - Supabase auth setup and integration\n- `references\u002Fendpoint-types-pattern.md` - Type definition structure\n- `references\u002Fendpoints-pattern.md` - URL organization pattern\n- `references\u002Fapi-client-pattern.md` - Generic client implementation with Supabase\n- `references\u002Fadmin-api-client-pattern.md` - Admin client with role-based access\n- `references\u002Fprotected-endpoints-pattern.md` - Wrapper function patterns\n",{"name":5,"description":7},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fbom-98\u002Fapi-organization",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill api-organization",{"tool":59,"command":60},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill api-organization",{"tool":62,"command":63},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill api-organization","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbom-98\u002Fapi-organization\u002FSKILL.md",true,[67,73,77,81],{"path":68,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":71,"sourceHtmlUrl":72},"references\u002Fendpoint-types-pattern.md","REFERENCE","参考文档",5404,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbom-98\u002Fapi-organization\u002Freferences\u002Fendpoint-types-pattern.md",{"path":74,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fendpoints-pattern.md",6645,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbom-98\u002Fapi-organization\u002Freferences\u002Fendpoints-pattern.md",{"path":78,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Fsupabase-auth-integration.md",9842,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbom-98\u002Fapi-organization\u002Freferences\u002Fsupabase-auth-integration.md",{"path":82,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":83,"sourceHtmlUrl":84},"skill-report.json",44094,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbom-98\u002Fapi-organization\u002Fskill-report.json",[86,95,104,113,119,125],{"skillNo":87,"name":88,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":39},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[92,93,94],"model","model hierarchy","model hierarchy skill",{"skillNo":96,"name":97,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":39},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[101,102,103],"MCP","zoom","zoom mcp",{"skillNo":105,"name":106,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":39},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[110,111,112,102],"sdk","zoom apps sdk","apps",{"skillNo":114,"name":115,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":39},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[115],{"skillNo":120,"name":121,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":39},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[121],{"skillNo":126,"name":127,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":39},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[127]]