Skip to main content

Installation

npm install @protonagency/sdk

Configuration

Shopify (optional)

Storefront API is opt-in. Enable it for richer product data (metafields, full variant info, collection/page metadata).
OptionTypeRequiredDescription
enableStorefrontbooleanNoEnable Storefront API hydration (default: false)
shopstringWhen enableStorefront: trueStore domain
storefrontPublicTokenstringWhen enableStorefront: trueStorefront API public access token
storefrontApiVersionstringNoAPI version (default: 2025-01)
fetchCustomFetchNoCustom fetch implementation (SSR, testing, proxying)

Layers

OptionTypeRequiredDescription
layersPublicTokenstringYesLayers API public token
sortsSort[]YesSort options ({ label, code })
facetsstring[]YesFacet fields for filtering
attributesstring[]NoProduct attributes to fetch
layersBaseUrlstringNoCustom API URL
fetchCustomFetchNoCustom fetch implementation (SSR, testing, proxying)

Product

OptionTypeDescription
currencyCodestringCurrency for price formatting
formatPrice(amount, currency) => stringCustom price formatter
swatchesSwatch[]Color swatch definitions
optionsstring[]Product options to expose
productMetafields{ namespace, key }[]Product metafields to fetch
variantMetafields{ namespace, key }[]Variant metafields to fetch

Extensibility

OptionTypeDescription
extendProduct(product, raw) => PTransform products after hydration
extendCollection(result, raw) => resultTransform collection results
extendSearch(result, raw) => resultTransform search results
transformFilters(filters) => FilterGroupCustom filter transformation
filterMapFilterMapURL-friendly filter key mapping
Once configured, extenders and transformers are applied automatically. You pass simple inputs and receive transformed outputs—no manual transformation needed on each call.
// Configure once at initialization
const sdk = createSdk({
  // ... base config
  extendProduct: (product, raw) => ({
    ...product,
    isNew: raw.tags?.includes('new') ?? false,
    rating: raw.calculated?.average_rating,
  }),
  filterMap: {
    color: 'options.color',
    size: 'options.size',
  },
})

// All SDK methods automatically use your transformers
const collection = sdk.collection({ handle: 'shirts' })
await collection.execute({ filters: { color: 'Red' } }) // filterMap applied
// → result.products have isNew and rating properties

Cache

OptionTypeDescription
cacheMaxProductsnumberMax products in cache
cacheMaxEntriesnumberMax query entries in cache
cacheTtlnumberTTL in milliseconds

Singleton Access

After initialization, access the SDK anywhere:
import { getSdk, isInitialized } from '@protonagency/sdk'

if (isInitialized()) {
  const result = getSdk()
  if (result.data) {
    const sdk = result.data
    // Use sdk
  }
}

Important Notes

All SDK methods return a Result type instead of throwing exceptions. Always check for result.error before accessing result.data.