360 Secure SkillHub
360 安全技能中心

Crossly Embed storefront

该 Skill 指导在网页中嵌入 Crossly 商品目录、购买按钮、指数和行情标记,涵盖发布密钥创建、来源限制、Shadow DOM 样式和加载/结账事件;不包含密钥、脚本源码或支付处理。

分类:开发
crossly
热度 9.14
最近更新 2026-11-30 11:10:02

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add crossly/crossly-embed-storefront
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
crossly-embed-storefront
description
Put a seller's Crossly listings on any website with @crossly/embed custom elements (crossly-catalog, crossly-buy-button, crossly-index, crossly-mark) and a crossly_pk_ publishable key. Mint the key with POST /v1/embeds/keys, lock it to origins, style through CSS variables and ::part, react to crossly:loaded / crossly:checkout events. Use when building a storefront, product grid or buy button on Squarespace, Wix, WordPress, Webflow, Shopify, React, Vue, Svelte or plain HTML. Never use a PAT in the page.

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

  1. Create a free Crossly account: https://crossly.net/register
  2. 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.
  3. Export it as CROSSLY_PAT and send it as Authorization: Bearer $CROSSLY_PAT to https://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'] });
  • allowedOrigins are 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/keys lists 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); formatPrice is exported by the package if you render your own layout.

Checklist

  • The page contains only crossly_pk_…; grep the built bundle for crossly_pat_ before shipping.
  • allowedOrigins lists 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