Add the SDK to your app
This walkthrough adds the Storefront SDK to an app you already have, and ends with a product grid filled from your Propeller catalog. It covers the four parts every app needs: the packages, a GraphQL route on your server, the providers and a first component. Pick your framework in the tabs: React shows a Next.js app with the App Router, Vue a Vite app.
To start from a complete storefront instead, use the Accelerator quickstart.
Prerequisites
- Node.js 22 and an existing Next.js or Vite app with React 18 or newer, or Vue 3.4 or newer
- Your GraphQL API URL and an API key limited to storefront use (see Keys and security)
- The id of a category in your catalog, for the product grid
Step 1: Install the packages
- React
- Vue
npm install @propeller-commerce/propeller-sdk-v2 @propeller-commerce/propeller-v2-react-ui
npm install @propeller-commerce/propeller-sdk-v2 @propeller-commerce/propeller-v2-vue-ui
Step 2: Add the GraphQL route
The SDK in the browser posts every request to a route on your own server, which adds the API key and forwards the request to Propeller. The key never reaches the browser. Put the endpoint and the key in server-only settings:
# .env.local (Next.js) or .env (Vite)
PROPELLER_GRAPHQL_ENDPOINT=https://api.helice.cloud/v2/graphql
PROPELLER_API_KEY=your-storefront-api-key
- React
- Vue
Create app/api/graphql/route.ts:
// Forwards the browser's GraphQL requests to Propeller with the storefront key.
export async function POST(request: Request) {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
apiKey: process.env.PROPELLER_API_KEY!,
};
// Forward the signed-in user's token, if there is one.
const authorization = request.headers.get('authorization');
if (authorization) headers.Authorization = authorization;
const upstream = await fetch(process.env.PROPELLER_GRAPHQL_ENDPOINT!, {
method: 'POST',
headers,
body: await request.text(),
});
return new Response(await upstream.text(), {
status: upstream.status,
headers: { 'Content-Type': 'application/json' },
});
}
In development, let the Vite dev server forward /api/graphql. Replace vite.config.ts with:
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig(({ mode }) => {
// The third argument loads settings without the VITE_ prefix, which stay on the server.
const env = loadEnv(mode, process.cwd(), '');
const endpoint = new URL(env.PROPELLER_GRAPHQL_ENDPOINT);
return {
plugins: [vue()],
server: {
proxy: {
'/api/graphql': {
target: endpoint.origin,
changeOrigin: true,
rewrite: () => endpoint.pathname,
headers: { apiKey: env.PROPELLER_API_KEY },
},
},
},
};
});
The dev server proxy does not exist in production. There, serve POST /api/graphql from your own server in the same way: add the key from a server-only setting and forward the body and the user's Authorization header.
Keep this route to the storefront key. Order actions that need the order-editor key, such as the status update after a payment, belong in your own server code. See Keys and security.
Step 3: Mount the providers
Create the SDK client and the services once, and pass them to the UI library at your app root, together with the session (the user, the language and the price display).
- React
- Vue
Create app/propeller-providers.tsx:
'use client';
import type { ReactNode } from 'react';
import { createClient } from '@propeller-commerce/propeller-sdk-v2';
import {
PropellerDepsProvider,
PropellerProvider,
createServices,
} from '@propeller-commerce/propeller-v2-react-ui';
const graphqlClient = createClient({ endpoint: '/api/graphql' });
const services = createServices(graphqlClient);
export function PropellerProviders({ children }: { children: ReactNode }) {
return (
<PropellerDepsProvider value={{ graphqlClient, services, currency: '€', configuration: {} }}>
<PropellerProvider
value={{ user: null, companyId: undefined, language: 'NL', includeTax: false, portalMode: 'open' }}
>
{children}
</PropellerProvider>
</PropellerDepsProvider>
);
}
Then wrap your root layout in it and load the stylesheet, in app/layout.tsx:
import type { ReactNode } from 'react';
import '@propeller-commerce/propeller-v2-react-ui/styles.css';
import { PropellerProviders } from './propeller-providers';
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<PropellerProviders>{children}</PropellerProviders>
</body>
</html>
);
}
In src/main.ts, install the propellerVue plugin and load the stylesheet:
import { createApp } from 'vue';
import { createClient } from '@propeller-commerce/propeller-sdk-v2';
import { propellerVue, createServices } from '@propeller-commerce/propeller-v2-vue-ui';
import '@propeller-commerce/propeller-v2-vue-ui/styles.css';
import App from './App.vue';
const graphqlClient = createClient({ endpoint: '/api/graphql' });
createApp(App)
.use(propellerVue, {
graphqlClient,
services: createServices(graphqlClient),
currency: '€',
configuration: {},
})
.mount('#app');
The session goes into the PropellerProvider component, in the next step.
A signed-in user, a Company switch or another language changes the session value, not the client. UI components explains every field.
Step 4: Render a product grid
Replace 1324 with the id of a category in your catalog.
- React
- Vue
Create app/shop/page.tsx:
import { ProductGrid } from '@propeller-commerce/propeller-v2-react-ui';
export default function ShopPage() {
return <ProductGrid categoryId={1324} />;
}
Run npm run dev and open http://localhost:3000/shop.
Replace src/App.vue with:
<script setup lang="ts">
import { PropellerProvider, ProductGrid } from '@propeller-commerce/propeller-v2-vue-ui';
</script>
<template>
<PropellerProvider :user="null" language="NL" :include-tax="false" portal-mode="open">
<ProductGrid :category-id="1324" />
</PropellerProvider>
</template>
Run npm run dev and open http://localhost:5173.
You should see the products of that category with their names and prices, for example "Tervo accuboorschroefmachine 18 V zonder accu, € 135,04 excl. VAT". In the browser's network tab, every request goes to /api/graphql and none carries an API key.
Next steps
- UI components for the components, hooks and entry points
- Keys and security before you deploy
- Authentication and authorization to sign users in and fill the session
- What's next for the rest of the Storefront SDK