Remove 'spree' prefix from isomorphicConfig and add lastUpdatedProductsPrerenderCount

This commit is contained in:
tniezg 2021-08-19 12:24:07 +02:00
parent 7d5a63bbf4
commit ed49ac8833
8 changed files with 23 additions and 18 deletions

View File

@ -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

View File

@ -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
),
})

View File

@ -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({

View File

@ -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({

View File

@ -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',
]
)

View File

@ -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

View File

@ -28,7 +28,7 @@ const normalizeProduct = (
const images = getMediaGallery(
spreeImageRecords,
createGetAbsoluteImageUrl(requireConfigValue('spreeImageHost') as string)
createGetAbsoluteImageUrl(requireConfigValue('imageHost') as string)
)
const price: ProductPrice = {

View File

@ -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 {