diff --git a/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.test.ts b/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.test.ts index 6cf937e0eff..6f8647e9136 100644 --- a/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.test.ts +++ b/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.test.ts @@ -1,7 +1,7 @@ import {SortBy} from '../../../../product-listing.index'; import {buildMockProductListingV2APIClient} from '../../../../test/mock-product-listing-v2-api-client'; import {PlatformClient} from '../../../platform-client'; -import {ProductListingV2APIClient} from './product-listing-v2-api-client'; +import {ProductListingAPIClient} from './product-listing-v2-api-client'; import {Mode} from './product-listing-v2-params'; import { ProductListingV2SuccessResponse, @@ -14,7 +14,7 @@ describe('product listing v2 api client', () => { const accessToken = 'some-access-token'; const trackingId = 'some-tracking-id'; - let client: ProductListingV2APIClient; + let client: ProductListingAPIClient; let platformCallMock: jest.Mock; beforeEach(() => { diff --git a/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.ts b/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.ts index 99080518904..e0e5f4bb28c 100644 --- a/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.ts +++ b/packages/headless/src/api/commerce/product-listings/v2/product-listing-v2-api-client.ts @@ -12,44 +12,44 @@ import { import {buildAPIResponseFromErrorOrThrow} from '../../../search/search-api-error-response'; import { buildProductListingV2Request, - ProductListingV2Request, - ProductListingV2SuccessResponse, + ProductListingV2Request as ProductListingRequest, + ProductListingV2SuccessResponse as ProductListingSuccessResponse, } from './product-listing-v2-request'; export interface AsyncThunkProductListingV2Options< T extends Partial > { state: T; - rejectValue: ProductListingV2APIErrorStatusResponse; + rejectValue: ProductListingAPIErrorStatusResponse; extra: ProductListingV2ThunkExtraArguments; } /** - * Initialization options for the `ProductListingV2APIClient`. + * The initialization options for the product listing API client. */ -export interface ProductListingV2APIClientOptions { +export interface ProductListingAPIClientOptions { logger: Logger; preprocessRequest: PreprocessRequest; } /** - * Defines a Product Listing API response. It can represent an error or a successful response. + * A product listing API response. */ export type ProductListingAPIResponse = | ProductListingAPISuccessResponse | ProductListingAPIErrorResponse; /** - * Defines a Product Listing API successful response. + * A product listing API successful response. */ export interface ProductListingAPISuccessResponse { success: TContent; } /** - * Defines the content of a Product Listing API error response. + * The content of a product listing API error response. */ -export interface ProductListingV2APIErrorStatusResponse { +export interface ProductListingAPIErrorStatusResponse { statusCode: number; message: string; type: string; @@ -57,30 +57,24 @@ export interface ProductListingV2APIErrorStatusResponse { } /** - * Defines a Product Listing API error response. + * A Product Listing API error response. */ export interface ProductListingAPIErrorResponse { - error: ProductListingV2APIErrorStatusResponse; + error: ProductListingAPIErrorStatusResponse; } /** - * The client to use to interface with the Product Listing API. + * The client to use to interface with the product listing API. */ -export class ProductListingV2APIClient implements FacetSearchAPIClient { +export class ProductListingAPIClient implements FacetSearchAPIClient { constructor( - private options: ProductListingV2APIClientOptions, + private options: ProductListingAPIClientOptions, private searchAPIClient: SearchAPIClient ) {} - /** - * Retrieves the product listing from the API. - * - * @param req - The request parameters. - * @returns The products for the requested product listing. - */ async getListing( - req: ProductListingV2Request - ): Promise> { + req: ProductListingRequest + ): Promise> { const response = await PlatformClient.call({ ...buildProductListingV2Request(req), ...this.options, @@ -92,8 +86,8 @@ export class ProductListingV2APIClient implements FacetSearchAPIClient { const body = await response.json(); return response.ok - ? {success: body as ProductListingV2SuccessResponse} - : {error: body as ProductListingV2APIErrorStatusResponse}; + ? {success: body as ProductListingSuccessResponse} + : {error: body as ProductListingAPIErrorStatusResponse}; } async facetSearch(req: FacetSearchRequest): Promise { diff --git a/packages/headless/src/app/commerce-engine/commerce-engine.ts b/packages/headless/src/app/commerce-engine/commerce-engine.ts index 700bf32d898..b732b404bfc 100644 --- a/packages/headless/src/app/commerce-engine/commerce-engine.ts +++ b/packages/headless/src/app/commerce-engine/commerce-engine.ts @@ -1,6 +1,6 @@ import {StateFromReducersMapObject} from '@reduxjs/toolkit'; import {Logger} from 'pino'; -import {ProductListingV2APIClient} from '../../api/commerce/product-listings/v2/product-listing-v2-api-client'; +import {ProductListingAPIClient} from '../../api/commerce/product-listings/v2/product-listing-v2-api-client'; import {NoopPreprocessRequest} from '../../api/preprocess-request'; import {SearchAPIClient} from '../../api/search/search-api-client'; import { @@ -17,7 +17,6 @@ import { ExternalEngineOptions, } from '../engine'; import {buildLogger} from '../logger'; -import {ProductListingThunkExtraArguments} from '../product-listing-thunk-extra-arguments'; import {ProductListingV2ThunkExtraArguments} from '../product-listing-v2-thunk-extra-arguments'; import {SearchEngineConfiguration} from '../search-engine/search-engine-configuration'; import {buildThunkExtraArguments} from '../thunk-extra-arguments'; @@ -39,7 +38,7 @@ type CommerceEngineState = StateFromReducersMapObject & export interface CommerceEngine extends CoreEngine< State & CommerceEngineState, - ProductListingThunkExtraArguments + ProductListingV2ThunkExtraArguments > {} export interface CommerceEngineOptions @@ -120,7 +119,7 @@ function createCommerceAPIClient( logger: Logger, searchAPIClient: SearchAPIClient ) { - return new ProductListingV2APIClient( + return new ProductListingAPIClient( { logger, preprocessRequest: diff --git a/packages/headless/src/app/product-listing-v2-thunk-extra-arguments.ts b/packages/headless/src/app/product-listing-v2-thunk-extra-arguments.ts index 8955a3bbe58..d09b6950fb0 100644 --- a/packages/headless/src/app/product-listing-v2-thunk-extra-arguments.ts +++ b/packages/headless/src/app/product-listing-v2-thunk-extra-arguments.ts @@ -1,5 +1,5 @@ -import {ProductListingV2APIClient} from '../api/commerce/product-listings/v2/product-listing-v2-api-client'; +import {ProductListingAPIClient} from '../api/commerce/product-listings/v2/product-listing-v2-api-client'; import {ClientThunkExtraArguments} from './thunk-extra-arguments'; export interface ProductListingV2ThunkExtraArguments - extends ClientThunkExtraArguments {} + extends ClientThunkExtraArguments {} diff --git a/packages/headless/src/features/product-listing/v2/product-listing-v2-state.ts b/packages/headless/src/features/product-listing/v2/product-listing-v2-state.ts index 6f4c6cfaa92..24ed6e158c3 100644 --- a/packages/headless/src/features/product-listing/v2/product-listing-v2-state.ts +++ b/packages/headless/src/features/product-listing/v2/product-listing-v2-state.ts @@ -1,4 +1,4 @@ -import {ProductListingV2APIErrorStatusResponse} from '../../../api/commerce/product-listings/v2/product-listing-v2-api-client'; +import {ProductListingAPIErrorStatusResponse} from '../../../api/commerce/product-listings/v2/product-listing-v2-api-client'; import {Context} from '../../../api/commerce/product-listings/v2/product-listing-v2-params'; import {Mode} from '../../../api/commerce/product-listings/v2/product-listing-v2-params'; import {ProductRecommendation} from '../../../api/search/search/product-recommendation'; @@ -9,7 +9,7 @@ export interface ProductListingV2State { locale: string; mode: Mode; clientId: string; - error: ProductListingV2APIErrorStatusResponse | null; + error: ProductListingAPIErrorStatusResponse | null; isLoading: boolean; responseId: string; products: ProductRecommendation[]; diff --git a/packages/headless/src/test/mock-product-listing-v2-api-client.ts b/packages/headless/src/test/mock-product-listing-v2-api-client.ts index 387ae5f2fa7..77840cc21b9 100644 --- a/packages/headless/src/test/mock-product-listing-v2-api-client.ts +++ b/packages/headless/src/test/mock-product-listing-v2-api-client.ts @@ -1,15 +1,15 @@ import pino from 'pino'; import { - ProductListingV2APIClient, - ProductListingV2APIClientOptions, + ProductListingAPIClient, + ProductListingAPIClientOptions, } from '../api/commerce/product-listings/v2/product-listing-v2-api-client'; import {NoopPreprocessRequest} from '../api/preprocess-request'; import {buildMockSearchAPIClient} from './mock-search-api-client'; export function buildMockProductListingV2APIClient( - options?: Partial + options?: Partial ) { - return new ProductListingV2APIClient( + return new ProductListingAPIClient( { preprocessRequest: NoopPreprocessRequest, logger: pino({level: 'silent'}),