@reactionary/algolia 0.7.5 → 0.8.0
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.
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
algoliasearch
|
|
6
6
|
} from "algoliasearch";
|
|
7
|
+
import { getProductIndexNameForLocale } from "../core/index-utils.js";
|
|
7
8
|
class AlgoliaAnalyticsCapability extends AnalyticsCapability {
|
|
8
9
|
client;
|
|
9
10
|
config;
|
|
@@ -18,7 +19,7 @@ class AlgoliaAnalyticsCapability extends AnalyticsCapability {
|
|
|
18
19
|
eventName: "addToCart",
|
|
19
20
|
eventType: "conversion",
|
|
20
21
|
eventSubtype: "addToCart",
|
|
21
|
-
index: this.config.indexName,
|
|
22
|
+
index: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
22
23
|
objectIDs: [event.product.key],
|
|
23
24
|
userToken: this.context.session.identityContext.personalizationKey,
|
|
24
25
|
queryID: event.source.identifier.key
|
|
@@ -33,7 +34,7 @@ class AlgoliaAnalyticsCapability extends AnalyticsCapability {
|
|
|
33
34
|
const algoliaEvent = {
|
|
34
35
|
eventName: "click",
|
|
35
36
|
eventType: "click",
|
|
36
|
-
index: this.config.indexName,
|
|
37
|
+
index: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
37
38
|
objectIDs: [event.product.key],
|
|
38
39
|
userToken: this.context.session.identityContext.personalizationKey,
|
|
39
40
|
positions: [event.position],
|
|
@@ -49,7 +50,7 @@ class AlgoliaAnalyticsCapability extends AnalyticsCapability {
|
|
|
49
50
|
const algoliaEvent = {
|
|
50
51
|
eventName: "view",
|
|
51
52
|
eventType: "view",
|
|
52
|
-
index: this.config.indexName,
|
|
53
|
+
index: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
53
54
|
objectIDs: event.products.map((x) => x.key),
|
|
54
55
|
userToken: this.context.session.identityContext.personalizationKey
|
|
55
56
|
};
|
|
@@ -63,7 +64,7 @@ class AlgoliaAnalyticsCapability extends AnalyticsCapability {
|
|
|
63
64
|
eventName: "purchase",
|
|
64
65
|
eventType: "conversion",
|
|
65
66
|
eventSubtype: "purchase",
|
|
66
|
-
index: this.config.indexName,
|
|
67
|
+
index: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
67
68
|
objectIDs: event.order.items.map((x) => x.variant.sku),
|
|
68
69
|
userToken: this.context.session.identityContext.personalizationKey
|
|
69
70
|
};
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
liteClient
|
|
8
8
|
} from "algoliasearch/lite";
|
|
9
|
+
import { getProductIndexNameForLocale } from "../core/index-utils.js";
|
|
9
10
|
class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapability {
|
|
10
11
|
config;
|
|
11
12
|
client;
|
|
@@ -38,7 +39,7 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
|
|
|
38
39
|
const response = await this.client.getRecommendations({
|
|
39
40
|
requests: [
|
|
40
41
|
{
|
|
41
|
-
indexName: this.config.indexName,
|
|
42
|
+
indexName: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
42
43
|
model: "bought-together",
|
|
43
44
|
objectID: query.sourceProduct.key,
|
|
44
45
|
maxRecommendations: query.numberOfRecommendations,
|
|
@@ -71,7 +72,7 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
|
|
|
71
72
|
const response = await this.client.getRecommendations({
|
|
72
73
|
requests: [
|
|
73
74
|
{
|
|
74
|
-
indexName: this.config.indexName,
|
|
75
|
+
indexName: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
75
76
|
model: "looking-similar",
|
|
76
77
|
objectID: query.sourceProduct.key,
|
|
77
78
|
maxRecommendations: query.numberOfRecommendations,
|
|
@@ -104,7 +105,7 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
|
|
|
104
105
|
const response = await this.client.getRecommendations({
|
|
105
106
|
requests: [
|
|
106
107
|
{
|
|
107
|
-
indexName: this.config.indexName,
|
|
108
|
+
indexName: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
108
109
|
model: "related-products",
|
|
109
110
|
objectID: query.sourceProduct.key,
|
|
110
111
|
maxRecommendations: query.numberOfRecommendations,
|
|
@@ -137,7 +138,7 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
|
|
|
137
138
|
const response = await this.client.getRecommendations({
|
|
138
139
|
requests: [
|
|
139
140
|
{
|
|
140
|
-
indexName: this.config.indexName,
|
|
141
|
+
indexName: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
141
142
|
model: "trending-items",
|
|
142
143
|
facetName: "categories",
|
|
143
144
|
facetValue: query.sourceCategory.key,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
success
|
|
20
20
|
} from "@reactionary/core";
|
|
21
21
|
import { algoliasearch } from "algoliasearch";
|
|
22
|
+
import { getProductIndexNameForLocale } from "../core/index-utils.js";
|
|
22
23
|
class AlgoliaProductSearchCapability extends ProductSearchCapability {
|
|
23
24
|
config;
|
|
24
25
|
factory;
|
|
@@ -40,7 +41,7 @@ class AlgoliaProductSearchCapability extends ProductSearchCapability {
|
|
|
40
41
|
finalFilters.push(`categories:"${categoryFacet.key}"`);
|
|
41
42
|
}
|
|
42
43
|
return {
|
|
43
|
-
indexName: this.config.indexName,
|
|
44
|
+
indexName: getProductIndexNameForLocale(this.config.indexName, this.context.languageContext.locale),
|
|
44
45
|
query: payload.search.term,
|
|
45
46
|
page: payload.search.paginationOptions.pageNumber - 1,
|
|
46
47
|
hitsPerPage: payload.search.paginationOptions.pageSize,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function getProductIndexNameForLocale(baseIndexName, locale) {
|
|
2
|
+
const localeShortCode = locale.split("-")[0];
|
|
3
|
+
if (localeShortCode === "en") {
|
|
4
|
+
return baseIndexName;
|
|
5
|
+
}
|
|
6
|
+
return `${baseIndexName}_${localeShortCode}`;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
getProductIndexNameForLocale
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/algolia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@reactionary/core": "0.
|
|
8
|
+
"@reactionary/core": "0.8.0",
|
|
9
9
|
"zod": "4.1.9",
|
|
10
10
|
"algoliasearch": "^5.48.0",
|
|
11
11
|
"vitest": "^4.0.9",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getProductIndexNameForLocale(baseIndexName: string, locale: string): string;
|