@reactionary/provider-commercetools 0.1.9 → 0.1.11
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/initialize.js +81 -22
- package/package.json +2 -2
- package/providers/product-search.provider.js +12 -8
- package/src/core/initialize.d.ts +4 -28
package/core/initialize.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
InventorySchema,
|
|
5
|
-
PriceSchema,
|
|
6
|
-
ProductSchema,
|
|
7
|
-
CategorySchema,
|
|
8
|
-
CheckoutSchema,
|
|
9
|
-
ProductSearchResultItemSchema,
|
|
10
|
-
ProfileSchema
|
|
11
|
-
} from "@reactionary/core";
|
|
12
|
-
import { CommercetoolsCapabilitiesSchema } from "../schema/capabilities.schema.js";
|
|
2
|
+
CommercetoolsCapabilitiesSchema
|
|
3
|
+
} from "../schema/capabilities.schema.js";
|
|
13
4
|
import { CommercetoolsSearchProvider } from "../providers/product-search.provider.js";
|
|
14
5
|
import { CommercetoolsProductProvider } from "../providers/product.provider.js";
|
|
15
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
CommercetoolsConfigurationSchema
|
|
8
|
+
} from "../schema/configuration.schema.js";
|
|
16
9
|
import { CommercetoolsIdentityProvider } from "../providers/identity.provider.js";
|
|
17
10
|
import { CommercetoolsCartProvider } from "../providers/cart.provider.js";
|
|
18
11
|
import { CommercetoolsInventoryProvider } from "../providers/inventory.provider.js";
|
|
19
12
|
import { CommercetoolsPriceProvider } from "../providers/price.provider.js";
|
|
20
13
|
import { CommercetoolsCategoryProvider } from "../providers/category.provider.js";
|
|
21
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
CommercetoolsCheckoutProvider,
|
|
16
|
+
CommercetoolsOrderProvider,
|
|
17
|
+
CommercetoolsProfileProvider,
|
|
18
|
+
CommercetoolsStoreProvider
|
|
19
|
+
} from "../providers/index.js";
|
|
22
20
|
import { CommercetoolsClient } from "./client.js";
|
|
23
21
|
function withCommercetoolsCapabilities(configuration, capabilities) {
|
|
24
22
|
return (cache, context) => {
|
|
@@ -27,31 +25,92 @@ function withCommercetoolsCapabilities(configuration, capabilities) {
|
|
|
27
25
|
const caps = CommercetoolsCapabilitiesSchema.parse(capabilities);
|
|
28
26
|
const commercetoolsClient = new CommercetoolsClient(config, context);
|
|
29
27
|
if (caps.product) {
|
|
30
|
-
client.product = new CommercetoolsProductProvider(
|
|
28
|
+
client.product = new CommercetoolsProductProvider(
|
|
29
|
+
config,
|
|
30
|
+
cache,
|
|
31
|
+
context,
|
|
32
|
+
commercetoolsClient
|
|
33
|
+
);
|
|
31
34
|
}
|
|
32
35
|
if (caps.profile) {
|
|
33
|
-
client.profile = new CommercetoolsProfileProvider(
|
|
36
|
+
client.profile = new CommercetoolsProfileProvider(
|
|
37
|
+
config,
|
|
38
|
+
cache,
|
|
39
|
+
context,
|
|
40
|
+
commercetoolsClient
|
|
41
|
+
);
|
|
34
42
|
}
|
|
35
43
|
if (caps.productSearch) {
|
|
36
|
-
client.productSearch = new CommercetoolsSearchProvider(
|
|
44
|
+
client.productSearch = new CommercetoolsSearchProvider(
|
|
45
|
+
config,
|
|
46
|
+
cache,
|
|
47
|
+
context,
|
|
48
|
+
commercetoolsClient
|
|
49
|
+
);
|
|
37
50
|
}
|
|
38
51
|
if (caps.identity) {
|
|
39
|
-
client.identity = new CommercetoolsIdentityProvider(
|
|
52
|
+
client.identity = new CommercetoolsIdentityProvider(
|
|
53
|
+
config,
|
|
54
|
+
cache,
|
|
55
|
+
context,
|
|
56
|
+
commercetoolsClient
|
|
57
|
+
);
|
|
40
58
|
}
|
|
41
59
|
if (caps.cart) {
|
|
42
|
-
client.cart = new CommercetoolsCartProvider(
|
|
60
|
+
client.cart = new CommercetoolsCartProvider(
|
|
61
|
+
config,
|
|
62
|
+
cache,
|
|
63
|
+
context,
|
|
64
|
+
commercetoolsClient
|
|
65
|
+
);
|
|
43
66
|
}
|
|
44
67
|
if (caps.inventory) {
|
|
45
|
-
client.inventory = new CommercetoolsInventoryProvider(
|
|
68
|
+
client.inventory = new CommercetoolsInventoryProvider(
|
|
69
|
+
config,
|
|
70
|
+
cache,
|
|
71
|
+
context,
|
|
72
|
+
commercetoolsClient
|
|
73
|
+
);
|
|
46
74
|
}
|
|
47
75
|
if (caps.price) {
|
|
48
|
-
client.price = new CommercetoolsPriceProvider(
|
|
76
|
+
client.price = new CommercetoolsPriceProvider(
|
|
77
|
+
config,
|
|
78
|
+
cache,
|
|
79
|
+
context,
|
|
80
|
+
commercetoolsClient
|
|
81
|
+
);
|
|
49
82
|
}
|
|
50
83
|
if (caps.category) {
|
|
51
|
-
client.category = new CommercetoolsCategoryProvider(
|
|
84
|
+
client.category = new CommercetoolsCategoryProvider(
|
|
85
|
+
config,
|
|
86
|
+
cache,
|
|
87
|
+
context,
|
|
88
|
+
commercetoolsClient
|
|
89
|
+
);
|
|
52
90
|
}
|
|
53
91
|
if (caps.checkout) {
|
|
54
|
-
client.checkout = new CommercetoolsCheckoutProvider(
|
|
92
|
+
client.checkout = new CommercetoolsCheckoutProvider(
|
|
93
|
+
config,
|
|
94
|
+
cache,
|
|
95
|
+
context,
|
|
96
|
+
commercetoolsClient
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (caps.store) {
|
|
100
|
+
client.store = new CommercetoolsStoreProvider(
|
|
101
|
+
config,
|
|
102
|
+
cache,
|
|
103
|
+
context,
|
|
104
|
+
commercetoolsClient
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (caps.order) {
|
|
108
|
+
client.store = new CommercetoolsOrderProvider(
|
|
109
|
+
config,
|
|
110
|
+
cache,
|
|
111
|
+
context,
|
|
112
|
+
commercetoolsClient
|
|
113
|
+
);
|
|
55
114
|
}
|
|
56
115
|
return client;
|
|
57
116
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-commercetools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.1.
|
|
7
|
+
"@reactionary/core": "0.1.11",
|
|
8
8
|
"debug": "^4.4.3",
|
|
9
9
|
"zod": "4.1.9",
|
|
10
10
|
"@commercetools/ts-client": "^4.2.1",
|
|
@@ -40,11 +40,10 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
|
|
|
40
40
|
}
|
|
41
41
|
async getFacetQuery(payload, selectedFacetValue) {
|
|
42
42
|
if (selectedFacetValue.facet.key === "categories") {
|
|
43
|
-
const category = await this.resolveCategoryFromKey({ key: selectedFacetValue.key });
|
|
44
43
|
return {
|
|
45
44
|
exact: {
|
|
46
45
|
field: "categoriesSubTree",
|
|
47
|
-
values: [
|
|
46
|
+
values: [selectedFacetValue.key],
|
|
48
47
|
fieldType: "text"
|
|
49
48
|
}
|
|
50
49
|
};
|
|
@@ -101,12 +100,11 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
|
|
|
101
100
|
if (!payload.search.categoryFilter) {
|
|
102
101
|
return void 0;
|
|
103
102
|
}
|
|
104
|
-
|
|
105
|
-
if (category) {
|
|
103
|
+
if (payload.search.categoryFilter.key) {
|
|
106
104
|
return {
|
|
107
105
|
exact: {
|
|
108
106
|
field: "categoriesSubTree",
|
|
109
|
-
values: [
|
|
107
|
+
values: [payload.search.categoryFilter.key],
|
|
110
108
|
fieldType: "text"
|
|
111
109
|
}
|
|
112
110
|
};
|
|
@@ -178,12 +176,14 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
|
|
|
178
176
|
async createCategoryNavigationFilter(payload) {
|
|
179
177
|
const categoryPath = payload.categoryPath;
|
|
180
178
|
const deepestCategory = categoryPath[categoryPath.length - 1];
|
|
179
|
+
const resolvedCategory = await this.resolveCategoryFromKey({ key: deepestCategory.identifier.key });
|
|
180
|
+
const resolvedId = resolvedCategory?.id;
|
|
181
181
|
const facetIdentifier = {
|
|
182
182
|
key: "categories"
|
|
183
183
|
};
|
|
184
184
|
const facetValueIdentifier = {
|
|
185
185
|
facet: facetIdentifier,
|
|
186
|
-
key:
|
|
186
|
+
key: resolvedId || "unknown"
|
|
187
187
|
};
|
|
188
188
|
return facetValueIdentifier;
|
|
189
189
|
}
|
|
@@ -255,10 +255,14 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
|
|
|
255
255
|
if (!categoryFacet) {
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
|
+
const resolvedCategories = categoryFacet.values.map((facetValue) => this.resolveCategoryFromId({ id: facetValue.identifier.key }));
|
|
259
|
+
const categories = await Promise.all(resolvedCategories);
|
|
258
260
|
for (const facetValue of categoryFacet.values) {
|
|
259
261
|
try {
|
|
260
|
-
const category =
|
|
261
|
-
|
|
262
|
+
const category = categories.find((c) => c.id === facetValue.identifier.key);
|
|
263
|
+
if (!category) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
262
266
|
facetValue.name = category.name[this.context.languageContext.locale] || category.id;
|
|
263
267
|
} catch (error) {
|
|
264
268
|
if (debug.enabled) {
|
package/src/core/initialize.d.ts
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
import type { Cache,
|
|
2
|
-
import { type CommercetoolsCapabilities } from
|
|
3
|
-
import { type CommercetoolsConfiguration } from
|
|
4
|
-
|
|
5
|
-
cart: CartProvider;
|
|
6
|
-
} : object) & (T['product'] extends true ? {
|
|
7
|
-
product: ProductProvider;
|
|
8
|
-
} : object) & (T['productSearch'] extends true ? {
|
|
9
|
-
productSearch: ProductSearchProvider;
|
|
10
|
-
} : object) & (T['identity'] extends true ? {
|
|
11
|
-
identity: IdentityProvider;
|
|
12
|
-
} : object) & (T['category'] extends true ? {
|
|
13
|
-
category: CategoryProvider;
|
|
14
|
-
} : object) & (T['inventory'] extends true ? {
|
|
15
|
-
inventory: InventoryProvider;
|
|
16
|
-
} : object) & (T['price'] extends true ? {
|
|
17
|
-
price: PriceProvider;
|
|
18
|
-
} : object) & (T['store'] extends true ? {
|
|
19
|
-
store: StoreProvider;
|
|
20
|
-
} : object) & (T['order'] extends true ? {
|
|
21
|
-
order: OrderProvider;
|
|
22
|
-
} : object) & (T['profile'] extends true ? {
|
|
23
|
-
profile: ProfileProvider;
|
|
24
|
-
} : object) & (T['checkout'] extends true ? {
|
|
25
|
-
checkout: CheckoutProvider;
|
|
26
|
-
} : object);
|
|
27
|
-
export declare function withCommercetoolsCapabilities<T extends CommercetoolsCapabilities>(configuration: CommercetoolsConfiguration, capabilities: T): (cache: Cache, context: RequestContext) => CommercetoolsProviderSet<T>;
|
|
28
|
-
export {};
|
|
1
|
+
import type { Cache, RequestContext, ClientFromCapabilities } from '@reactionary/core';
|
|
2
|
+
import { type CommercetoolsCapabilities } from '../schema/capabilities.schema.js';
|
|
3
|
+
import { type CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
|
+
export declare function withCommercetoolsCapabilities<T extends CommercetoolsCapabilities>(configuration: CommercetoolsConfiguration, capabilities: T): (cache: Cache, context: RequestContext) => ClientFromCapabilities<T>;
|