@reactionary/provider-commercetools 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/capability-descriptors.js +274 -0
- package/core/initialize.js +26 -135
- package/core/initialize.types.js +8 -0
- package/factories/cart/cart.factory.js +108 -0
- package/factories/category/category.factory.js +38 -0
- package/factories/checkout/checkout-initializer-overrides.example.js +67 -0
- package/factories/checkout/checkout.factory.js +232 -0
- package/factories/identity/identity.factory.js +13 -0
- package/factories/inventory/inventory.factory.js +29 -0
- package/factories/order/order.factory.js +113 -0
- package/factories/order-search/order-search.factory.js +67 -0
- package/factories/price/price.factory.js +51 -0
- package/factories/product/product-factory-baseline.example.js +10 -0
- package/factories/product/product-factory-schema-and-parse-extension.example.js +25 -0
- package/factories/product/product-factory-schema-extension.example.js +18 -0
- package/factories/product/product-initializer-factory-extension.example.js +33 -0
- package/factories/product/product-provider-custom-method-only.example.js +38 -0
- package/factories/product/product-provider-schema-signature-extension.example.js +46 -0
- package/factories/product/product.factory.js +150 -0
- package/factories/product/utils.example.js +8 -0
- package/factories/product-associations/product-associations.factory.js +62 -0
- package/factories/product-list/product-list.factory.js +61 -0
- package/factories/product-reviews/product-reviews.factory.js +39 -0
- package/factories/product-search/product-search.factory.js +113 -0
- package/factories/profile/profile.factory.js +61 -0
- package/factories/store/store.factory.js +28 -0
- package/index.js +15 -0
- package/package.json +2 -2
- package/providers/cart.provider.js +14 -126
- package/providers/category.provider.js +9 -41
- package/providers/checkout.provider.js +20 -233
- package/providers/identity.provider.js +22 -9
- package/providers/inventory.provider.js +3 -21
- package/providers/order-search.provider.js +4 -76
- package/providers/order.provider.js +3 -111
- package/providers/price.provider.js +15 -35
- package/providers/product-associations.provider.js +24 -71
- package/providers/product-list.provider.js +13 -12
- package/providers/product-reviews.provider.js +15 -8
- package/providers/product-search.provider.js +4 -112
- package/providers/product.provider.js +5 -139
- package/providers/profile.provider.js +9 -52
- package/providers/store.provider.js +3 -20
- package/schema/capabilities.schema.js +25 -0
- package/src/core/capability-descriptors.d.ts +16 -0
- package/src/core/initialize.d.ts +3 -2
- package/src/core/initialize.types.d.ts +118 -0
- package/src/factories/cart/cart.factory.d.ts +14 -0
- package/src/factories/category/category.factory.d.ts +11 -0
- package/src/factories/checkout/checkout-initializer-overrides.example.d.ts +1 -0
- package/src/factories/checkout/checkout.factory.d.ts +18 -0
- package/src/factories/identity/identity.factory.d.ts +8 -0
- package/src/factories/inventory/inventory.factory.d.ts +9 -0
- package/src/factories/order/order.factory.d.ts +9 -0
- package/src/factories/order-search/order-search.factory.d.ts +11 -0
- package/src/factories/price/price.factory.d.ts +11 -0
- package/src/factories/product/product-factory-baseline.example.d.ts +1 -0
- package/src/factories/product/product-factory-schema-and-parse-extension.example.d.ts +1 -0
- package/src/factories/product/product-factory-schema-extension.example.d.ts +1 -0
- package/src/factories/product/product-initializer-factory-extension.example.d.ts +1 -0
- package/src/factories/product/product-provider-custom-method-only.example.d.ts +1 -0
- package/src/factories/product/product-provider-schema-signature-extension.example.d.ts +1 -0
- package/src/factories/product/product.factory.d.ts +18 -0
- package/src/factories/product/utils.example.d.ts +4 -0
- package/src/factories/product-associations/product-associations.factory.d.ts +15 -0
- package/src/factories/product-list/product-list.factory.d.ts +17 -0
- package/src/factories/product-reviews/product-reviews.factory.d.ts +14 -0
- package/src/factories/product-search/product-search.factory.d.ts +13 -0
- package/src/factories/profile/profile.factory.d.ts +11 -0
- package/src/factories/store/store.factory.d.ts +9 -0
- package/src/index.d.ts +15 -0
- package/src/providers/cart.provider.d.ts +15 -15
- package/src/providers/category.provider.d.ts +13 -23
- package/src/providers/checkout.provider.d.ts +16 -32
- package/src/providers/identity.provider.d.ts +9 -7
- package/src/providers/inventory.provider.d.ts +6 -6
- package/src/providers/order-search.provider.d.ts +7 -65
- package/src/providers/order.provider.d.ts +6 -5
- package/src/providers/price.provider.d.ts +12 -9
- package/src/providers/product-associations.provider.d.ts +11 -18
- package/src/providers/product-list.provider.d.ts +12 -10
- package/src/providers/product-reviews.provider.d.ts +9 -7
- package/src/providers/product-search.provider.d.ts +8 -51
- package/src/providers/product.provider.d.ts +9 -18
- package/src/providers/profile.provider.d.ts +13 -13
- package/src/providers/store.provider.d.ts +6 -6
- package/src/schema/capabilities.schema.d.ts +102 -17
- package/src/test/client-builder-merge-extensions.example.d.ts +1 -0
- package/test/client-builder-merge-extensions.example.js +94 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { RequestContext, Cache,
|
|
1
|
+
import type { RequestContext, Cache, OrderFactory, OrderFactoryOutput, OrderFactoryWithOutput, OrderQueryById, Result, NotFoundError } from '@reactionary/core';
|
|
2
2
|
import { OrderProvider } from '@reactionary/core';
|
|
3
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
4
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
5
|
-
|
|
5
|
+
import type { CommercetoolsOrderFactory } from '../factories/order/order.factory.js';
|
|
6
|
+
export declare class CommercetoolsOrderProvider<TFactory extends OrderFactory = CommercetoolsOrderFactory> extends OrderProvider<OrderFactoryOutput<TFactory>> {
|
|
6
7
|
protected config: CommercetoolsConfiguration;
|
|
7
8
|
protected commercetools: CommercetoolsAPI;
|
|
8
|
-
|
|
9
|
+
protected factory: OrderFactoryWithOutput<TFactory>;
|
|
10
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: OrderFactoryWithOutput<TFactory>);
|
|
9
11
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyMeOrdersRequestBuilder>;
|
|
10
|
-
getById(payload: OrderQueryById): Promise<Result<
|
|
11
|
-
protected parseSingle(_body: unknown): Order;
|
|
12
|
+
getById(payload: OrderQueryById): Promise<Result<OrderFactoryOutput<TFactory>, NotFoundError>>;
|
|
12
13
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { PriceProvider } from '@reactionary/core';
|
|
2
|
-
import type { RequestContext,
|
|
1
|
+
import { PriceProvider, type PriceFactory, type PriceFactoryOutput, type PriceFactoryWithOutput } from '@reactionary/core';
|
|
2
|
+
import type { RequestContext, Cache, CustomerPriceQuery, ListPriceQuery, Result } from '@reactionary/core';
|
|
3
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
4
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
5
|
-
|
|
5
|
+
import type { CommercetoolsPriceFactory } from '../factories/price/price.factory.js';
|
|
6
|
+
export declare class CommercetoolsPriceProvider<TFactory extends PriceFactory = CommercetoolsPriceFactory> extends PriceProvider<PriceFactoryOutput<TFactory>> {
|
|
6
7
|
protected config: CommercetoolsConfiguration;
|
|
7
8
|
protected commercetools: CommercetoolsAPI;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
protected factory: PriceFactoryWithOutput<TFactory>;
|
|
10
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: PriceFactoryWithOutput<TFactory>);
|
|
11
|
+
getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<PriceFactoryOutput<TFactory>>>;
|
|
12
|
+
getListPrice(payload: ListPriceQuery): Promise<Result<PriceFactoryOutput<TFactory>>>;
|
|
11
13
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
12
|
-
protected
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
protected getChannels(): Promise<{
|
|
15
|
+
offer: string;
|
|
16
|
+
list: string;
|
|
17
|
+
}>;
|
|
15
18
|
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
import { ProductAssociationsProvider } from '@reactionary/core';
|
|
2
|
-
import type { ProductIdentifier,
|
|
3
|
-
import type { ProductProjection
|
|
1
|
+
import { type ProductAssociationsFactory, type ProductAssociationsFactoryOutput, type ProductAssociationsFactoryWithOutput, ProductAssociationsProvider } from '@reactionary/core';
|
|
2
|
+
import type { ProductIdentifier, ProductAssociationsGetAccessoriesQuery, ProductAssociationsGetSparepartsQuery, ProductAssociationsGetReplacementsQuery, Result, RequestContext, Cache } from '@reactionary/core';
|
|
3
|
+
import type { ProductProjection } from '@commercetools/platform-sdk';
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
6
|
-
|
|
6
|
+
import type { CommercetoolsProductAssociationsFactory } from '../factories/product-associations/product-associations.factory.js';
|
|
7
|
+
export declare class CommercetoolsProductAssociationsProvider<TFactory extends ProductAssociationsFactory = CommercetoolsProductAssociationsFactory> extends ProductAssociationsProvider<ProductAssociationsFactoryOutput<TFactory>> {
|
|
7
8
|
protected config: CommercetoolsConfiguration;
|
|
8
9
|
protected commercetools: CommercetoolsAPI;
|
|
9
|
-
|
|
10
|
+
protected factory: ProductAssociationsFactoryWithOutput<TFactory>;
|
|
11
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: ProductAssociationsFactoryWithOutput<TFactory>);
|
|
10
12
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
11
|
-
protected fetchAssociatedProductsFor(productKey: ProductIdentifier, maxNumberOfAssociations: number, attributeName: string): Promise<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
name: string;
|
|
17
|
-
slug: string;
|
|
18
|
-
variants: ProductSearchResultItemVariant[];
|
|
19
|
-
};
|
|
20
|
-
getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<ProductAssociation[]>>;
|
|
21
|
-
getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<ProductAssociation[]>>;
|
|
22
|
-
getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<ProductAssociation[]>>;
|
|
23
|
-
protected parseVariant(variant: CTProductVariant, product: ProductProjection): ProductSearchResultItemVariant;
|
|
13
|
+
protected fetchAssociatedProductsFor(productKey: ProductIdentifier, maxNumberOfAssociations: number, attributeName: string): Promise<ProductProjection[]>;
|
|
14
|
+
getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<ProductAssociationsFactoryOutput<TFactory>[]>>;
|
|
15
|
+
getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<ProductAssociationsFactoryOutput<TFactory>[]>>;
|
|
16
|
+
getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<ProductAssociationsFactoryOutput<TFactory>[]>>;
|
|
24
17
|
}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import type { ShoppingList, ShoppingListLineItem } from '@commercetools/platform-sdk';
|
|
2
|
-
import type { Cache, ProductList, ProductListIdentifier, ProductListItem, ProductListItemMutationCreate, ProductListItemMutationDelete, ProductListItemMutationUpdate,
|
|
2
|
+
import type { Cache, ProductListFactory, ProductListFactoryItemOutput, ProductListFactoryItemPaginatedOutput, ProductListFactoryListOutput, ProductListFactoryListPaginatedOutput, ProductListFactoryWithOutput, ProductList, ProductListIdentifier, ProductListItem, ProductListItemMutationCreate, ProductListItemMutationDelete, ProductListItemMutationUpdate, ProductListItemsQuery, ProductListMutationCreate, ProductListMutationDelete, ProductListMutationUpdate, ProductListQuery, ProductListQueryById, RequestContext, Result } from '@reactionary/core';
|
|
3
3
|
import { ProductListProvider } from '@reactionary/core';
|
|
4
4
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
5
5
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
6
|
-
|
|
6
|
+
import type { CommercetoolsProductListFactory } from '../factories/product-list/product-list.factory.js';
|
|
7
|
+
export declare class CommercetoolsProductListProvider<TFactory extends ProductListFactory = CommercetoolsProductListFactory> extends ProductListProvider<ProductListFactoryListOutput<TFactory>, ProductListFactoryItemOutput<TFactory>, ProductListFactoryListPaginatedOutput<TFactory>, ProductListFactoryItemPaginatedOutput<TFactory>> {
|
|
7
8
|
protected config: CommercetoolsConfiguration;
|
|
8
9
|
protected commercetools: CommercetoolsAPI;
|
|
9
|
-
|
|
10
|
+
protected factory: ProductListFactoryWithOutput<TFactory>;
|
|
11
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: ProductListFactoryWithOutput<TFactory>);
|
|
10
12
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyMeRequestBuilder>;
|
|
11
|
-
getById(payload: ProductListQueryById): Promise<Result<
|
|
12
|
-
queryLists(payload: ProductListQuery): Promise<Result<
|
|
13
|
-
addList(mutation: ProductListMutationCreate): Promise<Result<
|
|
14
|
-
updateList(mutation: ProductListMutationUpdate): Promise<Result<
|
|
13
|
+
getById(payload: ProductListQueryById): Promise<Result<ProductListFactoryListOutput<TFactory>>>;
|
|
14
|
+
queryLists(payload: ProductListQuery): Promise<Result<ProductListFactoryListPaginatedOutput<TFactory>>>;
|
|
15
|
+
addList(mutation: ProductListMutationCreate): Promise<Result<ProductListFactoryListOutput<TFactory>>>;
|
|
16
|
+
updateList(mutation: ProductListMutationUpdate): Promise<Result<ProductListFactoryListOutput<TFactory>>>;
|
|
15
17
|
deleteList(mutation: ProductListMutationDelete): Promise<Result<void>>;
|
|
16
|
-
queryListItems(query: ProductListItemsQuery): Promise<Result<
|
|
17
|
-
addItem(mutation: ProductListItemMutationCreate): Promise<Result<
|
|
18
|
+
queryListItems(query: ProductListItemsQuery): Promise<Result<ProductListFactoryItemPaginatedOutput<TFactory>>>;
|
|
19
|
+
addItem(mutation: ProductListItemMutationCreate): Promise<Result<ProductListFactoryItemOutput<TFactory>>>;
|
|
18
20
|
deleteItem(mutation: ProductListItemMutationDelete): Promise<Result<void>>;
|
|
19
|
-
updateItem(mutation: ProductListItemMutationUpdate): Promise<Result<
|
|
21
|
+
updateItem(mutation: ProductListItemMutationUpdate): Promise<Result<ProductListFactoryItemOutput<TFactory>>>;
|
|
20
22
|
/**
|
|
21
23
|
* It is not clear to me, why i'd want my CUSTOMER defined resources to be localized, since that means, if he changes visual language,
|
|
22
24
|
* the names of his lists will disappear, since they are not translated. But maybe there are usecases for this, so we should support it, but default to english.
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { ProductReviewsProvider } from '@reactionary/core';
|
|
2
|
-
import type { ProductReview,
|
|
1
|
+
import { type ProductReviewsFactory, type ProductReviewsFactoryRatingOutput, type ProductReviewsFactoryReviewOutput, type ProductReviewsFactoryReviewPaginatedOutput, type ProductReviewsFactoryWithOutput, ProductReviewsProvider } from '@reactionary/core';
|
|
2
|
+
import type { ProductReview, ProductReviewsListQuery, ProductReviewsGetRatingSummaryQuery, ProductReviewMutationSubmit, Result, RequestContext, Cache } from '@reactionary/core';
|
|
3
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
4
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
5
5
|
import type { Review as CTReview } from '@commercetools/platform-sdk';
|
|
6
|
-
|
|
6
|
+
import type { CommercetoolsProductReviewsFactory } from '../factories/product-reviews/product-reviews.factory.js';
|
|
7
|
+
export declare class CommercetoolsProductReviewsProvider<TFactory extends ProductReviewsFactory = CommercetoolsProductReviewsFactory> extends ProductReviewsProvider<ProductReviewsFactoryRatingOutput<TFactory>, ProductReviewsFactoryReviewPaginatedOutput<TFactory>, ProductReviewsFactoryReviewOutput<TFactory>> {
|
|
7
8
|
protected config: CommercetoolsConfiguration;
|
|
8
9
|
protected commercetools: CommercetoolsAPI;
|
|
9
|
-
|
|
10
|
+
protected factory: ProductReviewsFactoryWithOutput<TFactory>;
|
|
11
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: ProductReviewsFactoryWithOutput<TFactory>);
|
|
10
12
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
11
13
|
protected getAdminClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
12
|
-
getRatingSummary(query: ProductReviewsGetRatingSummaryQuery): Promise<Result<
|
|
13
|
-
findReviews(query: ProductReviewsListQuery): Promise<Result<
|
|
14
|
-
submitReview(mutation: ProductReviewMutationSubmit): Promise<Result<
|
|
14
|
+
getRatingSummary(query: ProductReviewsGetRatingSummaryQuery): Promise<Result<ProductReviewsFactoryRatingOutput<TFactory>>>;
|
|
15
|
+
findReviews(query: ProductReviewsListQuery): Promise<Result<ProductReviewsFactoryReviewPaginatedOutput<TFactory>>>;
|
|
16
|
+
submitReview(mutation: ProductReviewMutationSubmit): Promise<Result<ProductReviewsFactoryReviewOutput<TFactory>>>;
|
|
15
17
|
protected parseSingle(review: CTReview, productKey: string): ProductReview;
|
|
16
18
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Cache,
|
|
1
|
+
import type { ProductSearchFacetExpression } from '@commercetools/platform-sdk';
|
|
2
|
+
import type { Cache, FacetValueIdentifier, ProductSearchFactory, ProductSearchFactoryOutput, ProductSearchFactoryWithOutput, ProductSearchQueryByTerm, ProductSearchQueryCreateNavigationFilter, RequestContext, Result } from '@reactionary/core';
|
|
3
3
|
import { ProductSearchProvider } from '@reactionary/core';
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
6
6
|
import { type CommercetoolsCategoryLookup, type CommercetoolsResolveCategoryQueryById, type CommercetoolsResolveCategoryQueryByKey } from '../schema/commercetools.schema.js';
|
|
7
|
-
|
|
7
|
+
import type { CommercetoolsProductSearchFactory } from '../factories/product-search/product-search.factory.js';
|
|
8
|
+
export declare class CommercetoolsSearchProvider<TFactory extends ProductSearchFactory = CommercetoolsProductSearchFactory> extends ProductSearchProvider<ProductSearchFactoryOutput<TFactory>> {
|
|
8
9
|
protected config: CommercetoolsConfiguration;
|
|
9
10
|
protected commercetools: CommercetoolsAPI;
|
|
10
|
-
|
|
11
|
+
protected factory: ProductSearchFactoryWithOutput<TFactory>;
|
|
12
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: ProductSearchFactoryWithOutput<TFactory>);
|
|
11
13
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyProductsRequestBuilder>;
|
|
12
14
|
protected getFacetQuery(payload: ProductSearchQueryByTerm, selectedFacetValue: FacetValueIdentifier): Promise<{
|
|
13
15
|
exact: {
|
|
@@ -75,51 +77,6 @@ export declare class CommercetoolsSearchProvider extends ProductSearchProvider {
|
|
|
75
77
|
} | undefined>;
|
|
76
78
|
protected getFacetsToReturn(payload: ProductSearchQueryByTerm): Promise<ProductSearchFacetExpression[]>;
|
|
77
79
|
createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>>;
|
|
78
|
-
queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<
|
|
79
|
-
protected patchCategoryFacetValues(result:
|
|
80
|
-
protected parseSingle(body: ProductProjection): {
|
|
81
|
-
identifier: {
|
|
82
|
-
key: string;
|
|
83
|
-
};
|
|
84
|
-
name: string;
|
|
85
|
-
slug: string;
|
|
86
|
-
variants: ProductSearchResultItemVariant[];
|
|
87
|
-
};
|
|
88
|
-
protected parsePaginatedResult(body: ProductPagedSearchResponse, query: ProductSearchQueryByTerm): {
|
|
89
|
-
identifier: {
|
|
90
|
-
term: string;
|
|
91
|
-
facets: {
|
|
92
|
-
facet: {
|
|
93
|
-
key: string;
|
|
94
|
-
};
|
|
95
|
-
key: string;
|
|
96
|
-
}[];
|
|
97
|
-
filters: string[];
|
|
98
|
-
paginationOptions: {
|
|
99
|
-
pageNumber: number;
|
|
100
|
-
pageSize: number;
|
|
101
|
-
};
|
|
102
|
-
categoryFilter?: {
|
|
103
|
-
facet: {
|
|
104
|
-
key: string;
|
|
105
|
-
};
|
|
106
|
-
key: string;
|
|
107
|
-
} | undefined;
|
|
108
|
-
};
|
|
109
|
-
pageNumber: number;
|
|
110
|
-
pageSize: number;
|
|
111
|
-
totalCount: number;
|
|
112
|
-
totalPages: number;
|
|
113
|
-
items: ProductSearchResultItem[];
|
|
114
|
-
facets: ProductSearchResultFacet[];
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* See version 0.0.81 for ProductProjection based facet parsing
|
|
118
|
-
* @param facetIdentifier
|
|
119
|
-
* @param facetValue
|
|
120
|
-
* @returns
|
|
121
|
-
*/
|
|
122
|
-
protected parseFacet(facetIdentifier: FacetIdentifier, facet: CTProductSearchFacetResult): ProductSearchResultFacet;
|
|
123
|
-
protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number): ProductSearchResultFacetValue;
|
|
124
|
-
protected parseVariant(variant: CTProductVariant, product: ProductProjection): ProductSearchResultItemVariant;
|
|
80
|
+
queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchFactoryOutput<TFactory>>>;
|
|
81
|
+
protected patchCategoryFacetValues(result: ProductSearchFactoryOutput<TFactory>): Promise<void>;
|
|
125
82
|
}
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
import { ProductProvider } from '@reactionary/core';
|
|
1
|
+
import { ProductProvider, type ProductFactory, type ProductFactoryOutput, type ProductFactoryWithOutput } from '@reactionary/core';
|
|
2
2
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type { Product, ProductVariant, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext, ProductAttribute, ProductAttributeValue, Result } from '@reactionary/core';
|
|
3
|
+
import type { ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext, Result } from '@reactionary/core';
|
|
5
4
|
import type { Cache } from '@reactionary/core';
|
|
6
5
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
7
6
|
import type { NotFoundError } from '@reactionary/core';
|
|
8
|
-
|
|
7
|
+
import type { CommercetoolsProductFactory } from '../factories/product/product.factory.js';
|
|
8
|
+
export declare class CommercetoolsProductProvider<TFactory extends ProductFactory = CommercetoolsProductFactory> extends ProductProvider<ProductFactoryOutput<TFactory>> {
|
|
9
9
|
protected config: CommercetoolsConfiguration;
|
|
10
10
|
protected commercetools: CommercetoolsAPI;
|
|
11
|
-
|
|
11
|
+
protected factory: ProductFactoryWithOutput<TFactory>;
|
|
12
|
+
constructor(cache: Cache, context: RequestContext, config: CommercetoolsConfiguration, commercetools: CommercetoolsAPI, factory: ProductFactoryWithOutput<TFactory>);
|
|
12
13
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyProductProjectionsRequestBuilder>;
|
|
13
|
-
getById(payload: ProductQueryById): Promise<Result<
|
|
14
|
-
getBySlug(payload: ProductQueryBySlug): Promise<Result<
|
|
15
|
-
getBySKU(payload: ProductQueryBySKU): Promise<Result<
|
|
16
|
-
protected parseSingle(data: ProductProjection): Product;
|
|
17
|
-
/**
|
|
18
|
-
* Return true, if the attribute is a defining attribute (ie an option)
|
|
19
|
-
* @param attr a variant attribute
|
|
20
|
-
* @returns true if the attribute is an option
|
|
21
|
-
*/
|
|
22
|
-
protected isVariantAttributeAnOption(attr: CTAttribute): boolean;
|
|
23
|
-
protected parseVariant(variant: CTProductVariant, product: ProductProjection): ProductVariant;
|
|
24
|
-
protected parseAttribute(attr: CTAttribute): ProductAttribute;
|
|
25
|
-
protected parseAttributeValue(attr: CTAttribute): ProductAttributeValue;
|
|
14
|
+
getById(payload: ProductQueryById): Promise<Result<ProductFactoryOutput<TFactory>>>;
|
|
15
|
+
getBySlug(payload: ProductQueryBySlug): Promise<Result<ProductFactoryOutput<TFactory>, NotFoundError>>;
|
|
16
|
+
getBySKU(payload: ProductQueryBySKU): Promise<Result<ProductFactoryOutput<TFactory>>>;
|
|
26
17
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProfileFactory, ProfileFactoryOutput, ProfileFactoryWithOutput, ProfileMutationAddShippingAddress, ProfileMutationMakeShippingAddressDefault, ProfileMutationRemoveShippingAddress, ProfileMutationSetBillingAddress, ProfileMutationUpdate, ProfileQuerySelf, RequestContext, Result, NotFoundError, ProfileMutationUpdateShippingAddress, Address } from '@reactionary/core';
|
|
2
2
|
import { ProfileProvider } from '@reactionary/core';
|
|
3
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
4
|
import type { Cache } from '@reactionary/core';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Address as CTAddress } from '@commercetools/platform-sdk';
|
|
6
6
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
7
|
-
|
|
7
|
+
import type { CommercetoolsProfileFactory } from '../factories/profile/profile.factory.js';
|
|
8
|
+
export declare class CommercetoolsProfileProvider<TFactory extends ProfileFactory = CommercetoolsProfileFactory> extends ProfileProvider<ProfileFactoryOutput<TFactory>> {
|
|
8
9
|
protected config: CommercetoolsConfiguration;
|
|
9
10
|
protected commercetools: CommercetoolsAPI;
|
|
10
|
-
|
|
11
|
+
protected factory: ProfileFactoryWithOutput<TFactory>;
|
|
12
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: ProfileFactoryWithOutput<TFactory>);
|
|
11
13
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
12
|
-
getById(payload: ProfileQuerySelf): Promise<Result<
|
|
13
|
-
addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<
|
|
14
|
-
updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<
|
|
15
|
-
removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<
|
|
16
|
-
makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<
|
|
17
|
-
setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<
|
|
18
|
-
update(payload: ProfileMutationUpdate): Promise<Result<
|
|
19
|
-
protected parseAddress(address: CTAddress): Address;
|
|
20
|
-
protected parseSingle(body: Customer): Profile;
|
|
14
|
+
getById(payload: ProfileQuerySelf): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
15
|
+
addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
16
|
+
updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
17
|
+
removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
18
|
+
makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
19
|
+
setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
20
|
+
update(payload: ProfileMutationUpdate): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
21
21
|
protected createCTAddressDraft(address: Address): CTAddress;
|
|
22
22
|
/**
|
|
23
23
|
* Checks if an address only contains phone information and lacks essential address fields.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { RequestContext, Cache,
|
|
1
|
+
import type { RequestContext, Cache, StoreFactory, StoreFactoryOutput, StoreFactoryWithOutput, StoreQueryByProximity, Result } from '@reactionary/core';
|
|
2
2
|
import { StoreProvider } from '@reactionary/core';
|
|
3
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
|
-
import type { Channel } from '@commercetools/platform-sdk';
|
|
5
4
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
6
|
-
|
|
5
|
+
import type { CommercetoolsStoreFactory } from '../factories/store/store.factory.js';
|
|
6
|
+
export declare class CommercetoolsStoreProvider<TFactory extends StoreFactory = CommercetoolsStoreFactory> extends StoreProvider<StoreFactoryOutput<TFactory>> {
|
|
7
7
|
protected config: CommercetoolsConfiguration;
|
|
8
8
|
protected commercetools: CommercetoolsAPI;
|
|
9
|
-
|
|
9
|
+
protected factory: StoreFactoryWithOutput<TFactory>;
|
|
10
|
+
constructor(config: CommercetoolsConfiguration, cache: Cache, context: RequestContext, commercetools: CommercetoolsAPI, factory: StoreFactoryWithOutput<TFactory>);
|
|
10
11
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
11
|
-
queryByProximity(payload: StoreQueryByProximity): Promise<Result<Array<
|
|
12
|
-
protected parseSingle(body: Channel): Store;
|
|
12
|
+
queryByProximity(payload: StoreQueryByProximity): Promise<Result<Array<StoreFactoryOutput<TFactory>>>>;
|
|
13
13
|
}
|
|
@@ -1,19 +1,104 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { Cache, CartFactory, CartFactoryWithOutput, CartProvider, CategoryFactory, CategoryFactoryWithOutput, CategoryProvider, CheckoutFactory, CheckoutFactoryWithOutput, CheckoutProvider, IdentityFactory, IdentityFactoryWithOutput, IdentityProvider, InventoryFactory, InventoryFactoryWithOutput, InventoryProvider, OrderFactory, OrderFactoryWithOutput, OrderProvider, OrderSearchFactory, OrderSearchFactoryWithOutput, OrderSearchProvider, PriceFactory, PriceFactoryWithOutput, PriceProvider, ProductAssociationsFactory, ProductAssociationsFactoryWithOutput, ProductAssociationsProvider, ProductFactory, ProductFactoryWithOutput, ProductListFactory, ProductListFactoryWithOutput, ProductListProvider, ProductProvider, ProductReviewsFactory, ProductReviewsFactoryWithOutput, ProductReviewsProvider, ProductSearchFactory, ProductSearchFactoryWithOutput, ProductSearchProvider, ProfileFactory, ProfileFactoryWithOutput, ProfileProvider, RequestContext, StoreFactory, StoreFactoryWithOutput, StoreProvider } from '@reactionary/core';
|
|
2
|
+
import type { CommercetoolsAPI } from '../core/client.js';
|
|
3
|
+
import type { CommercetoolsConfiguration } from './configuration.schema.js';
|
|
4
|
+
import * as z from 'zod';
|
|
2
5
|
export declare const CommercetoolsCapabilitiesSchema: z.ZodObject<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
productSearch: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
7
|
+
enabled: z.ZodBoolean;
|
|
8
|
+
}, z.core.$loose>>>;
|
|
9
|
+
productAssociations: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
10
|
+
enabled: z.ZodBoolean;
|
|
11
|
+
}, z.core.$loose>>>;
|
|
12
|
+
productReviews: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
13
|
+
enabled: z.ZodBoolean;
|
|
14
|
+
}, z.core.$loose>>>;
|
|
15
|
+
productList: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
16
|
+
enabled: z.ZodBoolean;
|
|
17
|
+
}, z.core.$loose>>>;
|
|
18
|
+
identity: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
19
|
+
enabled: z.ZodBoolean;
|
|
20
|
+
}, z.core.$loose>>>;
|
|
21
|
+
cart: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
22
|
+
enabled: z.ZodBoolean;
|
|
23
|
+
}, z.core.$loose>>>;
|
|
24
|
+
order: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
25
|
+
enabled: z.ZodBoolean;
|
|
26
|
+
}, z.core.$loose>>>;
|
|
27
|
+
orderSearch: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
28
|
+
enabled: z.ZodBoolean;
|
|
29
|
+
}, z.core.$loose>>>;
|
|
30
|
+
inventory: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
31
|
+
enabled: z.ZodBoolean;
|
|
32
|
+
}, z.core.$loose>>>;
|
|
33
|
+
price: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
34
|
+
enabled: z.ZodBoolean;
|
|
35
|
+
}, z.core.$loose>>>;
|
|
36
|
+
category: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
37
|
+
enabled: z.ZodBoolean;
|
|
38
|
+
}, z.core.$loose>>>;
|
|
39
|
+
store: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
40
|
+
enabled: z.ZodBoolean;
|
|
41
|
+
}, z.core.$loose>>>;
|
|
42
|
+
profile: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
43
|
+
enabled: z.ZodBoolean;
|
|
44
|
+
}, z.core.$loose>>>;
|
|
45
|
+
product: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
46
|
+
enabled: z.ZodBoolean;
|
|
47
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
48
|
+
provider: z.ZodOptional<z.ZodUnknown>;
|
|
49
|
+
}, z.core.$loose>>>;
|
|
50
|
+
checkout: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
51
|
+
enabled: z.ZodBoolean;
|
|
52
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
53
|
+
provider: z.ZodOptional<z.ZodUnknown>;
|
|
54
|
+
}, z.core.$loose>>>;
|
|
18
55
|
}, z.core.$loose>;
|
|
19
|
-
export
|
|
56
|
+
export interface CommercetoolsCapabilityProviderFactoryArgs<TFactory> {
|
|
57
|
+
cache: Cache;
|
|
58
|
+
context: RequestContext;
|
|
59
|
+
config: CommercetoolsConfiguration;
|
|
60
|
+
commercetoolsApi: CommercetoolsAPI;
|
|
61
|
+
factory: TFactory;
|
|
62
|
+
}
|
|
63
|
+
export interface CommercetoolsCapabilityConfig<TFactory, TProvider> {
|
|
64
|
+
factory?: TFactory;
|
|
65
|
+
provider?: (args: CommercetoolsCapabilityProviderFactoryArgs<TFactory>) => TProvider;
|
|
66
|
+
}
|
|
67
|
+
type EnabledCapabilityConfig<TFactory, TProvider> = {
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
} & CommercetoolsCapabilityConfig<TFactory, TProvider>;
|
|
70
|
+
export type CommercetoolsProductCapabilityConfig<TFactory extends ProductFactory = ProductFactory, TProvider extends ProductProvider = ProductProvider> = CommercetoolsCapabilityConfig<ProductFactoryWithOutput<TFactory>, TProvider>;
|
|
71
|
+
export type CommercetoolsCheckoutCapabilityConfig<TFactory extends CheckoutFactory = CheckoutFactory, TProvider extends CheckoutProvider = CheckoutProvider> = CommercetoolsCapabilityConfig<CheckoutFactoryWithOutput<TFactory>, TProvider>;
|
|
72
|
+
export type CommercetoolsProductSearchCapabilityConfig = CommercetoolsCapabilityConfig<ProductSearchFactoryWithOutput<ProductSearchFactory>, ProductSearchProvider>;
|
|
73
|
+
export type CommercetoolsProductAssociationsCapabilityConfig = CommercetoolsCapabilityConfig<ProductAssociationsFactoryWithOutput<ProductAssociationsFactory>, ProductAssociationsProvider>;
|
|
74
|
+
export type CommercetoolsProductReviewsCapabilityConfig = CommercetoolsCapabilityConfig<ProductReviewsFactoryWithOutput<ProductReviewsFactory>, ProductReviewsProvider>;
|
|
75
|
+
export type CommercetoolsProductListCapabilityConfig = CommercetoolsCapabilityConfig<ProductListFactoryWithOutput<ProductListFactory>, ProductListProvider>;
|
|
76
|
+
export type CommercetoolsIdentityCapabilityConfig = CommercetoolsCapabilityConfig<IdentityFactoryWithOutput<IdentityFactory>, IdentityProvider>;
|
|
77
|
+
export type CommercetoolsCartCapabilityConfig = CommercetoolsCapabilityConfig<CartFactoryWithOutput<CartFactory>, CartProvider>;
|
|
78
|
+
export type CommercetoolsInventoryCapabilityConfig = CommercetoolsCapabilityConfig<InventoryFactoryWithOutput<InventoryFactory>, InventoryProvider>;
|
|
79
|
+
export type CommercetoolsPriceCapabilityConfig = CommercetoolsCapabilityConfig<PriceFactoryWithOutput<PriceFactory>, PriceProvider>;
|
|
80
|
+
export type CommercetoolsCategoryCapabilityConfig = CommercetoolsCapabilityConfig<CategoryFactoryWithOutput<CategoryFactory>, CategoryProvider>;
|
|
81
|
+
export type CommercetoolsStoreCapabilityConfig = CommercetoolsCapabilityConfig<StoreFactoryWithOutput<StoreFactory>, StoreProvider>;
|
|
82
|
+
export type CommercetoolsProfileCapabilityConfig = CommercetoolsCapabilityConfig<ProfileFactoryWithOutput<ProfileFactory>, ProfileProvider>;
|
|
83
|
+
export type CommercetoolsOrderCapabilityConfig = CommercetoolsCapabilityConfig<OrderFactoryWithOutput<OrderFactory>, OrderProvider>;
|
|
84
|
+
export type CommercetoolsOrderSearchCapabilityConfig = CommercetoolsCapabilityConfig<OrderSearchFactoryWithOutput<OrderSearchFactory>, OrderSearchProvider>;
|
|
85
|
+
export type CommercetoolsCapabilityConfigMap<TProductFactory extends ProductFactory = ProductFactory, TProductProvider extends ProductProvider = ProductProvider, TCheckoutFactory extends CheckoutFactory = CheckoutFactory, TCheckoutProvider extends CheckoutProvider = CheckoutProvider> = {
|
|
86
|
+
product: EnabledCapabilityConfig<ProductFactoryWithOutput<TProductFactory>, TProductProvider>;
|
|
87
|
+
checkout: EnabledCapabilityConfig<CheckoutFactoryWithOutput<TCheckoutFactory>, TCheckoutProvider>;
|
|
88
|
+
productSearch: EnabledCapabilityConfig<ProductSearchFactoryWithOutput<ProductSearchFactory>, ProductSearchProvider>;
|
|
89
|
+
productAssociations: EnabledCapabilityConfig<ProductAssociationsFactoryWithOutput<ProductAssociationsFactory>, ProductAssociationsProvider>;
|
|
90
|
+
productReviews: EnabledCapabilityConfig<ProductReviewsFactoryWithOutput<ProductReviewsFactory>, ProductReviewsProvider>;
|
|
91
|
+
productList: EnabledCapabilityConfig<ProductListFactoryWithOutput<ProductListFactory>, ProductListProvider>;
|
|
92
|
+
identity: EnabledCapabilityConfig<IdentityFactoryWithOutput<IdentityFactory>, IdentityProvider>;
|
|
93
|
+
cart: EnabledCapabilityConfig<CartFactoryWithOutput<CartFactory>, CartProvider>;
|
|
94
|
+
inventory: EnabledCapabilityConfig<InventoryFactoryWithOutput<InventoryFactory>, InventoryProvider>;
|
|
95
|
+
price: EnabledCapabilityConfig<PriceFactoryWithOutput<PriceFactory>, PriceProvider>;
|
|
96
|
+
category: EnabledCapabilityConfig<CategoryFactoryWithOutput<CategoryFactory>, CategoryProvider>;
|
|
97
|
+
store: EnabledCapabilityConfig<StoreFactoryWithOutput<StoreFactory>, StoreProvider>;
|
|
98
|
+
profile: EnabledCapabilityConfig<ProfileFactoryWithOutput<ProfileFactory>, ProfileProvider>;
|
|
99
|
+
order: EnabledCapabilityConfig<OrderFactoryWithOutput<OrderFactory>, OrderProvider>;
|
|
100
|
+
orderSearch: EnabledCapabilityConfig<OrderSearchFactoryWithOutput<OrderSearchFactory>, OrderSearchProvider>;
|
|
101
|
+
};
|
|
102
|
+
type CommercetoolsCapabilitiesBase = z.infer<typeof CommercetoolsCapabilitiesSchema>;
|
|
103
|
+
export type CommercetoolsCapabilities<TProductFactory extends ProductFactory = ProductFactory, TProductProvider extends ProductProvider = ProductProvider, TCheckoutFactory extends CheckoutFactory = CheckoutFactory, TCheckoutProvider extends CheckoutProvider = CheckoutProvider> = Omit<CommercetoolsCapabilitiesBase, keyof CommercetoolsCapabilityConfigMap<TProductFactory, TProductProvider, TCheckoutFactory, TCheckoutProvider>> & Partial<CommercetoolsCapabilityConfigMap<TProductFactory, TProductProvider, TCheckoutFactory, TCheckoutProvider>>;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClientBuilder,
|
|
3
|
+
createInitialRequestContext,
|
|
4
|
+
NoOpCache,
|
|
5
|
+
ProductSchema,
|
|
6
|
+
StoreSchema
|
|
7
|
+
} from "@reactionary/core";
|
|
8
|
+
import * as z from "zod";
|
|
9
|
+
import { withCommercetoolsCapabilities } from "../core/initialize.js";
|
|
10
|
+
import { CommercetoolsProductFactory } from "../factories/product/product.factory.js";
|
|
11
|
+
import { CommercetoolsStoreFactory } from "../factories/store/store.factory.js";
|
|
12
|
+
import { assertNotAny, assertType } from "../factories/product/utils.example.js";
|
|
13
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
14
|
+
extendedProductValue: z.string()
|
|
15
|
+
});
|
|
16
|
+
class ExtendedCommercetoolsProductFactory extends CommercetoolsProductFactory {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(ExtendedProductSchema);
|
|
19
|
+
}
|
|
20
|
+
parseProduct(context, data) {
|
|
21
|
+
const base = super.parseProduct(context, data);
|
|
22
|
+
return this.productSchema.parse({
|
|
23
|
+
...base,
|
|
24
|
+
extendedProductValue: "from-product-factory"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const ExtendedStoreSchema = StoreSchema.safeExtend({
|
|
29
|
+
extendedStoreValue: z.string()
|
|
30
|
+
});
|
|
31
|
+
class ExtendedCommercetoolsStoreFactory extends CommercetoolsStoreFactory {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(ExtendedStoreSchema);
|
|
34
|
+
}
|
|
35
|
+
parseStore(context, data) {
|
|
36
|
+
const base = super.parseStore(context, data);
|
|
37
|
+
return this.storeSchema.parse({
|
|
38
|
+
...base,
|
|
39
|
+
extendedStoreValue: "from-store-factory"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const config = {
|
|
44
|
+
apiUrl: "https://api.example.invalid",
|
|
45
|
+
authUrl: "https://auth.example.invalid",
|
|
46
|
+
clientId: "test-client",
|
|
47
|
+
clientSecret: "test-secret",
|
|
48
|
+
projectKey: "test-project",
|
|
49
|
+
scopes: [],
|
|
50
|
+
paymentMethods: [],
|
|
51
|
+
facetFieldsForSearch: []
|
|
52
|
+
};
|
|
53
|
+
function createMergedClientExample() {
|
|
54
|
+
const cache = new NoOpCache();
|
|
55
|
+
const context = createInitialRequestContext();
|
|
56
|
+
const withProduct = withCommercetoolsCapabilities(config, {
|
|
57
|
+
product: {
|
|
58
|
+
enabled: true,
|
|
59
|
+
factory: new ExtendedCommercetoolsProductFactory()
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const withStore = withCommercetoolsCapabilities(config, {
|
|
63
|
+
store: {
|
|
64
|
+
enabled: true,
|
|
65
|
+
factory: new ExtendedCommercetoolsStoreFactory()
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const client = new ClientBuilder(context).withCache(cache).withCapability(withProduct).withCapability(withStore).build();
|
|
69
|
+
client.product.getById({
|
|
70
|
+
identifier: { key: "p-1" }
|
|
71
|
+
}).then((result) => {
|
|
72
|
+
assertNotAny(result);
|
|
73
|
+
if (result.success) {
|
|
74
|
+
assertNotAny(result.value);
|
|
75
|
+
assertNotAny(result.value.extendedProductValue);
|
|
76
|
+
assertType(result.value.extendedProductValue);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
client.store.queryByProximity({
|
|
80
|
+
longitude: 10,
|
|
81
|
+
latitude: 56,
|
|
82
|
+
distance: 50,
|
|
83
|
+
limit: 5
|
|
84
|
+
}).then((result) => {
|
|
85
|
+
assertNotAny(result);
|
|
86
|
+
if (result.success) {
|
|
87
|
+
const first = result.value[0];
|
|
88
|
+
assertNotAny(first);
|
|
89
|
+
assertNotAny(first.extendedStoreValue);
|
|
90
|
+
assertType(first.extendedStoreValue);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return client;
|
|
94
|
+
}
|