@reactionary/provider-algolia 0.3.6 → 0.3.8

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@reactionary/provider-algolia",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.3.6",
7
+ "@reactionary/core": "0.3.8",
8
8
  "algoliasearch": "^5.48.0",
9
9
  "zod": "4.1.9"
10
10
  },
@@ -1,5 +1,7 @@
1
1
  import {
2
- ProductRecommendationsProvider
2
+ ProductRecommendationsProvider,
3
+ ProductSearchResultItemVariantSchema,
4
+ ImageSchema
3
5
  } from "@reactionary/core";
4
6
  import {
5
7
  liteClient
@@ -157,12 +159,33 @@ class AlgoliaProductRecommendationsProvider extends ProductRecommendationsProvid
157
159
  * Maps Algolia recommendation results to ProductRecommendation format
158
160
  */
159
161
  parseSingle(hit, recommendationIdentifier) {
162
+ const product = this.parseSearchResultItem(hit);
160
163
  return {
161
164
  recommendationIdentifier,
162
- product: {
163
- key: hit.objectID
164
- }
165
+ recommendationReturnType: "productSearchResultItem",
166
+ product
167
+ };
168
+ }
169
+ parseSearchResultItem(body) {
170
+ const product = {
171
+ identifier: { key: body.objectID },
172
+ name: body.name || body.objectID,
173
+ slug: body.slug || body.objectID,
174
+ variants: [...body.variants || []].map((variant) => this.parseVariant(variant, body))
165
175
  };
176
+ return product;
177
+ }
178
+ parseVariant(variant, product) {
179
+ const result = ProductSearchResultItemVariantSchema.parse({
180
+ variant: {
181
+ sku: variant.sku
182
+ },
183
+ image: ImageSchema.parse({
184
+ sourceUrl: variant.image,
185
+ altText: product.name || ""
186
+ })
187
+ });
188
+ return result;
166
189
  }
167
190
  }
168
191
  export {
@@ -1,12 +1,8 @@
1
- import { type Cache, ProductRecommendationsProvider, type ProductRecommendation, type ProductRecommendationAlgorithmFrequentlyBoughtTogetherQuery, type ProductRecommendationAlgorithmSimilarProductsQuery, type ProductRecommendationAlgorithmRelatedProductsQuery, type ProductRecommendationAlgorithmTrendingInCategoryQuery, type RequestContext, type ProductRecommendationsQuery } from '@reactionary/core';
1
+ import { type Cache, ProductRecommendationsProvider, type ProductRecommendation, type ProductRecommendationAlgorithmFrequentlyBoughtTogetherQuery, type ProductRecommendationAlgorithmSimilarProductsQuery, type ProductRecommendationAlgorithmRelatedProductsQuery, type ProductRecommendationAlgorithmTrendingInCategoryQuery, type RequestContext, type ProductRecommendationsQuery, type ProductSearchResultItemVariant } from '@reactionary/core';
2
2
  import { type RecommendationsResults, type RecommendSearchParams, type LiteClient } from 'algoliasearch/lite';
3
3
  import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
4
4
  import type { AlgoliaProductRecommendationIdentifier } from '../schema/product-recommendation.schema.js';
5
- interface AlgoliaRecommendHit {
6
- objectID: string;
7
- sku?: string;
8
- [key: string]: unknown;
9
- }
5
+ import type { AlgoliaNativeRecord, AlgoliaNativeVariant } from '../schema/search.schema.js';
10
6
  /**
11
7
  * AlgoliaProductRecommendationsProvider
12
8
  *
@@ -38,21 +34,81 @@ export declare class AlgoliaProductRecommendationsProvider extends ProductRecomm
38
34
  * Get trending in category recommendations using Algolia Recommend
39
35
  */
40
36
  protected getTrendingInCategoryRecommendations(query: ProductRecommendationAlgorithmTrendingInCategoryQuery): Promise<ProductRecommendation[]>;
41
- protected parseRecommendation(res: RecommendationsResults, query: ProductRecommendationsQuery): {
37
+ protected parseRecommendation(res: RecommendationsResults, query: ProductRecommendationsQuery): ({
42
38
  [x: string]: unknown;
43
39
  recommendationIdentifier: {
44
40
  [x: string]: unknown;
45
41
  key: string;
46
42
  algorithm: string;
47
43
  };
44
+ recommendationReturnType: "idOnly";
48
45
  product: {
49
46
  [x: string]: unknown;
50
47
  key: string;
51
48
  };
52
- }[];
49
+ } | {
50
+ [x: string]: unknown;
51
+ recommendationIdentifier: {
52
+ [x: string]: unknown;
53
+ key: string;
54
+ algorithm: string;
55
+ };
56
+ recommendationReturnType: "productSearchResultItem";
57
+ product: {
58
+ [x: string]: unknown;
59
+ identifier: {
60
+ [x: string]: unknown;
61
+ key: string;
62
+ };
63
+ name: string;
64
+ slug: string;
65
+ variants: {
66
+ [x: string]: unknown;
67
+ variant: {
68
+ [x: string]: unknown;
69
+ sku: string;
70
+ };
71
+ image: {
72
+ [x: string]: unknown;
73
+ sourceUrl: string;
74
+ altText: string;
75
+ width?: number | undefined;
76
+ height?: number | undefined;
77
+ };
78
+ options?: {
79
+ [x: string]: unknown;
80
+ identifier: {
81
+ [x: string]: unknown;
82
+ key: string;
83
+ };
84
+ name: string;
85
+ value: {
86
+ [x: string]: unknown;
87
+ identifier: {
88
+ [x: string]: unknown;
89
+ option: {
90
+ [x: string]: unknown;
91
+ key: string;
92
+ };
93
+ key: string;
94
+ };
95
+ label: string;
96
+ };
97
+ } | undefined;
98
+ }[];
99
+ };
100
+ })[];
53
101
  /**
54
102
  * Maps Algolia recommendation results to ProductRecommendation format
55
103
  */
56
- protected parseSingle(hit: AlgoliaRecommendHit, recommendationIdentifier: AlgoliaProductRecommendationIdentifier): ProductRecommendation;
104
+ protected parseSingle(hit: AlgoliaNativeRecord, recommendationIdentifier: AlgoliaProductRecommendationIdentifier): ProductRecommendation;
105
+ protected parseSearchResultItem(body: AlgoliaNativeRecord): {
106
+ identifier: {
107
+ key: string;
108
+ };
109
+ name: string;
110
+ slug: string;
111
+ variants: ProductSearchResultItemVariant[];
112
+ };
113
+ protected parseVariant(variant: AlgoliaNativeVariant, product: AlgoliaNativeRecord): ProductSearchResultItemVariant;
57
114
  }
