Skip to content
Merged
18 changes: 15 additions & 3 deletions apps/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix",
"typecheck": "npx tsc --noEmit",
"generate": "npx openapi-typescript https://api.echo-social.app/openapi -o ./src/libs/api/v1.d.ts",
"openapi": "npx openapi-typescript https://api.echo-social.app/openapi -o ./src/libs/api/v1.d.ts",
"preview": "vite preview"
},
"dependencies": {
"@clerk/clerk-react": "^5.35.3",
"@clerk/types": "^4.90.0",
"@tailwindcss/vite": "^4.1.11",
"@tanstack/react-form": "^1.15.0",
"@tanstack/react-query": "^5.90.2",
Expand All @@ -27,6 +28,7 @@
"react": "^19.1.0",
"react-dom": "^19.1.0",
"react-icons": "^5.5.0",
"sonner": "^2.0.7",
"tailwind-merge": "^3.3.1",
"tailwindcss": "^4.1.11"
},
Expand Down
27 changes: 19 additions & 8 deletions apps/client/src/libs/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import createClient from "openapi-fetch"
import createOpenApiClient from "openapi-fetch"

import type { components, paths } from "./v1"

const BASE_URL = import.meta.env.VITE_API_BASE_URL
export const createClient = (baseUrl: string) => createOpenApiClient<paths>({ baseUrl })

// TODO: validate .env variables in one place
if (!BASE_URL) {
throw new Error("API base URL missing from .env file!")
}
export class ApiException extends Error {
public timestamp: string
public status: number
public path: string
public response: Response

export const client = createClient<paths>({ baseUrl: BASE_URL })
constructor(error: schemas["ErrorResponse"], response: Response) {
super(error.message)
this.timestamp = error.timestamp
this.status = error.status
this.path = error.path
this.response = response
this.name = "ApiException"
}
}

export type { paths, operations } from "./v1"
export type { Middleware } from "openapi-fetch"
export type { operations, paths } from "./v1"
export type schemas = components["schemas"]
export type Client = ReturnType<typeof createClient>
Loading