@shopbb/helium
v0.10.1
Published
shopbb storefront framework — components, React SSR, GraphQL client, cart handler, cache for Cloudflare Workers
Maintainers
Readme
@shopbb/helium
The storefront framework for shopbb. Use it inside a Cloudflare Worker to talk to the shopbb Storefront API.
Install
npm install @shopbb/heliumQuick start
import { createHeliumContext, cartGetIdDefault, cartSetIdDefault } from '@shopbb/helium';
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const ctx = createHeliumContext({
request,
env,
executionContext: ctx,
storefront: {
apiUrl: env.PUBLIC_STOREFRONT_API_URL,
publicAccessToken: request.headers.get('X-Public-Storefront-Token')!,
privateAccessToken: request.headers.get('X-Private-Storefront-Token') ?? undefined,
storeId: request.headers.get('X-Store-Id')!,
},
cart: {
getId: cartGetIdDefault(request.headers),
setId: cartSetIdDefault({ maxage: 60 * 60 * 24 * 365 }),
},
});
const { products } = await ctx.storefront.query(
`{ products(first: 10) { nodes { id title } } }`,
{ cache: ctx.storefront.CacheShort() },
);
return new Response(JSON.stringify(products), {
headers: { ...Object.fromEntries(ctx.responseHeaders), 'content-type': 'application/json' },
});
},
};See the full docs at oxygen-demo.cloudc.top/docs/helium.
License
MIT
