### Install Alokai SDK with Yarn Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/sdk/README.md Installs the core Alokai SDK package using the Yarn package manager. This is the first step to integrate the SDK into your project. ```bash yarn add @vue-storefront/sdk ``` -------------------------------- ### Install SAP Commerce Cloud SDK Module with Yarn Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/sdk/README.md Installs a specific SDK module for SAP Commerce Cloud using Yarn. Note that module installation processes can vary and may require additional dependencies. ```bash yarn add @vsf-enterprise/sapcc-sdk ``` -------------------------------- ### Generate Alokai Project using CLI Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/cli/README.md Use this command to initialize a new Alokai project. It requires the '@vue-storefront/cli' package to be installed via npx. ```bash npx @vue-storefront/cli generate store ``` -------------------------------- ### Changeset CLI Commands for Releasing Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/changesets/README.md Demonstrates the usage of the Changeset CLI for creating new changesets and publishing releases. It includes examples of providing descriptive messages for added and removed features, and the expected markdown output. ```shell # 1. Create a new changeset changeset # Example changeset messages: # [REMOVED] getPhysicalStores method was removed from the Middleware and SDK. # [ADDED] getPhysicalStores method that allows fetching a list of physical stores and filtering it by their location. # 2. Commit changes and merge to main branch # 3. After merging, Changeset will create a PR for release. # The changelog will be automatically generated. ``` -------------------------------- ### Alokai CLI for Project and Integration Generation (Bash) Source: https://context7.com/vuestorefront/vue-storefront/llms.txt The Alokai CLI facilitates project setup, integration boilerplate creation, and API endpoint generation. It streamlines development by automating the creation of necessary files and directory structures for new features and integrations. ```bash # Create new Alokai storefront project npx @vue-storefront/cli generate store # Create new integration boilerplate npx @vue-storefront/cli create integration my-commerce --framework nuxt # Add new API endpoint to existing integration npx @vue-storefront/cli add endpoint getProductReviews # After running CLI commands, generated structure: # api/ # └── getProductReviews/ # └── index.ts # sdk/ # └── getProductReviews.ts # pages/ # └── getProductReviews.vue ``` -------------------------------- ### List Installed Plugins using Alokai CLI Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/cli/README.md Lists all installed plugins for the Alokai CLI. The '--core' flag can be used to filter and display only core plugins. ```bash USAGE $ @vue-storefront/cli plugins [--core] FLAGS --core Show core plugins. DESCRIPTION List installed plugins. EXAMPLES $ @vue-storefront/cli plugins ``` -------------------------------- ### Install Vue Storefront Changesets CLI Tool Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/changesets/README.md Installs the `@vue-storefront/changesets` package as a development dependency using Yarn. This package provides custom changelog formatting for the Changesets CLI. ```shell yarn add -D @vue-storefront/changesets ``` -------------------------------- ### Changeset Changelog Formatting Example Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/changesets/README.md Illustrates how the custom `@vue-storefront/changesets` package transforms raw changeset descriptions into a more readable markdown format for release notes. It shows the transformation of specific change types like REMOVED and ADDED. ```markdown Raw changeset entries: [REMOVED] getPhysicalStores method was removed from the Middleware and SDK. [ADDED] getPhysicalStores method that allows fetching a list of physical stores and filtering it by their location. Transformed markdown output: - **[REMOVED]** getPhysicalStores method was removed from the Middleware and SDK. - **[ADDED]** getPhysicalStores method that allows fetching a list of physical stores and filtering it by their location. ``` -------------------------------- ### Update Vue Storefront CLI Plugins Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/cli/README.md Updates all installed Vue Storefront CLI plugins to their latest versions. This command does not require any arguments. Verbose output can be enabled using the -v flag. ```bash @vue-storefront/cli plugins update [-h] [-v] ``` -------------------------------- ### Extend Alokai SDK Modules with Custom Methods Source: https://context7.com/vuestorefront/vue-storefront/llms.txt Demonstrates how to extend existing Alokai SDK modules with custom methods, enabling additional functionality like fetching specific product types or custom endpoints. It uses `buildModule` with a custom extension function that can access base methods and the request context. The example shows how to add methods for fetching blue products and custom data, as well as combining operations. ```typescript import { initSDK, buildModule, middlewareModule } from '@vue-storefront/sdk'; import type { SAPCCModuleType } from '@vsf-enterprise/sapcc-sdk'; // Define extension with custom methods const customExtension = (extensionOptions, { methods, context }) => ({ extend: { // Add new method that uses existing module methods async getBlueProducts(params) { const products = await methods.getProducts({ ...params, color: 'blue' }); return products; }, // Use requestSender directly for custom endpoints async getCustomData(params) { const response = await context.requestSender('customEndpoint', [params]); return response; }, // Combine multiple operations async getProductsWithReviews(productId) { const product = await methods.getProduct({ id: productId }); const reviews = await context.requestSender('getReviews', [{ productId }]); return { ...product, reviews }; } } }); // Build module with extension const sdkConfig = { sapcc: buildModule( middlewareModule, { apiUrl: 'http://localhost:4000/sapcc', ssrApiUrl: 'http://localhost:8181/sapcc' }, customExtension ) }; export const sdk = initSDK(sdkConfig); // Use extended methods const blueProducts = await sdk.sapcc.getBlueProducts({ limit: 10 }); const productWithReviews = await sdk.sapcc.getProductsWithReviews('prod-123'); ``` -------------------------------- ### Vue Storefront Product Data JSON Example Source: https://github.com/vuestorefront/vue-storefront/wiki/Grouped-products-support This JSON snippet represents a product's data structure within Vue Storefront. It includes essential fields such as product name, SKU, pricing, media gallery entries, tier prices, and custom attributes. This structure is commonly used for fetching and displaying product information on e-commerce storefronts. ```json { "image_size_x": 0, "image_size_y": 0, "values": [ { "title": "string", "sort_order": 0, "price": 0, "price_type": "string", "sku": "string", "option_type_id": 0 } ], "extension_attributes": {}, "media_gallery_entries": [ { "id": 0, "media_type": "string", "label": "string", "position": 0, "disabled": true, "types": [ "string" ], "file": "string", "content": { "base64_encoded_data": "string", "type": "string", "name": "string" }, "extension_attributes": { "video_content": { "media_type": "string", "video_provider": "string", "video_url": "string", "video_title": "string", "video_description": "string", "video_metadata": "string" } } } ], "tier_prices": [ { "customer_group_id": 0, "qty": 0, "value": 0, "extension_attributes": {} } ], "custom_attributes": [ { "attribute_code": "string", "value": "string" } ] } ``` -------------------------------- ### Apply Alokai SDK Interceptors for Cross-Cutting Concerns Source: https://context7.com/vuestorefront/vue-storefront/llms.txt Illustrates how to use interceptors with the Alokai SDK to handle cross-cutting concerns such as logging, authentication, and data transformation. Interceptors can modify arguments before a request (`before`) or transform results after a request (`after`). This example shows adding an authorization header and parsing price data. ```typescript import { initSDK, buildModule, middlewareModule } from '@vue-storefront/sdk'; // Define interceptors extension const loggingExtension = { interceptors: [ { // Before interceptors modify arguments before: { getProducts: async (args) => { console.log('getProducts called with:', args); // Add authentication token return [{ ...args[0], headers: { ...args[0]?.headers, 'Authorization': `Bearer ${getAuthToken()}` } }]; } }, // After interceptors modify results after: { getProducts: async (result) => { console.log('getProducts returned:', result); // Transform response data return { ...result, items: result.items.map(item => ({ ...item, price: parseFloat(item.price) })) }; } } } ] }; // Build module with interceptors const sdkConfig = { commerce: buildModule( middlewareModule, { apiUrl: 'http://localhost:4000/api' }, loggingExtension ) }; export const sdk = initSDK(sdkConfig); function getAuthToken() { return localStorage.getItem('auth_token') || ''; } ``` -------------------------------- ### Axios Request Sender for HTTP Operations (TypeScript) Source: https://context7.com/vuestorefront/vue-storefront/llms.txt The AxiosRequestSender class simplifies HTTP operations by providing a fluent API for configuring requests. It includes automatic fallback from GET to POST for large payloads (414 URI too long errors) and allows custom error handlers and configurations. ```typescript import { AxiosRequestSender } from '@vue-storefront/sdk-axios-request-sender'; import axios from 'axios'; // Create axios client const client = axios.create({ baseURL: 'https://api.example.com', timeout: 5000 }); // Use request sender in SDK method async function getProducts(props, options) { try { const result = await new AxiosRequestSender(client) .setUrl('/products') .setMethod('GET') .setProps(props) .setConfig(options?.axiosRequestConfig) .send(); return result; } catch (error) { console.error('Failed to fetch products:', error); throw error; } } // Custom error handling async function searchProducts(searchTerm, filters) { const result = await new AxiosRequestSender(client) .setUrl('/search') .setMethod('GET') .setProps({ q: searchTerm, filters }) .setErrorHandler((error) => { if (error?.response?.status === 404) { return { items: [], total: 0 }; } throw error; }) .send(); return result; } // POST request with custom config async function createOrder(orderData) { const result = await new AxiosRequestSender(client) .setUrl('/orders') .setMethod('POST') .setProps(orderData) .setConfig({ headers: { 'X-Api-Version': '2.0', 'Content-Type': 'application/json' } }) .send(); return result; } // Automatic fallback for large GET requests async function complexSearch(params) { // If URI too long (414), automatically retries as POST const result = await new AxiosRequestSender(client) .setUrl('/search/advanced') .setMethod('GET') .setProps(params) .send(); return result; } ``` -------------------------------- ### Initialize Alokai SDK with SAPCC Module Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/sdk/README.md Demonstrates the initialization of the Alokai SDK with the SAP Commerce Cloud module. It shows how to import necessary functions and types, configure module-specific options like API URLs, and finally initialize the SDK client. ```javascript // SAPCC Example import { sapccModule, SAPCCModuleType } from '@vsf-enterprise/sapcc-sdk'; import { initSDK, buildModule } from '@vue-storefront/sdk'; const sdkConfig = { sapcc: buildModule( sapccModule, { apiUrl: 'http://localhost:8181/sapcc', ssrApiUrl: 'http://localhost:8181/sapcc' } ) }; export const sdk = initSDK(sdkConfig); ``` -------------------------------- ### Display Help for Alokai CLI Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/cli/README.md Shows help information for the Alokai CLI. It can display help for specific commands and optionally include nested commands using the '-n' flag. ```bash USAGE $ @vue-storefront/cli help [COMMANDS] [-n] ARGUMENTS COMMANDS Command to show help for. FLAGS -n, --nested-commands Include all nested commands in the output. DESCRIPTION Display help for @vue-storefront/cli. ``` -------------------------------- ### Initialize Alokai SDK with Middleware Modules Source: https://context7.com/vuestorefront/vue-storefront/llms.txt Initializes the Alokai SDK with specified middleware modules and configures communication endpoints for an eCommerce platform. It utilizes `initSDK`, `buildModule`, and `middlewareModule` from the SDK. The function returns a promise that resolves with product data or throws an error on failure. ```typescript import { initSDK, buildModule, middlewareModule } from '@vue-storefront/sdk'; import type { SAPCCEndpoints } from './types'; // Define SDK configuration with module const sdkConfig = { sapcc: buildModule(middlewareModule, { apiUrl: 'http://localhost:4000/sapcc', ssrApiUrl: 'http://localhost:8181/sapcc' }) }; // Initialize SDK with type-safe configuration export const sdk = initSDK(sdkConfig); // Use SDK methods to call backend endpoints async function fetchProducts() { try { const products = await sdk.sapcc.getProducts({ category: 'electronics', limit: 20 }); return products; } catch (error) { console.error('Failed to fetch products:', error); throw error; } } ``` -------------------------------- ### Create Specific Integration Boilerplate using Alokai CLI Source: https://github.com/vuestorefront/vue-storefront/blob/main/packages/cli/README.md Generates boilerplate code for a specific integration. This command allows specifying the framework (nuxt or next) via the '-t' flag and is part of the '@vue-storefront/cli'. ```bash USAGE $ @vue-storefront/cli create integration [NAME] [-t nuxt|next] FLAGS -t, --framework=