JavaScript SDK

Build mockup and buy URLs, read the catalog, and call the API from any JS environment — with Snowcone's hosts owned by the package, not your code.

Applies to @snowcone-app/sdk@0.33.2

The mockup is a URL

A mockup is just an image URL — a product, your artwork, and your Shop ID — that drops into an <img>:

html
<img src="https://img.snowcone.app/BC43BE?asset=https%3A%2F%2Fcdn.example.com%2Fart.png&shop=YOUR_SHOP_ID" />

In JavaScript and TypeScript, build it with @snowcone-app/sdk rather than by hand. The SDK encodes and signs the URL, reads the public catalog, and owns Snowcone’s hostnames — so your code never contains one, and a host move is a package upgrade instead of an outage. It ships TypeScript types.

Building in another language, or a static HTML page? Use the URL primitive directly — and keep each host in one config value, not repeated at every call site (see Keep hosts out of your code).

Keep hosts out of your code

Don’t write api.snowcone.app (or any Snowcone host) into your integration. Call the SDK, and it picks the host. For an endpoint the SDK doesn’t wrap yet, read the host from SNOWCONE_HOSTS — api, img, buy, search — instead of typing it:

tsx
import { getMockupUrl, getBuyUrl, getProduct, SNOWCONE_HOSTS } from "@snowcone-app/sdk";

// ✓ The SDK picks the host — your code never names one.
const img = getMockupUrl("BEEB77", { shop: "YOUR_SHOP_ID", asset: "https://cdn.example.com/art.png" });
const buy = getBuyUrl("BEEB77", { shop: "YOUR_SHOP_ID", asset: "https://cdn.example.com/art.png" });
const product = await getProduct("BEEB77");

// ✓ An endpoint the SDK doesn't wrap: still take the host from the SDK.
await fetch(`${SNOWCONE_HOSTS.api}/orders`, { method: "POST", headers, body });

// ✗ A hardcoded host breaks the day it moves.
await fetch("https://api.snowcone.app/orders", { method: "POST", headers, body });

Hostnames live in one place in the SDK. If one ever has to change, we ship a new SDK version and you upgrade — nothing you wrote changes. A hardcoded host would instead fail the day it moves, in every integration at once. The MCP server and the React components work the same way.

Store inputs, not URLs. Save the product code, artwork URL, and options, and rebuild the mockup URL with getMockupUrl() when you render — it’s pure and synchronous, so it costs nothing. A URL saved in your database pins today’s host; rebuilt inputs always get the current one. Not in JavaScript? Put each host in one config value (for example a SNOWCONE_API_BASE environment variable) and read it everywhere.

Install

Add the package with npm. There’s no CLI, no postinstall, and nothing to configure — it’s a plain, logic-only library with no stylesheet.

npm install @snowcone-app/sdk

TypeScript definitions are included — no separate @types package.

Build mockup URLs

getMockupUrl() is a pure, synchronous string builder — no fetch, no await. Its output is the raw URL, without the manual encoding or a hardcoded host.

import { getMockupUrl } from "@snowcone-app/sdk";

// Pure + synchronous — returns a string. No fetch, no await, no secret.
const src = getMockupUrl("BC43BE", {
  shop: "YOUR_SHOP_ID",
  asset: "https://cdn.example.com/art.png", // encoded for you
});
// → https://img.snowcone.app/BC43BE?shop=YOUR_SHOP_ID&asset=…

// Use it anywhere a URL goes:
document.querySelector("img").src = src;

Every mockup URL has a checkout twin: getBuyUrl() takes the exact same options and returns the hosted buy-page link — the conversion step of the same flow.

tsx
import { getBuyUrl, getMockupUrl } from "@snowcone-app/sdk";

// Same options shape as getMockupUrl — the <img> shows the design,
// the <a> sells it. Both pure + synchronous.
const opts = { shop: "YOUR_SHOP_ID", asset: "https://cdn.example.com/art.png" };
const img = getMockupUrl("BC43BE", opts); // → https://img.snowcone.app/BC43BE?…
const buy = getBuyUrl("BC43BE", opts);    // → https://buy.snowcone.app/BC43BE?…
// The buy link opens the Snowcone-hosted checkout with this exact design
// in the cart — price and fulfillment resolve from your Shop ID.

