Crossly Embed storefront
Latest: v1.0.0
Initial release
Build a storefront with @crossly/embed
@crossly/embed is a set of custom elements. No build step, no framework wrapper: it works in plain HTML and in React, Vue and Svelte alike because they all render HTML elements.
Setup
- Create a free Crossly account: https://crossly.net/register
- Create a personal access token at https://crossly.net/settings/api/tokens/new (guide: https://crossly.net/guides/personal-access-tokens). Use a
crossly_pat_test_token against the sandbox while building. - Export it as
CROSSLY_PATand send it asAuthorization: Bearer $CROSSLY_PATtohttps://crossly.net/api/v1/*. Full docs: https://crossly.net/docs
1. Get a publishable key (server-side, once)
The page needs a publishable key crossly_pk_live_… (crossly_pk_test_… in the sandbox). It is designed to sit in page source: it can read the seller's own active listings and start a checkout, and nothing else. Never put a crossly_pat_… personal access token or an OAuth token in a web page; a PAT in page source is a full-access credential published to the world.
Mint one in the dashboard, or with a PAT holding accounts:write:
curl -X POST https://crossly.net/api/v1/embeds/keys \
-H "Authorization: Bearer $CROSSLY_PAT" -H "Content-Type: application/json" \
-d '{"name":"my Squarespace shop","allowedOrigins":["https://shop.example.com"]}'
# → { "data": { "id", "key": "crossly_pk_live_…", "name", "allowedOrigins" } }
const { data } = await crossly.embeds.createKey({ name: 'my shop', allowedOrigins: ['https://shop.example.com'] });
allowedOriginsare exact origins (https://shop.example.com), not paths. Empty means any origin, which is deliberate for site builders whose domain you don't control; add origins once you know them.GET /v1/embeds/keyslists keys (crossly.embeds.listKeys()),DELETE /v1/embeds/keys/{id}revokes one immediately (crossly.embeds.revokeKey(id)): swap the new key into the page before revoking the old one, or the catalog goes empty.
2. Drop in the elements
<script src="https://crossly.net/embed.js" async></script>
<crossly-catalog pk="crossly_pk_live_…" limit="24"></crossly-catalog>
<crossly-buy-button pk="crossly_pk_live_…" listing="<listing id>" label="Buy now"></crossly-buy-button>
The hosted script is the intended way to load it; the npm package is @crossly/embed (ES module, registers the same elements).
| Element | Attributes |
|---|---|
<crossly-catalog> | pk (required), limit (1-48, default 12), q (free-text filter over title and brand), api (override the API base, for testing) |
<crossly-buy-button> | pk (required), listing (required listing id), quantity (default 1), label (default "Buy now"), target (_self default, or _blank), api |
<crossly-index> | pk, slug (a Vault Markets index, e.g. crossly-50), range (1m, 3m, 6m, 1y default, 5y), api |
<crossly-mark> | pk, key (a market book key), range, api |
React:
<crossly-catalog pk={process.env.NEXT_PUBLIC_CROSSLY_PK} limit="24" />
Only the publishable key belongs in a NEXT_PUBLIC_ / VITE_ variable. Load https://crossly.net/embed.js once (for example with Next.js <Script>).
3. Style it
The elements render in Shadow DOM, so your CSS can't break their layout. Style through custom properties and parts:
crossly-catalog {
--crossly-accent: #ff5a5f;
--crossly-radius: 2px;
--crossly-min-col: 260px;
--crossly-card-bg: #fafafa;
}
crossly-catalog::part(card) { box-shadow: 0 2px 8px rgb(0 0 0 / 0.08); }
crossly-catalog::part(title) { font-family: Georgia, serif; }
Dark mode follows prefers-color-scheme unless you override the variables.
4. React to events
The elements dispatch composed, bubbling events on document:
document.addEventListener('crossly:loaded', (e) => console.log(e.detail.listings));
document.addEventListener('crossly:error', (e) => console.warn(e.detail.message));
document.addEventListener('crossly:checkout', (e) => {
// cancelable: e.preventDefault() and route e.detail.checkoutUrl yourself
});
What it does not do
- It never takes a payment on your page:
<crossly-buy-button>sends the buyer to a Crossly-hosted checkout, so your site stays out of PCI scope. - It sets no cookies, reads no storage on your origin, and sends no credentials cross-origin.
- Prices from the embed API are integer cents (
priceCents: 4599);formatPriceis exported by the package if you render your own layout.
Checklist
- The page contains only
crossly_pk_…; grep the built bundle forcrossly_pat_before shipping. allowedOriginslists the real production origin(s) once known.- A live key on crossly.net, a test key with the sandbox: the other kind is refused.
Docs: https://crossly.net/docs/ref-embeds · Source: https://github.com/crossly-dev/crossly-embed
