API Clients
The core package provides type-safe API clients built on top of the ky HTTP library with Zod schema validation.
Authentication (Legacy)
authRepositories
Legacy authentication client for token-based authentication.
Location : @workspace/core/apis/auth
import { Http } from '@workspace/core/services/http'
import { authRepositories } from '@workspace/core/apis/auth'
const http = new Http ({ baseUrl: process . env . API_BASE_URL })
const auth = authRepositories ( http )
login
Authenticate user with username and password.
const result = await auth . login ({
json: {
username: 'johndoe' ,
password: 'password123' ,
expiresInMins: 60 , // optional
},
})
Username (minimum 3 characters)
Password (minimum 6 characters)
Token expiration time in minutes
URL to user’s profile image
Throws : HTTPError, TimeoutError, ZodError
URL : POST ${env.apiBaseUrl}/auth/login
Better Auth
authRepositories
Modern authentication client using Better Auth library with session-based authentication.
Location : @workspace/core/apis/better-auth
import { Http } from '@workspace/core/services/http'
import { authRepositories } from '@workspace/core/apis/better-auth'
const http = new Http ({ baseUrl: process . env . API_BASE_URL })
const auth = authRepositories ( http )
getSession
Retrieve the current user session.
const { headers , json } = await auth . getSession ()
if ( json ) {
console . log ( 'User:' , json . user . email )
console . log ( 'Session expires:' , json . session . expiresAt )
}
Session information ISO date when session expires
ISO date when session was created
ISO date when session was last updated
IP address of the session
User information Whether email is verified
URL to user’s profile image
ISO date when user was created
ISO date when user was last updated
Throws : HTTPError, TimeoutError, ZodError
URL : GET ${env.apiBaseUrl}/api/auth/get-session
signInEmail
Sign in user with email and password.
const { headers , json } = await auth . signInEmail ({
json: {
email: '[email protected] ' ,
password: 'securepassword' ,
rememberMe: true ,
callbackURL: '/dashboard' ,
},
})
User’s password (minimum 8 characters)
Whether to create a persistent session
URL to redirect after successful sign in
Whether to perform a redirect
Throws : HTTPError, TimeoutError, ZodError
URL : POST ${env.apiBaseUrl}/api/auth/sign-in/email
signUpEmail
Register a new user with email and password.
const { headers , json } = await auth . signUpEmail ({
json: {
email: '[email protected] ' ,
password: 'securepassword' ,
name: 'John Doe' ,
callbackURL: '/welcome' ,
},
})
User’s password (minimum 8 characters)
User’s full name (minimum 3 characters)
URL to redirect after successful registration
Verification token (if email verification is enabled)
Throws : HTTPError, TimeoutError, ZodError
URL : POST ${env.apiBaseUrl}/api/auth/sign-up/email
signOut
Sign out the current user.
const { headers , json } = await auth . signOut ()
if ( json . success ) {
// Redirect to login page
}
Whether sign out was successful
Throws : HTTPError, TimeoutError, ZodError
URL : POST ${env.apiBaseUrl}/api/auth/sign-out
CDN
cdnRepositories
Client for fetching files from CDN or external URLs.
Location : @workspace/core/apis/cdn
import { cdnRepositories } from '@workspace/core/apis/cdn'
const cdn = cdnRepositories ()
getCdnFile
Fetch a file from a CDN URL.
const { response , blob , headers } = await cdn . getCdnFile ({
url: 'https://cdn.example.com/images/photo.jpg' ,
})
// Create object URL for display
const objectUrl = URL . createObjectURL ( blob )
Optional Ky request options (timeout, headers, etc.)
The full Ky response object
Response headers as key-value object
Throws : HTTPError, TimeoutError
URL : GET ${url}
Core API Schemas
Common Schemas
Shared schemas used across API clients.
Location : @workspace/core/apis/core
ErrorResponseSchema
Standard error response format.
import type { ErrorResponseSchema } from '@workspace/core/apis/core'
interface ErrorResponseSchema {
message : string
}
ResourceListRequestSchema
Pagination and filtering parameters for list endpoints.
import type { ResourceListRequestSchema } from '@workspace/core/apis/core'
interface ResourceListRequestSchema {
limit ?: number // 1-100, limit per page
skip ?: number // Skip first n items
select ?: string // Comma-separated field names
delay ?: number // Artificial delay in ms (for testing)
}
ResourceListResponseSchema
Standard pagination metadata in list responses.
import type { ResourceListResponseSchema } from '@workspace/core/apis/core'
interface ResourceListResponseSchema {
total : number // Total number of items
skip : number // Number of items skipped
limit : number // Items per page
}
Query Keys
All API clients export query key factories for use with React Query:
import { authKeys } from '@workspace/core/apis/better-auth'
import { cdnKeys } from '@workspace/core/apis/cdn'
// Generate query keys
const sessionKey = authKeys . all () // ['auth']
const signInKey = authKeys . signInEmail ({ email: '[email protected] ' })
// ['auth', 'signInEmail', { email: '[email protected] ' }]
const cdnKey = cdnKeys . getArticleCoverImage ( 'https://...' )
// ['cdn', 'article', 'https://...']