Core Types
Core TypeScript type definitions
Core types used throughout the Arky SDK.
Result Type
All SDK methods return a Result type:
type Result<T, E> = Ok<T> | Err<E>;
interface Ok<T> {
ok: true;
val: T;
}
interface Err<E> {
ok: false;
val: E;
}
Usage
const result = await sdk.eshop.getProduct({ businessId, id });
if (result.ok) {
const product = result.val; // T
} else {
const error = result.val; // ApiError
}
ApiError
interface ApiError {
error: string;
message: string;
statusCode: number;
details?: {
field?: string;
reason?: string;
[key: string]: unknown;
};
}
Pagination
PaginatedResponse
interface PaginatedResponse<T> {
items: T[];
cursor: string | null;
hasMore: boolean;
}
PaginationParams
interface PaginationParams {
cursor?: string | null;
limit?: number;
}
User
interface User {
id: string;
email: string;
firstName?: string;
lastName?: string;
phone?: string;
avatar?: string;
provider: AuthProvider;
confirmed: boolean;
createdAt: number;
updatedAt: number;
permissions?: string[];
}
type AuthProvider = 'EMAIL' | 'GOOGLE' | 'APPLE' | 'GUEST';
Business
interface Business {
id: string;
name: string;
slug: string;
description?: string;
logo?: string;
settings: BusinessSettings;
parentId?: string;
createdAt: number;
updatedAt: number;
}
interface BusinessSettings {
currency: string;
timezone: string;
locale: string;
webhookUrl?: string;
webhookEvents?: string[];
emailTemplates?: EmailTemplateSettings;
}
Address
interface Address {
line1: string;
line2?: string;
city: string;
state: string;
postalCode: string;
country: string;
}
Customer
interface Customer {
id?: string;
email: string;
firstName?: string;
lastName?: string;
phone?: string;
}
Media
interface Media {
id: string;
url: string;
type: MediaType;
mimeType: string;
size: number;
width?: number;
height?: number;
alt?: string;
title?: string;
folder?: string;
createdAt: number;
}
type MediaType = 'IMAGE' | 'VIDEO' | 'DOCUMENT' | 'AUDIO';
Timestamps
All timestamps in Arky are Unix timestamps (seconds since epoch):
// Server response
{
createdAt: 1704067200, // Jan 1, 2024 00:00:00 UTC
updatedAt: 1704153600 // Jan 2, 2024 00:00:00 UTC
}
// Convert to Date
const date = new Date(timestamp * 1000);
// Convert from Date
const timestamp = Math.floor(date.getTime() / 1000);
Money
All monetary values are in minor units (cents):
// Stored as cents
{
price: 1999, // $19.99
compareAtPrice: 2999, // $29.99
total: 5497 // $54.97
}
// Convert for display
const dollars = cents / 100; // 19.99
Status Types
Common Statuses
type ResourceStatus = 'ACTIVE' | 'DRAFT' | 'ARCHIVED';
type PublishStatus = 'DRAFT' | 'PUBLISHED' | 'ARCHIVED';
Order Status
type OrderStatus =
| 'PENDING'
| 'PAID'
| 'PROCESSING'
| 'SHIPPED'
| 'DELIVERED'
| 'CANCELLED'
| 'REFUNDED';
Reservation Status
type ReservationStatus =
| 'PENDING'
| 'CONFIRMED'
| 'CANCELLED'
| 'COMPLETED'
| 'NOSHOW';
SDK Configuration
interface ArkyClientConfig {
businessId: string;
environment?: 'production' | 'sandbox';
baseUrl?: string;
getToken: () => string | null;
setToken: (token: string) => void;
onAuthError?: () => void;
}