Back to arkyStore.io

Installation

Install and configure the Arky SDK in your project

Install The SDK

npm install arky-sdk

Requirements

  • Node.js 18+ or a modern browser
  • TypeScript 5.0+ is recommended

Storefront Setup

Storefronts should use createArkyStore. It is a framework-agnostic layer on top of the SDK and exposes reactive Nano Store state.

import { createArkyStore } from 'arky-sdk/storefront-store';

export const arkyStore = createArkyStore({
  baseUrl: import.meta.env.PUBLIC_ARKY_API_URL,
  storeId: import.meta.env.PUBLIC_ARKY_STORE_ID,
  locale: 'en',
  market: 'us',
  marketForLocale: (locale) => (locale === 'it' ? 'ita' : 'us'),
  navigate: (path) => window.location.assign(path),
});

Then initialize the page:

await arkyStore.setup({
  locale: 'en',
  hydrateCart: true,
});

Configuration Options

OptionTypeRequiredDescription
baseUrlstringYesAPI base URL
storeIdstringYesStore ID
marketstringNoInitial market key used for prices, taxes, payment methods, and cart context
localestringNoInitial storefront locale
marketForLocale(locale: string) => string | nullNoMaps locale changes to a market key
apiTokenstringNoAPI token for trusted server-side use
navigate(path: string) => voidNoOptional navigation hook for auth and checkout flows
loginFallbackPathstringNoPath used when auth-required actions need a login fallback

Framework Integration

React

import { createArkyStore } from 'arky-sdk/storefront-store';
import { useEffect, useState } from 'react';

export const arkyStore = createArkyStore({
  baseUrl: process.env.NEXT_PUBLIC_ARKY_API_URL!,
  storeId: process.env.NEXT_PUBLIC_ARKY_STORE_ID!,
  market: 'us',
  locale: 'en',
});

export function useCartCount() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    return arkyStore.eshop.cart.item_count.subscribe(setCount);
  }, []);

  return count;
}

Svelte

// src/lib/arky.ts
import { createArkyStore } from 'arky-sdk/storefront-store';

export const arkyStore = createArkyStore({
  baseUrl: import.meta.env.PUBLIC_ARKY_API_URL,
  storeId: import.meta.env.PUBLIC_ARKY_STORE_ID,
  market: 'us',
  locale: 'en',
});
<script lang="ts">
  import { arkyStore } from '$lib/arky';

  const cartCount = arkyStore.eshop.cart.item_count;
</script>

<span>{$cartCount}</span>

Plain TypeScript

const unsubscribe = arkyStore.eshop.cart.snapshot.subscribe((snapshot) => {
  document.querySelector('[data-cart-count]')!.textContent = String(snapshot.item_count);
});

await arkyStore.eshop.cart.ensure();
unsubscribe();

Server-Side Usage

For trusted backend jobs or custom server routes, use apiToken or the lower-level client. Browser storefronts should not ship private API tokens.

import { createStorefront } from 'arky-sdk/storefront';

export function createServerClient() {
  return createStorefront({
    baseUrl: process.env.ARKY_API_URL!,
    storeId: process.env.ARKY_STORE_ID!,
    market: 'us',
    apiToken: process.env.ARKY_API_TOKEN!,
  });
}
Tip

Keep storefronts store-first. Reach for arkyStore.client or createStorefront only when you are building a lower-level integration that the store layer does not cover yet.

TypeScript Support

The SDK exports store helpers and platform types:

import { createArkyStore, type ArkyStore } from 'arky-sdk/storefront-store';
import type { Product, Service, Cart, Order } from 'arky-sdk';

Next Steps