Skip to content

About

Nuxt module for the Crossly embeddable storefront: auto-registered components, publishable key from runtime config.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@crossly/nuxt

npm CI Nuxt 3 | 4 license

A Nuxt module for the Crossly embeddable storefront. Install it and you get:

  • Auto-registered components from @crossly/vue: <CrosslyCatalog>, <CrosslyBuyButton>, <CrosslyPriceIndex>, <CrosslyPriceMark>. No imports needed.
  • Your publishable key in runtime config (runtimeConfig.public.crossly), provided to every component, and overridable per environment with NUXT_PUBLIC_CROSSLY_PUBLISHABLE_KEY.
  • compilerOptions.isCustomElement set for crossly-*, so you can also write the raw elements in templates.
  • SSR that works. The server renders each component's #fallback slot. The custom elements are registered in the browser.

Install

npm install @crossly/nuxt
# pnpm add @crossly/nuxt · yarn add @crossly/nuxt · bun add @crossly/nuxt
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@crossly/nuxt'],
  crossly: {
    publishableKey: 'crossly_pk_live_…', // or NUXT_PUBLIC_CROSSLY_PUBLISHABLE_KEY at runtime
  },
});

Mint the key in Crossly → Settings → Embeds. It is public by design: it can read your own active listings and start a checkout, and nothing else.

Usage

<script setup lang="ts">
import type { CatalogLoadedDetail } from '@crossly/vue';

function onLoaded({ listings }: CatalogLoadedDetail) {
  console.log(`${listings.length} listings`);
}
</script>

<template>
  <CrosslyCatalog :limit="24" @loaded="onLoaded" @error="({ message }) => console.warn(message)">
    <template #fallback><p>Loading the shop…</p></template>
  </CrosslyCatalog>

  <CrosslyBuyButton listing="lst_123" label="Buy now" @checkout="({ checkoutUrl }) => console.info(checkoutUrl)" />

  <CrosslyPriceIndex slug="crossly-50" range="6m" />
  <CrosslyPriceMark book-key="var_1:nm:psa10" />
</template>

A runnable app is in examples/nuxt-app.

Options

option (crossly: { … }) default runtime env
publishableKey '' NUXT_PUBLIC_CROSSLY_PUBLISHABLE_KEY Default pk for every component. A component's own pk prop wins.
api '' (embed default https://crossly.net/api) NUXT_PUBLIC_CROSSLY_API API base override. For testing.
prefix 'Crossly' Component name prefix. prefix: 'Shop' gives <ShopCatalog>, <ShopBuyButton>, <ShopPriceIndex>, <ShopPriceMark>.
customElements true Adds tag.startsWith('crossly-') to vue.compilerOptions.isCustomElement (any existing predicate is kept).

The values end up in useRuntimeConfig().public.crossly as { publishableKey, api }.

Components

These are the @crossly/vue components. The full reference is in its README:

component element props emits
<CrosslyCatalog> <crossly-catalog> limit (1–48, default 12), q loaded({ listings }), error({ message })
<CrosslyBuyButton> <crossly-buy-button> listing (required), quantity (1), label ("Buy now"), target (_self) checkout({ checkoutUrl }), error
<CrosslyPriceIndex> <crossly-index> slug (required), range (1y) loaded({ index }), error
<CrosslyPriceMark> <crossly-mark> book-key (required, becomes the key attribute), range (1y) loaded({ mark }), error

All of them also take pk and api and a #fallback slot, and forward class / style to the custom element. Theming uses the elements' CSS variables and ::parts, set on the element itself:

crossly-catalog { --crossly-accent: #ff5a5f; --crossly-min-col: 260px; }
crossly-catalog::part(card) { box-shadow: 0 2px 8px rgb(0 0 0 / 0.08); }

Raw elements

With customElements: true, the compiler leaves crossly-* tags alone, so you can write them directly. The tags are registered once any Crossly component has mounted. Or call loadCrosslyElements() from @crossly/vue in onMounted.

<crossly-index :pk="$config.public.crossly.publishableKey" slug="crossly-50" />

Prefer the components for crossly-mark: Vue reserves key, so <crossly-mark key="…"> won't reach the element. <CrosslyPriceMark book-key="…"> sets it for you.

SSR notes

@crossly/embed defines HTMLElement subclasses when it loads, so it never runs on the server. The components render their #fallback slot during SSR and on the first client render (so hydration matches). On mount they import the embed once and render the elements. CI builds a real Nuxt app with this module and checks the server-rendered HTML.

Known limitations

These come from @crossly/embed 0.1.0:

  • crossly:checkout is dispatched as cancelable, but the element navigates anyway.
  • A q search surfaces as @error: the API requires a proof-of-work header for fresh searches, and the element doesn't send one.
  • If your key has an origin allowlist, your site's origin must be on it. That covers both the requests and the checkout returnUrl, which is the current page.

Compatibility

Nuxt >=3.13.0 (declared). CI runs Nuxt 4.
Vue 3.3+

Links

License

MIT

About

Nuxt module for the Crossly embeddable storefront: auto-registered components, publishable key from runtime config.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages