Sdk
API Reference
전체 API 레퍼런스
API Reference
SDK의 전체 API 레퍼런스입니다.
지원 컬렉션
SDK는 37개의 컬렉션을 지원합니다.
브랜드 관련
| 컬렉션 | 설명 |
|---|---|
brands | 브랜드 정보 |
brand-logos | 브랜드 로고 이미지 |
brand-og-images | 브랜드 OG 이미지 |
brand-settings | 브랜드 설정 |
brand-secret-keys | 브랜드 API 키 (서버 전용) |
상품 관련
| 컬렉션 | 설명 |
|---|---|
products | 상품 정보 |
product-variants | 상품 옵션/변형 |
product-options | 상품 옵션 그룹 |
product-categories | 상품 카테고리 |
product-tags | 상품 태그 |
product-images | 상품 이미지 |
주문 관련
| 컬렉션 | 설명 |
|---|---|
orders | 주문 정보 |
order-products | 주문 상품 |
returns | 반품/환불 |
return-products | 반품 상품 |
transactions | 결제 트랜잭션 |
콘텐츠 관련
| 컬렉션 | 설명 |
|---|---|
posts | 블로그 포스트 |
post-categories | 포스트 카테고리 |
post-tags | 포스트 태그 |
post-images | 포스트 이미지 |
documents | 문서 |
document-images | 문서 이미지 |
entities | 엔티티 |
entity-categories | 엔티티 카테고리 |
entity-tags | 엔티티 태그 |
entity-images | 엔티티 이미지 |
미디어 관련
| 컬렉션 | 설명 |
|---|---|
playlists | 재생목록 |
playlist-images | 재생목록 이미지 |
musics | 음악 |
galleries | 갤러리 |
gallery-images | 갤러리 이미지 |
기타
| 컬렉션 | 설명 |
|---|---|
links | 링크 |
link-images | 링크 이미지 |
nodes | 노드 |
forms | 폼 |
Query Builder API
find(options)
목록을 조회합니다.
client.from(collection).find(options)Parameters
{
limit?: number // 한 페이지당 항목 수 (기본값: 10)
page?: number // 페이지 번호 (기본값: 1)
sort?: string // 정렬 ('-createdAt', 'price' 등)
where?: WhereQuery // 필터 조건
}Returns
Promise<{
data?: {
docs: T[]
pagination: {
totalDocs: number
limit: number
page: number
totalPages: number
hasNextPage: boolean
hasPrevPage: boolean
nextPage: number | null
prevPage: number | null
}
}
error?: SDKError
}>Example
const { data } = await client.from('products').find({
limit: 20,
page: 1,
sort: '-createdAt',
where: {
status: { equals: 'published' },
price: { greater_than: 1000 }
}
})findById(id)
ID로 단일 항목을 조회합니다.
client.from(collection).findById(id)Parameters
id(string): 항목 ID
Returns
Promise<{
data?: T
error?: SDKError
}>Example
const { data: product } = await client
.from('products')
.findById('product_id')create(data)
새 항목을 생성합니다.
client.from(collection).create(data)Parameters
data(object): 생성할 데이터
Returns
Promise<{
data?: T
error?: SDKError
}>Example
const { data: newProduct } = await client.from('products').create({
name: '새 상품',
price: 10000,
status: 'draft'
})update(id, data)
항목을 수정합니다.
client.from(collection).update(id, data)Parameters
id(string): 항목 IDdata(object): 수정할 데이터
Returns
Promise<{
data?: T
error?: SDKError
}>Example
const { data: updatedProduct } = await client
.from('products')
.update('product_id', {
name: '수정된 상품명',
price: 15000
})remove(id)
항목을 삭제합니다.
client.from(collection).remove(id)Parameters
id(string): 항목 ID
Returns
Promise<{
data?: T
error?: SDKError
}>Example
const { data: deletedProduct } = await client
.from('products')
.remove('product_id')React Query Hooks
SDK는 TanStack Query의 원형을 살린 훅들을 제공합니다.
useQuery(params, options)
목록을 조회하는 훅입니다.
client.query.useQuery(params, options)Parameters
params(object):collection(string): 컬렉션 이름options(object, optional): API 쿼리 파라미터 (find 옵션과 동일)
options(object, optional): TanStack Query 옵션
Returns
{
data?: T[]
isLoading: boolean
isFetching: boolean
error: Error | null
refetch: () => void
// ... 기타 TanStack Query 속성
}Example
const { data, isLoading } = client.query.useQuery({
collection: 'products',
options: {
limit: 10,
where: { status: { equals: 'published' } }
}
})useSuspenseQuery(params, options)
Suspense와 함께 사용하는 목록 조회 훅입니다.
client.query.useSuspenseQuery(params, options)Example
const { data } = client.query.useSuspenseQuery({
collection: 'products',
options: { limit: 10 }
})
// data는 항상 존재 (undefined가 아님)useQueryById(params, options)
단일 항목을 ID로 조회하는 훅입니다.
client.query.useQueryById(params, options)Parameters
params(object):collection(string): 컬렉션 이름id(string | number): 항목 IDoptions(object, optional): API 쿼리 파라미터
options(object, optional): TanStack Query 옵션
Returns
{
data?: T | null
isLoading: boolean
error: Error | null
refetch: () => void
}Example
const { data: product } = client.query.useQueryById({
collection: 'products',
id: 'product_123'
})useSuspenseQueryById(params, options)
Suspense와 함께 사용하는 단일 항목 조회 훅입니다.
client.query.useSuspenseQueryById(params, options)Example
const { data: product } = client.query.useSuspenseQueryById({
collection: 'products',
id: 'product_123'
})useInfiniteQuery(params, options)
무한 스크롤을 위한 훅입니다.
client.query.useInfiniteQuery(params, options)Parameters
params(object):collection(string): 컬렉션 이름options(object, optional): API 쿼리 파라미터 (page 제외)pageSize(number, optional): 페이지당 항목 수 (기본값: 20)
options(object, optional): TanStack Query 옵션
Returns
{
data?: {
pages: T[][]
pageParams: number[]
}
fetchNextPage: () => void
hasNextPage: boolean
isFetchingNextPage: boolean
isLoading: boolean
}Example
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage
} = client.query.useInfiniteQuery({
collection: 'products',
pageSize: 20
})useSuspenseInfiniteQuery(params, options)
Suspense와 함께 사용하는 무한 스크롤 훅입니다.
prefetchQuery(params, options)
서버에서 데이터를 미리 가져옵니다.
await client.query.prefetchQuery(params, options)Example
// Server Component
await client.query.prefetchQuery({
collection: 'products',
options: { limit: 10 }
})prefetchQueryById(params, options)
서버에서 단일 항목을 미리 가져옵니다.
await client.query.prefetchQueryById(params, options)Example
await client.query.prefetchQueryById({
collection: 'products',
id: 'product_123'
})Cache Utilities
// 쿼리 무효화
client.query.invalidateQueries('products')
client.query.invalidateQueries('products', 'list')
client.query.invalidateQueries('products', 'detail')
// 캐시 데이터 가져오기
client.query.getQueryData('products', 'list')
client.query.getQueryData('products', 'detail', '123')
// 캐시 데이터 설정
client.query.setQueryData('products', 'list', data)
client.query.setQueryData('products', 'detail', '123', data)Server API
서버 API는 ServerClient에서만 사용 가능합니다.
createOrder(data)
주문을 생성합니다.
serverClient.api.createOrder(data)Parameters
{
paymentId: string // 결제 ID
orderNumber: string // 주문 번호
email: string // 주문자 이메일
orderProducts: Array<{ // 주문 상품
product: string // 상품 ID
variant: string // 옵션 ID
quantity: number // 수량
price: number // 가격
}>
totalAmount: number // 총 금액
status?: string // 주문 상태 (기본: 'pending')
// ... 기타 필드
}Returns
Promise<Order>Example
const order = await serverClient.api.createOrder({
paymentId: 'pay_123',
orderNumber: generateOrderNumber(),
email: 'user@example.com',
orderProducts: [{
product: 'product_id',
variant: 'variant_id',
quantity: 1,
price: 10000
}],
totalAmount: 10000
})updateOrder(id, data)
주문을 수정합니다.
serverClient.api.updateOrder(id, data)Parameters
id(string): 주문 IDdata(object): 수정할 데이터
Returns
Promise<Order>Example
await serverClient.api.updateOrder('order_id', {
status: 'completed',
deliveryStatus: 'delivered'
})updateTransaction(id, data)
트랜잭션을 수정합니다.
serverClient.api.updateTransaction(id, data)Parameters
id(string): 트랜잭션 IDdata(object): 수정할 데이터
Returns
Promise<Transaction>Example
await serverClient.api.updateTransaction('transaction_id', {
status: 'paid',
paidAt: new Date().toISOString()
})Where 조건
비교 연산자
{
equals: value // 같음
not_equals: value // 같지 않음
greater_than: value // 보다 큼
greater_than_equal: value // 보다 큼 또는 같음
less_than: value // 보다 작음
less_than_equal: value // 보다 작음 또는 같음
like: value // LIKE (%, _ 사용 가능)
contains: value // 포함 (배열)
not_contains: value // 포함하지 않음
in: [value1, value2, ...] // IN
not_in: [value1, value2, ...] // NOT IN
exists: boolean // 존재 여부
}논리 연산자
{
and: [condition1, condition2, ...] // AND
or: [condition1, condition2, ...] // OR
}Example
{
where: {
and: [
{ status: { equals: 'published' } },
{ price: { greater_than: 1000, less_than: 50000 } },
{
or: [
{ category: { equals: 'electronics' } },
{ tags: { contains: 'featured' } }
]
}
]
}
}타입 정의
PaginationInfo
interface PaginationInfo {
totalDocs: number
limit: number
page: number
totalPages: number
hasNextPage: boolean
hasPrevPage: boolean
nextPage: number | null
prevPage: number | null
}ApiSuccessResponse
interface ApiSuccessResponse<T> {
data: T
error?: never
}ApiErrorResponse
interface ApiErrorResponse {
data?: never
error: SDKError
}SDKError
class SDKError extends Error {
code: string
statusCode?: number
userMessage: string
suggestion: string
getUserMessage(): string
}타입 가드
isSuccessResponse(response)
응답이 성공인지 확인합니다.
import { isSuccessResponse } from '@01.software/sdk'
const response = await client.from('products').find()
if (isSuccessResponse(response)) {
console.log(response.data) // 타입: { docs: Product[], pagination: PaginationInfo }
}isErrorResponse(response)
응답이 에러인지 확인합니다.
import { isErrorResponse } from '@01.software/sdk'
const response = await client.from('products').find()
if (isErrorResponse(response)) {
console.error(response.error) // 타입: SDKError
}isNetworkError(error)
네트워크 에러인지 확인합니다.
import { isNetworkError } from '@01.software/sdk'
try {
await client.from('products').find()
} catch (error) {
if (isNetworkError(error)) {
console.error('Network error:', error.getUserMessage())
}
}다음 단계
- Utilities - 유틸리티 함수
- Components - React 컴포넌트
- Webhooks - Webhook 처리