diff --git a/docs/content/4.sdk/2.getting-started/1.index.md b/docs/content/4.sdk/2.getting-started/1.index.md index 5c0a9d4e8f..6550e75002 100644 --- a/docs/content/4.sdk/2.getting-started/1.index.md +++ b/docs/content/4.sdk/2.getting-started/1.index.md @@ -45,6 +45,7 @@ It is not necessary to name the file `sdk.config.ts` specifically or to keep it import { contentfulModule } from "@vsf-enterprise/contentful-sdk"; import { CreateSdkOptions, createSdk } from "@vue-storefront/next"; import { UnifiedEndpoints } from "storefront-middleware/types"; +import { env } from 'next-runtime-env'; const options: CreateSdkOptions = { middleware: { @@ -52,14 +53,18 @@ const options: CreateSdkOptions = { }, }; +const cdnCacheBustingId = env('NEXT_PUBLIC_CDN_CACHE_BUSTING_ID') ?? 'no-cache-busting-id-provided'; + export const { getSdk } = createSdk( options, - ({ buildModule, middlewareUrl, middlewareModule, getRequestHeaders }) => ({ + ({ buildModule, middlewareUrl, middlewareModule, getRequestHeader, defaults }) => ({ commerce: buildModule(middlewareModule, { apiUrl: middlewareUrl + "/commerce", defaultRequestConfig: { headers: getRequestHeaders(), }, + cdnCacheBustingId, + methodsRequestConfig: defaults.unifiedCommerce.middlewareModule.defaultMethodsRequestConfig, }), cms: buildModule(contentfulModule, { apiUrl: middlewareUrl + "/cms", @@ -81,6 +86,8 @@ Let's break down the code above: - The `middlewareModule` is an SDK module that ensures communication with the Server Middleware. It takes the `UnifiedEndpoints` type as a generic parameter. The `UnifiedEndpoints` type is a type that represents the endpoints of the Server Middleware. +- The `defaults` is the default configuration of the SDK. + - The `getRequestHeaders` function is used to provide the incoming headers within your requests. You can use `getRequestHeaders` to access and proxy the initial cookie headers to SDK requests during SSR. Initial headers could be provided by the [`getSdk`](#getsdk) method. Check out examples there: - Next Pages Router [link](https://github.com/vuestorefront/vue-storefront/tree/main/packages/storefront/packages/next/__tests__/apps/pages-router) diff --git a/docs/content/4.sdk/2.getting-started/2.middleware-module.md b/docs/content/4.sdk/2.getting-started/2.middleware-module.md index 676e4351e2..f614f0186a 100644 --- a/docs/content/4.sdk/2.getting-started/2.middleware-module.md +++ b/docs/content/4.sdk/2.getting-started/2.middleware-module.md @@ -14,6 +14,7 @@ In Next, `middlewareModule` is available in the `createSdk` function. // sdk/sdk.config.ts import { CreateSdkOptions, createSdk } from "@vue-storefront/next"; import { UnifiedEndpoints } from "storefront-middleware/types"; +import { env } from 'next-runtime-env'; const options: CreateSdkOptions = { middleware: { @@ -21,14 +22,18 @@ const options: CreateSdkOptions = { }, }; +const cdnCacheBustingId = env('NEXT_PUBLIC_CDN_CACHE_BUSTING_ID') ?? 'no-cache-busting-id-provided'; + export const { getSdk } = createSdk( options, - ({ buildModule, middlewareUrl, middlewareModule, getRequestHeaders }) => ({ + ({ buildModule, middlewareUrl, middlewareModule, getRequestHeaders, defaults }) => ({ commerce: buildModule(middlewareModule, { apiUrl: middlewareUrl + "/commerce", defaultRequestConfig: { headers: getRequestHeaders(), }, + cdnCacheBustingId, + methodsRequestConfig: defaults.unifiedCommerce.middlewareModule.defaultMethodsRequestConfig, }), }) ); @@ -61,6 +66,7 @@ import { UnifiedEndpoints } from "storefront-middleware/types"; export const sdk = initSDK({ commerce: buildModule(middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, }), }); ``` @@ -83,6 +89,7 @@ type Endpoints = { const sdk = initSDK({ commerce: buildModule(middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, }), }); @@ -101,6 +108,7 @@ import { UnifiedEndpoints } from "storefront-middleware/types"; export const sdk = initSDK({ commerce: buildModule(middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, }), }); @@ -115,6 +123,7 @@ import { Endpoints } from "@vsf-enterprise/sapcc-api"; export const sdk = initSDK({ commerce: buildModule(middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, }), }); ``` @@ -139,6 +148,7 @@ export const sdk = initSDK({ commerce: buildModule(middlewareModule, { apiUrl: "/api/commerce", ssrApiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, defaultRequestConfig: { headers: { "X-Api-Key": "123", @@ -263,6 +273,7 @@ import { SdkHttpError } from "@vue-storefront/sdk"; export const sdk = initSDK({ commerce: buildModule(middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, httpClient: async (url, params, config) => { try { const { data } = await axios(url, { @@ -418,6 +429,7 @@ However, you can always specify the headers manually by passing them to the `def export const sdk = initSDK({ commerce: buildModule(middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, defaultRequestConfig: { headers: { Cookie: "name=value", @@ -466,6 +478,7 @@ import { CustomEndpoints } from "storefront-middleware/types"; export const sdk = initSDK({ custom: buildModule(middlewareModule, { apiUrl: "http://localhost:8181/custom", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, }), }); ``` diff --git a/docs/content/4.sdk/3.advanced/1.extending-module.md b/docs/content/4.sdk/3.advanced/1.extending-module.md index b56fc298f4..e066354b42 100644 --- a/docs/content/4.sdk/3.advanced/1.extending-module.md +++ b/docs/content/4.sdk/3.advanced/1.extending-module.md @@ -20,6 +20,7 @@ const sdk = initSDK({ middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, }, { extend: { @@ -40,6 +41,7 @@ const sdk = initSDK({ middlewareModule, { apiUrl: "http://localhost:8181/commerce", + cdnCacheBustingId: /** pass the commit hash of the middleware here */, }, (extensionParams, { methods, context }) => ({ extend: {