Installation
Install and configure the Arky SDK in your project
Install the SDK
npm install arky-sdkRequirements
- Node.js 18+ or modern browser
- TypeScript 5.0+ (recommended)
Initialize the SDK
Create an SDK instance with your configuration:
import { createArkyClient } from 'arky-sdk';
const sdk = createArkyClient({
businessId: 'your-business-id',
environment: 'production', // or 'sandbox'
// Token management callbacks
getToken: () => localStorage.getItem('arky_token'),
setToken: (token) => localStorage.setItem('arky_token', token),
// Optional: Handle auth errors
onAuthError: () => {
window.location.href = '/login';
}
});
Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
businessId | string | Yes | Your Arky business ID |
environment | 'production' | 'sandbox' | No | API environment (default: production) |
getToken | () => string | null | Yes | Callback to retrieve stored token |
setToken | (token: string) => void | Yes | Callback to store token |
onAuthError | () => void | No | Called when authentication fails |
baseUrl | string | No | Override API base URL |
Environment Setup
Tip
Use environment variables to keep your business ID secure and enable different configurations per environment.
// config.ts
const sdk = createArkyClient({
businessId: process.env.ARKY_BUSINESS_ID!,
environment: process.env.NODE_ENV === 'production' ? 'production' : 'sandbox',
getToken: () => localStorage.getItem('arky_token'),
setToken: (token) => localStorage.setItem('arky_token', token),
});
export default sdk;
Framework Integration
React
// lib/arky.ts
import { createArkyClient } from 'arky-sdk';
export const sdk = createArkyClient({
businessId: process.env.NEXT_PUBLIC_ARKY_BUSINESS_ID!,
getToken: () => {
if (typeof window === 'undefined') return null;
return localStorage.getItem('arky_token');
},
setToken: (token) => {
localStorage.setItem('arky_token', token);
},
});
Svelte
// lib/arky.ts
import { createArkyClient } from 'arky-sdk';
import { browser } from '$app/environment';
export const sdk = createArkyClient({
businessId: import.meta.env.VITE_ARKY_BUSINESS_ID,
getToken: () => browser ? localStorage.getItem('arky_token') : null,
setToken: (token) => {
if (browser) localStorage.setItem('arky_token', token);
},
});
Vue
// plugins/arky.ts
import { createArkyClient } from 'arky-sdk';
export const sdk = createArkyClient({
businessId: import.meta.env.VITE_ARKY_BUSINESS_ID,
getToken: () => localStorage.getItem('arky_token'),
setToken: (token) => localStorage.setItem('arky_token', token),
});
Server-Side Usage
For server-side applications, manage tokens differently:
import { createArkyClient } from 'arky-sdk';
// Per-request token management
function createServerSdk(token: string | null) {
let currentToken = token;
return createArkyClient({
businessId: process.env.ARKY_BUSINESS_ID!,
getToken: () => currentToken,
setToken: (newToken) => {
currentToken = newToken;
},
});
}
// Usage in API route
export async function GET(request: Request) {
const token = request.headers.get('Authorization')?.replace('Bearer ', '');
const sdk = createServerSdk(token);
const user = await sdk.user.getMe({});
return Response.json(user);
}
TypeScript Support
The SDK is written in TypeScript and exports all types:
import {
createArkyClient,
type User,
type Product,
type Reservation,
type Order
} from 'arky-sdk';
Next Steps
- Authentication - Learn how to authenticate users
- Core Concepts - Understand key SDK concepts
- API Reference - Explore all available methods