From ed49ac8833da48390634fd72ee48912133a74b1e Mon Sep 17 00:00:00 2001 From: tniezg Date: Thu, 19 Aug 2021 12:24:07 +0200 Subject: [PATCH] Remove 'spree' prefix from isomorphicConfig and add lastUpdatedProductsPrerenderCount --- framework/spree/.env.template | 1 + .../spree/api/operations/get-site-info.ts | 4 ++-- framework/spree/api/utils/create-api-fetch.ts | 2 +- framework/spree/fetcher.ts | 2 +- framework/spree/isomorphic-config.ts | 22 +++++++++++-------- framework/spree/utils/normalize-cart.ts | 4 ++-- framework/spree/utils/normalize-product.ts | 2 +- .../spree/utils/validate-cookie-expire.ts | 4 ++-- 8 files changed, 23 insertions(+), 18 deletions(-) diff --git a/framework/spree/.env.template b/framework/spree/.env.template index 60698d794..7f584f8bf 100644 --- a/framework/spree/.env.template +++ b/framework/spree/.env.template @@ -13,3 +13,4 @@ NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=localhost NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_ID=1 NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_ID=27 NEXT_PUBLIC_SPREE_SHOW_SINGLE_VARIANT_OPTIONS=false +NEXT_PUBLIC_SPREE_LAST_UPDATED_PRODUCTS_PRERENDER_COUNT=10 diff --git a/framework/spree/api/operations/get-site-info.ts b/framework/spree/api/operations/get-site-info.ts index e54964744..b094916c9 100644 --- a/framework/spree/api/operations/get-site-info.ts +++ b/framework/spree/api/operations/get-site-info.ts @@ -93,7 +93,7 @@ export default function getSiteInfoOperation({ SpreeSdkVariables >('__UNUSED__', { variables: createVariables( - requireConfigValue('spreeCategoriesTaxonomyId') as string + requireConfigValue('categoriesTaxonomyId') as string ), }) @@ -106,7 +106,7 @@ export default function getSiteInfoOperation({ SpreeSdkVariables >('__UNUSED__', { variables: createVariables( - requireConfigValue('spreeBrandsTaxonomyId') as string + requireConfigValue('brandsTaxonomyId') as string ), }) diff --git a/framework/spree/api/utils/create-api-fetch.ts b/framework/spree/api/utils/create-api-fetch.ts index 43227ab57..c4babcc83 100644 --- a/framework/spree/api/utils/create-api-fetch.ts +++ b/framework/spree/api/utils/create-api-fetch.ts @@ -20,7 +20,7 @@ const createApiFetch: ( _getConfig ) => { const client = makeClient({ - host: requireConfigValue('spreeApiHost') as string, + host: requireConfigValue('apiHost') as string, fetcherType: 'custom', createFetcher: (fetcherOptions) => { return createCustomizedFetchFetcher({ diff --git a/framework/spree/fetcher.ts b/framework/spree/fetcher.ts index 001fdb6dd..3b6766b38 100644 --- a/framework/spree/fetcher.ts +++ b/framework/spree/fetcher.ts @@ -15,7 +15,7 @@ import type { GraphQLFetcherResult } from '@commerce/api' import createCustomizedFetchFetcher from './utils/create-customized-fetch-fetcher' const client = makeClient({ - host: requireConfigValue('spreeApiHost') as string, + host: requireConfigValue('apiHost') as string, fetcherType: 'custom', createFetcher: (fetcherOptions) => { return createCustomizedFetchFetcher({ diff --git a/framework/spree/isomorphic-config.ts b/framework/spree/isomorphic-config.ts index ed6a9fa34..6255b1535 100644 --- a/framework/spree/isomorphic-config.ts +++ b/framework/spree/isomorphic-config.ts @@ -1,34 +1,38 @@ import forceIsomorphicConfigValues from './utils/force-isomorphic-config-values' import requireConfig from './utils/require-config' import validateCookieExpire from './utils/validate-cookie-expire' +import validateProductsPrerenderCount from './utils/validate-products-prerender-count' const isomorphicConfig = { - spreeApiHost: process.env.NEXT_PUBLIC_SPREE_API_HOST, + apiHost: process.env.NEXT_PUBLIC_SPREE_API_HOST, defaultLocale: process.env.NEXT_PUBLIC_SPREE_DEFAULT_LOCALE, cartCookieName: process.env.NEXT_PUBLIC_SPREE_CART_COOKIE_NAME, cartCookieExpire: validateCookieExpire( process.env.NEXT_PUBLIC_SPREE_CART_COOKIE_EXPIRE ), - spreeImageHost: process.env.NEXT_PUBLIC_SPREE_IMAGE_HOST, - spreeCategoriesTaxonomyId: - process.env.NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_ID, - spreeBrandsTaxonomyId: process.env.NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_ID, + imageHost: process.env.NEXT_PUBLIC_SPREE_IMAGE_HOST, + categoriesTaxonomyId: process.env.NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_ID, + brandsTaxonomyId: process.env.NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_ID, showSingleVariantOptions: process.env.NEXT_PUBLIC_SPREE_SHOW_SINGLE_VARIANT_OPTIONS === 'true', + lastUpdatedProductsPrerenderCount: validateProductsPrerenderCount( + process.env.NEXT_PUBLIC_SPREE_LAST_UPDATED_PRODUCTS_PRERENDER_COUNT + ), } export default forceIsomorphicConfigValues( isomorphicConfig, [], [ - 'spreeApiHost', + 'apiHost', 'defaultLocale', 'cartCookieName', 'cartCookieExpire', - 'spreeImageHost', - 'spreeCategoriesTaxonomyId', - 'spreeBrandsTaxonomyId', + 'imageHost', + 'categoriesTaxonomyId', + 'brandsTaxonomyId', 'showSingleVariantOptions', + 'lastUpdatedProductsPrerenderCount', ] ) diff --git a/framework/spree/utils/normalize-cart.ts b/framework/spree/utils/normalize-cart.ts index f4106a7eb..47489193c 100644 --- a/framework/spree/utils/normalize-cart.ts +++ b/framework/spree/utils/normalize-cart.ts @@ -54,7 +54,7 @@ const normalizeVariant = ( const variantImage = getMediaGallery( spreeVariantImageRecords, - createGetAbsoluteImageUrl(requireConfigValue('spreeImageHost') as string) + createGetAbsoluteImageUrl(requireConfigValue('imageHost') as string) )[0] if (variantImage) { @@ -68,7 +68,7 @@ const normalizeVariant = ( const productImage = getMediaGallery( spreeProductImageRecords, - createGetAbsoluteImageUrl(requireConfigValue('spreeImageHost') as string) + createGetAbsoluteImageUrl(requireConfigValue('imageHost') as string) )[0] lineItemImage = productImage diff --git a/framework/spree/utils/normalize-product.ts b/framework/spree/utils/normalize-product.ts index 4f2781851..f01fea089 100644 --- a/framework/spree/utils/normalize-product.ts +++ b/framework/spree/utils/normalize-product.ts @@ -28,7 +28,7 @@ const normalizeProduct = ( const images = getMediaGallery( spreeImageRecords, - createGetAbsoluteImageUrl(requireConfigValue('spreeImageHost') as string) + createGetAbsoluteImageUrl(requireConfigValue('imageHost') as string) ) const price: ProductPrice = { diff --git a/framework/spree/utils/validate-cookie-expire.ts b/framework/spree/utils/validate-cookie-expire.ts index 35e043439..1bd987273 100644 --- a/framework/spree/utils/validate-cookie-expire.ts +++ b/framework/spree/utils/validate-cookie-expire.ts @@ -1,8 +1,8 @@ -const validateCookieExpire = (expire: unknown) => { +const validateCookieExpire = (expire: unknown): number => { let expireInteger: number if (typeof expire === 'string') { - expireInteger = parseFloat(expire || '') + expireInteger = parseFloat(expire) } else if (typeof expire === 'number') { expireInteger = expire } else {