Your Shop ID is public, like a Cloudinary cloud name. Don’t have one yet? Mint a sandbox shop in one call — claiming, limits, and lifecycle are on Get a Shop ID. Never ship a Shop ID copied from these examples — those attribute sales to someone else.

bash
# Mint your own Shop ID in one call — no signup required to start.
curl -X POST https://api.snowcone.app/shops/sandbox -H 'Content-Type: application/json' -d '{}'
# → { "shop_id": "…", "shop_secret": "scsec_…", "claim": { … } }

Variants, placements, crop

The URL grammar is plain query params: opt.<attr> for variants, asset.<key> / color.<key> for extra print areas, and aspect for crop. The helper takes them as typed options and emits the right params for you.

tsx
const src = getMockupUrl("BC43BE", {
  shop: "YOUR_SHOP_ID",
  options: { size: "l" },                 // → opt.size=l
  design: {                                // → asset.<key> / color.<key>
    front: "https://cdn.example.com/front.png",
    back: { src: "https://cdn.example.com/back.png", tile: 2, align: "top" },
    sleeve: { color: "#FF5733" },          // → color.sleeve=FF5733
  },
  preset: "instagram-feed",                // → aspect=4:5&width=1200 (or aspect: "4:5" yourself;
});                                        //   omit both = the default 16:9 picture)
Same grammar the raw URL uses — see Options and Multiple placements.

The exported types, for reference:

tsx
import type { GetMockupUrlOptions, Design, Fill } from "@snowcone-app/sdk";

interface GetMockupUrlOptions {
  shop: string;                  // your public Shop ID → &shop=
  asset?: string;                // single-placement image → &asset=
  design?: Design;               // multi-placement map → asset.<key> / color.<key>
  options?: Record<string, string>; // variant picks → opt.<attr>
  aspect?: MockupAspect;         // "16:9" (default) "2:3" "3:4" "4:5" "1:1" "1.91:1" "9:16" "21:9" "8:3" "app-header"
  preset?: MockupPreset;         // "tiktok" "instagram-feed" "pinterest" "amazon" … : a platform's shape + width
  width?: number;                // render width, snaps down (default 1400)
  secret?: string;               // server-side only → &signature
}

// A Fill is a string URL, { src, align?, tile? }, or { color }.
// A Design is a map of placement key → Fill.

Signing

Public Shop IDs are fine for most shops. If you’d rather only your server mint valid URLs, pass your per-shop secret and the helper appends an &signature — the one place the SDK earns its keep, since the HMAC matches the edge verifier byte-for-byte.

tsx
// SERVER-SIDE ONLY — never ship the secret to a browser.
const src = getMockupUrl("BC43BE", {
  shop: "YOUR_SHOP_ID",
  asset: "https://cdn.example.com/art.png",
  secret: process.env.SNOWCONE_SHOP_SECRET, // appends &signature=…
});
The secret is server-side only — never ship it to a browser. For high-volume patterns, see Signing at scale.

Read the catalog

The mockup shows what they’re buying; pull the rest with getProduct(). It returns a CatalogProduct: not just name/price/description, but the fields the realtime renderer needs — mockups[].id (the mockupIds you render), placements[].label and requiredPlacements (the print-area names you pass to renderState, e.g. "Front"), and options.combinations[].variantId (the variantId required for color/variant products).

tsx
import { getProduct, formatPrice } from "@snowcone-app/sdk";

const product = await getProduct("BC43BE"); // CatalogProduct — any product code

// Identity + pricing
product.id;            // "BC43BE"
product.name;          // "Apple iPhone 17 Pro Max Case"
product.price;         // 3772  (MSRP, in minor units / cents — suggested retail)
product.description;   // string[] — paragraphs, NOT a single string

// Don't hand-roll a price formatter — one ships in the box:
formatPrice(product.price, "en-US", "USD", true);  // "$37.72"

// Mockup scenes → product.mockups[].id are the opaque codes you pass as
// RenderSession mockupIds (e.g. "947QAD").
product.mockups?.[0]?.id;                       // "947QAD"