58
- export {};
@@ -1,16 +1,7 @@
1
1
  import { type Cache, type FacetIdentifier, type FacetValueIdentifier, ProductSearchProvider, type ProductSearchQueryByTerm, type ProductSearchQueryCreateNavigationFilter, type ProductSearchResult, type ProductSearchResultFacet, type ProductSearchResultFacetValue, type ProductSearchResultItemVariant, type RequestContext, type Result } from '@reactionary/core';
2
2
  import { type SearchResponse } from 'algoliasearch';
3
3
  import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
4
- interface AlgoliaNativeVariant {
5
- sku: string;
6
- image: string;
7
- }
8
- interface AlgoliaNativeRecord {
9
- objectID: string;
10
- slug?: string;
11
- name?: string;
12
- variants: Array<AlgoliaNativeVariant>;
13
- }
4
+ import type { AlgoliaNativeRecord, AlgoliaNativeVariant } from '../schema/search.schema.js';
14
5
  export declare class AlgoliaProductSearchProvider extends ProductSearchProvider {
15
6
  protected config: AlgoliaConfiguration;
16
7
  constructor(cache: Cache, context: RequestContext, config: AlgoliaConfiguration);
@@ -59,4 +50,3 @@ export declare class AlgoliaProductSearchProvider extends ProductSearchProvider
59
50
  protected parseFacet(facetIdentifier: FacetIdentifier, facetValues: Record<string, number>): ProductSearchResultFacet;
60
51
  protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number): ProductSearchResultFacetValue;
61
52
  }
62
- export {};
@@ -101,3 +101,13 @@ export declare const AlgoliaProductSearchResultSchema: z.ZodObject<{
101
101
  }, z.core.$strip>;
102
102
  export type AlgoliaProductSearchResult = z.infer<typeof AlgoliaProductSearchResultSchema>;
103
103
  export type AlgoliaProductSearchIdentifier = z.infer<typeof AlgoliaProductSearchIdentifierSchema>;
104
+ export interface AlgoliaNativeVariant {
105
+ sku: string;
106
+ image: string;
107
+ }
108
+ export interface AlgoliaNativeRecord {
109
+ objectID: string;
110
+ slug?: string;
111
+ name?: string;
112
+ variants: Array<AlgoliaNativeVariant>;
113
+ }