From e45ca89e71f9efd9989d8df543762db42e2fcc2b Mon Sep 17 00:00:00 2001 From: Filip Drozd Date: Thu, 23 Mar 2023 13:08:17 +0100 Subject: [PATCH] fix: remove addHostToImage function --- .../api-client/src/api/getProduct/index.ts | 5 ++-- .../api-client/src/api/getProducts/index.ts | 5 ++-- .../api-client/src/api/serializers/product.ts | 25 +------------------ 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/packages/api-client/src/api/getProduct/index.ts b/packages/api-client/src/api/getProduct/index.ts index e3a1c508..05194416 100644 --- a/packages/api-client/src/api/getProduct/index.ts +++ b/packages/api-client/src/api/getProduct/index.ts @@ -1,6 +1,6 @@ import { Logger } from '@vue-storefront/core'; import { ApiContext, GetProductParams, ProductVariant } from '../../types'; -import { addHostToProductImages, deserializeSingleProductVariants } from '../serializers/product'; +import { deserializeSingleProductVariants } from '../serializers/product'; export default async function getProduct({ client, config }: ApiContext, { slug }: GetProductParams): Promise { const currency = await config.internationalization.getCurrency(); @@ -30,8 +30,7 @@ export default async function getProduct({ client, config }: ApiContext, { slug if (result.isSuccess()) { try { const data = result.success(); - const productsData = addHostToProductImages(data, config); - const deserializedVariants = deserializeSingleProductVariants(productsData); + const deserializedVariants = deserializeSingleProductVariants(data); return deserializedVariants; } catch (e) { Logger.error(e); diff --git a/packages/api-client/src/api/getProducts/index.ts b/packages/api-client/src/api/getProducts/index.ts index 6fcb9869..bcfb16af 100644 --- a/packages/api-client/src/api/getProducts/index.ts +++ b/packages/api-client/src/api/getProducts/index.ts @@ -1,6 +1,6 @@ import { Logger } from '@vue-storefront/core'; import type { ApiContext, GetProductsParams, ProductSearchResult } from '../../types'; -import { addHostToProductImages, deserializeLimitedVariants } from '../serializers/product'; +import { deserializeLimitedVariants } from '../serializers/product'; import { deserializeSearchMetadata } from '../serializers/search'; export default async function getProducts({ client, config }: ApiContext, params: GetProductsParams): Promise { @@ -50,10 +50,9 @@ export default async function getProducts({ client, config }: ApiContext, params if (result.isSuccess()) { const data = result.success(); - const productsData = addHostToProductImages(data, config); return { - data: deserializeLimitedVariants(productsData), + data: deserializeLimitedVariants(data), meta: deserializeSearchMetadata(data.meta, optionTypeFilters, productPropertyFilters) }; } else { diff --git a/packages/api-client/src/api/serializers/product.ts b/packages/api-client/src/api/serializers/product.ts index 95f63c63..7145e7e0 100644 --- a/packages/api-client/src/api/serializers/product.ts +++ b/packages/api-client/src/api/serializers/product.ts @@ -1,12 +1,11 @@ import type { JsonApiDocument, - JsonApiResponse, IProduct, IProducts, ProductAttr, RelationType } from '@spree/storefront-api-v2-sdk/dist/server'; -import type { ApiConfig, ProductVariant, OptionType, OptionValue, Image } from '../../types'; +import type { ProductVariant, OptionType, OptionValue, Image } from '../../types'; import { extractRelationships, filterAttachments } from './common'; const groupIncluded = (included, discriminators): { [key in Groups]: JsonApiDocument[] } => { @@ -229,25 +228,3 @@ export const deserializeLimitedVariants = (apiProducts: IProducts): ProductVaria }; }); }; - -const addHostToImage = (image, config: ApiConfig) => ({ - ...image, - attributes: { - ...image.attributes, - styles: image.attributes?.styles ? image.attributes.styles.map((style) => ({ - width: style.width, - height: style.height, - url: (config.assetsUrl || config.backendUrl) + style.url - })) : [] - } -}); - -const addHostToIncluded = (included: JsonApiDocument[], config: ApiConfig) => - included.map((e) => - e.type === 'image' ? addHostToImage(e, config) : e - ); - -export const addHostToProductImages = (apiProductsData: DocumentType, config: ApiConfig): DocumentType => ({ - ...apiProductsData, - included: addHostToIncluded(apiProductsData.included, config) -});