@reactionary/source 0.3.17 → 0.6.1
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/README.md +22 -11
- package/core/src/schemas/models/cart.model.ts +7 -2
- package/core/src/schemas/models/identifiers.model.ts +12 -8
- package/core/src/schemas/models/price.model.ts +9 -0
- package/examples/node/package.json +7 -7
- package/examples/node/src/capabilities/cart.spec.ts +97 -15
- package/examples/node/src/capabilities/category.spec.ts +27 -32
- package/examples/node/src/capabilities/checkout.spec.ts +5 -5
- package/examples/node/src/capabilities/identity.spec.ts +5 -1
- package/examples/node/src/capabilities/inventory.spec.ts +1 -1
- package/package.json +3 -3
- package/providers/algolia/src/providers/product-search.provider.ts +19 -14
- package/providers/commercetools/src/providers/cart.provider.ts +76 -11
- package/providers/fake/src/providers/cart.provider.ts +1 -0
- package/providers/medusa/src/providers/cart.provider.ts +159 -70
- package/providers/medusa/src/providers/category.provider.ts +35 -23
- package/providers/medusa/src/providers/checkout.provider.ts +78 -41
- package/providers/medusa/src/providers/order-search.provider.ts +21 -10
- package/providers/medusa/src/providers/product-recommendations.provider.ts +10 -6
- package/providers/medusa/src/providers/product-search.provider.ts +19 -10
- package/providers/medusa/src/providers/product.provider.ts +20 -12
- package/providers/medusa/src/providers/profile.provider.ts +38 -13
- package/providers/meilisearch/src/providers/order-search.provider.ts +17 -12
- package/providers/meilisearch/src/providers/product-recommendations.provider.ts +10 -11
- package/providers/meilisearch/src/providers/product-search.provider.ts +23 -18
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type ProductSearchResultItemVariant,
|
|
10
10
|
ProductSearchResultItemVariantSchema,
|
|
11
11
|
} from '@reactionary/core';
|
|
12
|
-
import { MeiliSearch, type Hits, type RecordAny, type SearchParams, type SearchResponse } from 'meilisearch';
|
|
12
|
+
import { MeiliSearch, type Hits, type RecordAny, type SearchParams, type SearchResponse, type SearchSimilarDocumentsParams } from 'meilisearch';
|
|
13
13
|
import type { MeilisearchConfiguration } from '../schema/configuration.schema.js';
|
|
14
14
|
import type { MeilisearchNativeRecord, MeilisearchNativeVariant } from '../schema/index.js';
|
|
15
15
|
|
|
@@ -32,6 +32,14 @@ export class MeilisearchProductRecommendationsProvider extends ProductRecommenda
|
|
|
32
32
|
this.config = config;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
protected getSimilarProductsRecommendationsPayload(query: ProductRecommendationAlgorithmSimilarProductsQuery): SearchSimilarDocumentsParams {
|
|
36
|
+
return {
|
|
37
|
+
id: query.sourceProduct.key,
|
|
38
|
+
limit: query.numberOfRecommendations,
|
|
39
|
+
embedder: this.config.useAIEmbedding,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
/**
|
|
36
44
|
* Get similar product recommendations
|
|
37
45
|
* Uses semantic search to find visually or data-wise similar products
|
|
@@ -52,16 +60,7 @@ export class MeilisearchProductRecommendationsProvider extends ProductRecommenda
|
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
try {
|
|
55
|
-
const
|
|
56
|
-
limit: query.numberOfRecommendations,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const response = await index.searchSimilarDocuments<MeilisearchNativeRecord>({
|
|
60
|
-
id: query.sourceProduct.key,
|
|
61
|
-
limit: query.numberOfRecommendations,
|
|
62
|
-
embedder: this.config.useAIEmbedding,
|
|
63
|
-
});
|
|
64
|
-
|
|
63
|
+
const response = await index.searchSimilarDocuments<MeilisearchNativeRecord>(this.getSimilarProductsRecommendationsPayload(query));
|
|
65
64
|
|
|
66
65
|
return this.parseRecommendations(response, 'similar');
|
|
67
66
|
} catch (error) {
|
|
@@ -36,23 +36,7 @@ export class MeilisearchSearchProvider extends ProductSearchProvider {
|
|
|
36
36
|
this.config = config;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
inputSchema: ProductSearchQueryByTermSchema,
|
|
41
|
-
outputSchema: ProductSearchResultSchema,
|
|
42
|
-
cache: true,
|
|
43
|
-
cacheTimeToLiveInSeconds: 300,
|
|
44
|
-
currencyDependentCaching: false,
|
|
45
|
-
localeDependentCaching: true
|
|
46
|
-
})
|
|
47
|
-
public override async queryByTerm(
|
|
48
|
-
payload: ProductSearchQueryByTerm
|
|
49
|
-
): Promise<Result<ProductSearchResult>> {
|
|
50
|
-
const client = new MeiliSearch({
|
|
51
|
-
host: this.config.apiUrl,
|
|
52
|
-
apiKey: this.config.apiKey,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const index = client.index(this.config.indexName);
|
|
39
|
+
protected queryByTermPayload(payload: ProductSearchQueryByTerm) {
|
|
56
40
|
|
|
57
41
|
const facetsThatAreNotCategory = payload.search.facets.filter(x => x.facet.key !== 'categories');
|
|
58
42
|
const categoryFacet = payload.search.facets.find(x => x.facet.key === 'categories') || payload.search.categoryFilter;
|
|
@@ -88,8 +72,29 @@ export class MeilisearchSearchProvider extends ProductSearchProvider {
|
|
|
88
72
|
embedder: this.config.useAIEmbedding
|
|
89
73
|
};
|
|
90
74
|
}
|
|
75
|
+
return searchOptions;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Reactionary({
|
|
79
|
+
inputSchema: ProductSearchQueryByTermSchema,
|
|
80
|
+
outputSchema: ProductSearchResultSchema,
|
|
81
|
+
cache: true,
|
|
82
|
+
cacheTimeToLiveInSeconds: 300,
|
|
83
|
+
currencyDependentCaching: false,
|
|
84
|
+
localeDependentCaching: true
|
|
85
|
+
})
|
|
86
|
+
public override async queryByTerm(
|
|
87
|
+
payload: ProductSearchQueryByTerm
|
|
88
|
+
): Promise<Result<ProductSearchResult>> {
|
|
89
|
+
const client = new MeiliSearch({
|
|
90
|
+
host: this.config.apiUrl,
|
|
91
|
+
apiKey: this.config.apiKey,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const index = client.index(this.config.indexName);
|
|
95
|
+
|
|
91
96
|
|
|
92
|
-
const remote = await index.search<MeilisearchNativeRecord>(payload.search.term,
|
|
97
|
+
const remote = await index.search<MeilisearchNativeRecord>(payload.search.term, this.queryByTermPayload(payload) as SearchParams);
|
|
93
98
|
|
|
94
99
|
const result = this.parsePaginatedResult(remote, payload) as MeilisearchProductSearchResult;
|
|
95
100
|
|