@reactionary/algolia 0.6.4 → 0.6.6

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.
@@ -31,6 +31,10 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
31
31
  */
32
32
  async getFrequentlyBoughtTogetherRecommendations(query) {
33
33
  try {
34
+ if (this.context.isBot && !this.config.useRecommendationsForBots) {
35
+ console.warn("Bot traffic detected. Recommendations are disabled for bots in configuration to save on API costs. Returning empty recommendations.");
36
+ return [];
37
+ }
34
38
  const response = await this.client.getRecommendations({
35
39
  requests: [
36
40
  {
@@ -60,6 +64,10 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
60
64
  */
61
65
  async getSimilarProductsRecommendations(query) {
62
66
  try {
67
+ if (this.context.isBot && !this.config.useRecommendationsForBots) {
68
+ console.warn("Bot traffic detected. Recommendations are disabled for bots in configuration to save on API costs. Returning empty recommendations.");
69
+ return [];
70
+ }
63
71
  const response = await this.client.getRecommendations({
64
72
  requests: [
65
73
  {
@@ -89,6 +97,10 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
89
97
  */
90
98
  async getRelatedProductsRecommendations(query) {
91
99
  try {
100
+ if (this.context.isBot && !this.config.useRecommendationsForBots) {
101
+ console.warn("Bot traffic detected. Recommendations are disabled for bots in configuration to save on API costs. Returning empty recommendations.");
102
+ return [];
103
+ }
92
104
  const response = await this.client.getRecommendations({
93
105
  requests: [
94
106
  {
@@ -118,6 +130,10 @@ class AlgoliaProductRecommendationsCapability extends ProductRecommendationsCapa
118
130
  */
119
131
  async getTrendingInCategoryRecommendations(query) {
120
132
  try {
133
+ if (this.context.isBot && !this.config.useRecommendationsForBots) {
134
+ console.warn("Bot traffic detected. Recommendations are disabled for bots in configuration to save on API costs. Returning empty recommendations.");
135
+ return [];
136
+ }
121
137
  const response = await this.client.getRecommendations({
122
138
  requests: [
123
139
  {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@reactionary/algolia",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
- "@reactionary/core": "0.6.4",
8
+ "@reactionary/core": "0.6.6",
9
9
  "zod": "4.1.9",
10
10
  "algoliasearch": "^5.48.0",
11
11
  "vitest": "^4.0.9",
@@ -2,7 +2,8 @@ import * as z from "zod";
2
2
  const AlgoliaConfigurationSchema = z.looseObject({
3
3
  appId: z.string(),
4
4
  apiKey: z.string(),
5
- indexName: z.string()
5
+ indexName: z.string(),
6
+ useRecommendationsForBots: z.boolean().default(false).meta({ description: "Whether to use recommendations for bot traffic. By default, recommendations are not used for bots to save on API costs, but enabling this can provide a better experience for bot traffic such as search engine crawlers." })
6
7
  });
7
8
  export {
8
9
  AlgoliaConfigurationSchema
@@ -3,5 +3,6 @@ export declare const AlgoliaConfigurationSchema: z.ZodObject<{
3
3
  appId: z.ZodString;
4
4
  apiKey: z.ZodString;
5
5
  indexName: z.ZodString;
6
+ useRecommendationsForBots: z.ZodDefault<z.ZodBoolean>;
6
7
  }, z.core.$loose>;
7
8
  export type AlgoliaConfiguration = z.infer<typeof AlgoliaConfigurationSchema>;
@@ -31,7 +31,8 @@ class ExtendedAlgoliaProductSearchFactory extends AlgoliaProductSearchFactory {
31
31
  const config = {
32
32
  appId: "ALGOLIA_APP_ID",
33
33
  apiKey: "ALGOLIA_API_KEY",
34
- indexName: "ALGOLIA_INDEX"
34
+ indexName: "ALGOLIA_INDEX",
35
+ useRecommendationsForBots: false
35
36
  };
36
37
  const client = new ClientBuilder(createInitialRequestContext()).withCache(new NoOpCache()).withCapability(
37
38
  withAlgoliaCapabilities(config, {