Type Safety
The @tanqory/types package provides a unified Tanqory namespace with all resource types, request params, and response shapes.
The Tanqory Namespace
import type { Tanqory } from '@tanqory/types'
// Resource types
const product: Tanqory.Product
const order: Tanqory.Order
const customer: Tanqory.Customer
const store: Tanqory.Store
// Request params
const createParams: Tanqory.Product.CreateParams = {
title: 'My Product',
price: 2999,
status: 'DRAFT',
}
// List response (paginated)
const response: Tanqory.Product.ListResponse = {
data: [],
total: 0,
page: 1,
limit: 20,
totalPages: 0,
}
// Sub-resources
const variant: Tanqory.Product.Variant
const segment: Tanqory.Customer.Segment
const member: Tanqory.Store.Member
const lineItem: Tanqory.Order.LineItem
Shared Value Objects
import type { Tanqory } from '@tanqory/types'
const money: Tanqory.Money = { amount: 2999, currency: 'THB' }
const address: Tanqory.Address = {
address1: '123 Main St',
city: 'Bangkok',
province: 'Bangkok',
postalCode: '10110',
countryCode: 'TH',
}
Zod Schemas
Every type has a corresponding Zod schema for runtime validation:
import { productSchemas, orderSchemas } from '@tanqory/types'
// Validate input at runtime
const parsed = productSchemas.create.parse(userInput)
// parsed is typed as Tanqory.Product.CreateParams
// Safe parse (no throw)
const result = productSchemas.create.safeParse(userInput)
if (!result.success) {
console.log(result.error.issues)
}
z.infer Pattern
Derive TypeScript types from Zod schemas (this is how all DTOs are generated internally):
import { z } from 'zod'
import { productSchemas } from '@tanqory/types'
// Infer the type from the schema
type CreateProductDto = z.infer<typeof productSchemas.create>
// Equivalent to Tanqory.Product.CreateParams
const dto: CreateProductDto = {
title: 'My Product',
price: 2999,
}
Type-Safe API Calls
All SDK methods are fully typed. The return type matches the Tanqory namespace:
// Return type: Tanqory.Product
const product = await tanqory.products.create(storeId, {
title: 'My Product', // TypeScript enforces required fields
price: 2999,
})
product.title // string
product.price // Tanqory.Money
product.status // 'ACTIVE' | 'DRAFT' | 'ARCHIVED'
// Return type: Tanqory.Product.ListResponse
const list = await tanqory.products.list(storeId, {
status: 'ACTIVE', // Autocomplete for valid values
limit: 50,
})
list.data // Tanqory.Product[]
list.total // number
list.totalPages // number
Enums
import type { Tanqory } from '@tanqory/types'
type ProductStatus = Tanqory.Product.Status // 'ACTIVE' | 'DRAFT' | 'ARCHIVED'
type OrderStatus = Tanqory.Order.Status // 'UNFULFILLED' | 'FULFILLED' | ...
type PaymentStatus = Tanqory.Order.PaymentStatus // 'PENDING' | 'PAID' | ...
Custom Extensions
Extend types for your application:
import type { Tanqory } from '@tanqory/types'
interface ProductWithUI extends Tanqory.Product {
isSelected: boolean
displayPrice: string
}