// Placements → the print-area labels. THIS is where "Front" comes from.
product.placements?.map((p) => p.label);        // ["Front"]
// requiredPlacements is the renderer's contract: which labels renderState will
// demand, and which are auto-filled by the variant (color placements).
product.requiredPlacements;                      // [{ label:"Front", type:"image", autoFilledByVariant:false }]
// (a framed print would also list { label:"Frame", type:"color", autoFilledByVariant:true })

// Variants → variantId for RenderSession / color products lives HERE.
const variantId = product.options?.combinations?.find((c) => c.variantId)?.variantId;
product.options?.attributesList;                 // undefined here (one variant);
                                                 // ["Size","color"] on the hoodie XTNA6J
Heads up on shapes: description is a string array (paragraphs), and price is in minor units (cents). The placement labels a render needs live at product.placements[].label / product.requiredPlacements[].label, and a product’s variantId comes from product.options.combinations[].variantId — there is no separate endpoint to discover either.
The catalog is a standard Meilisearch index with a public read key, so any Meilisearch client works too — but in JavaScript prefer the SDK, which owns the host and the key. Under the hood getProduct(id) fetches that index’s /documents/{id} with the same public read key — it’s the exact same catalog you can query directly with a raw bearer token, just returned as a typed CatalogProduct. See the catalog docs.

Realtime canvas render

The SDK isn’t only a URL builder. It also ships the realtime server-side render API — send a whole saved canvas (or just its id) over a WebSocket and the server renders the mockup, fetching the referenced artwork itself. The public surface: RenderSession, mintRealtimeGrant, createDesignState, and the React hook useRealtimeMockup (from @snowcone-app/sdk/react); serializeStateForServer comes from @snowcone-app/canvas.

tsx
import { RenderSession, mintRealtimeGrant, createDesignState, getProduct } from "@snowcone-app/sdk";
import { serializeStateForServer } from "@snowcone-app/canvas";

// 1. SERVER: mint a short-lived grant. Signature: mintRealtimeGrant({ apiKey?, shop }).
//    e.g. inside POST /api/realtime/grant — the sk_ key never reaches the browser.
//    PRODUCTION: pass a secret sk_ key (scope mockups:realtime).
const grant = await mintRealtimeGrant({
  apiKey: process.env.SNOWCONE_API_KEY, // sk_… — omit entirely for a sandbox shop
  shop: "YOUR_SHOP_ID",
});

// 2. BROWSER: open a session against your grant proxy and render a canvas state.
const product = await getProduct("BC43BE");
const variantId = product.options?.combinations?.find((c) => c.variantId)?.variantId;
const session = new RenderSession({
  shop: "YOUR_SHOP_ID",
  grantUrl: "/api/realtime/grant",
  // variantId is required for color/variant products. Read it from the live catalog
  // and pass options too so the SDK can validate missing/invalid variants immediately.
  product: { productId: "BC43BE", mockupIds: ["947QAD"], variantId, options: product.options },
});
session.onMockups((r) => { img.src = r[0].imageUrl; });
session.onError((message: string) => console.error(message)); // onError gives a string

// First arg is the placement label (getProduct(...).placements[].label, e.g. "Front").
await session.renderState("Front", serializeStateForServer(canvasState), 200);
Two auth paths for mintRealtimeGrant({ apiKey?, shop }). A sandbox shop authorizes keyless — the publishable shop.id alone is enough, so omit apiKey. In production you pass a secret apiKey (an sk_ key with the mockups:realtime scope). Either way, mintRealtimeGrant runs server-side (e.g. in your /api/realtime/grant route) so the key never reaches the browser — the client only ever holds the short-lived grant. The Realtime page covers this sandbox-vs-production split in full.
This is the same primitive that powers mockups on snowcone.app. For the full flow — the grant proxy, the keyless sandbox path, multi-placement, saved-state-by-id, the id-space rules, and a copy-paste Next.js App Router quickstart — see the dedicated Realtime server-side render page. Import serializeStateForServer from @snowcone-app/canvas (its stable, semver-protected home — the SDK does not re-export it).

Next steps

© 2026 Art Shop AI LLC d/b/a Snowcone. All rights reserved.