@reactionary/provider-algolia 0.0.61 → 0.0.63

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.
@@ -1,15 +1,10 @@
1
- import { ProductSchema, ProductSearchResultItemSchema } from "@reactionary/core";
2
- import { AlgoliaProductProvider } from "../providers/product.provider.js";
1
+ import { ProductSearchResultItemSchema } from "@reactionary/core";
3
2
  import { AlgoliaSearchProvider } from "../providers/product-search.provider.js";
4
- import { AlgoliaSearchResultSchema } from "../schema/search.schema.js";
5
3
  function withAlgoliaCapabilities(configuration, capabilities) {
6
- return (cache) => {
4
+ return (cache, context) => {
7
5
  const client = {};
8
- if (capabilities.product) {
9
- client.product = new AlgoliaProductProvider(configuration, ProductSchema, cache);
10
- }
11
6
  if (capabilities.productSearch) {
12
- client.productSearch = new AlgoliaSearchProvider(configuration, ProductSearchResultItemSchema, cache);
7
+ client.productSearch = new AlgoliaSearchProvider(configuration, ProductSearchResultItemSchema, cache, context);
13
8
  }
14
9
  return client;
15
10
  };
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./core/initialize.js";
2
- export * from "./providers/product.provider.js";
3
2
  export * from "./providers/product-search.provider.js";
4
3
  export * from "./schema/configuration.schema.js";
5
4
  export * from "./schema/capabilities.schema.js";
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@reactionary/provider-algolia",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.0.61",
7
+ "@reactionary/core": "0.0.63",
8
8
  "algoliasearch": "^5.23.4",
9
9
  "zod": "4.1.9"
10
10
  },
@@ -1,2 +1 @@
1
1
  export * from "./product-search.provider.js";
2
- export * from "./product.provider.js";
@@ -11,11 +11,11 @@ import {
11
11
  import { algoliasearch } from "algoliasearch";
12
12
  import { AlgoliaSearchIdentifierSchema } from "../schema/search.schema.js";
13
13
  class AlgoliaSearchProvider extends ProductSearchProvider {
14
- constructor(config, schema, cache) {
15
- super(schema, cache);
14
+ constructor(config, schema, cache, context) {
15
+ super(schema, cache, context);
16
16
  this.config = config;
17
17
  }
18
- async queryByTerm(payload, reqCtx) {
18
+ async queryByTerm(payload) {
19
19
  const client = algoliasearch(this.config.appId, this.config.apiKey);
20
20
  const remote = await client.search({
21
21
  requests: [
@@ -40,7 +40,7 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
40
40
  index: input.index,
41
41
  key: input.queryID
42
42
  });
43
- const result = this.parsePaginatedResult(input, reqCtx);
43
+ const result = this.parsePaginatedResult(input);
44
44
  result.identifier = identifier;
45
45
  for (const selectedFacet of payload.search.facets) {
46
46
  const facet = result.facets.find((f) => f.identifier.key === selectedFacet.facet.key);
@@ -57,15 +57,15 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
57
57
  };
58
58
  return result;
59
59
  }
60
- parseSingle(body, reqCtx) {
60
+ parseSingle(body) {
61
61
  const product = this.newModel();
62
62
  product.identifier = { key: body.objectID };
63
63
  product.name = body.name || body.objectID;
64
64
  product.slug = body.slug || body.objectID;
65
- product.variants = [...body.variants || []].map((variant) => this.parseVariant(variant, body, reqCtx));
65
+ product.variants = [...body.variants || []].map((variant) => this.parseVariant(variant, body));
66
66
  return this.assert(product);
67
67
  }
68
- parseVariant(variant, product, reqCtx) {
68
+ parseVariant(variant, product) {
69
69
  const result = ProductSearchResultItemVariantSchema.parse({
70
70
  variant: {
71
71
  sku: variant.variantID
@@ -77,15 +77,15 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
77
77
  });
78
78
  return result;
79
79
  }
80
- parsePaginatedResult(body, reqCtx) {
81
- const items = body.hits.map((hit) => this.parseSingle(hit, reqCtx));
80
+ parsePaginatedResult(body) {
81
+ const items = body.hits.map((hit) => this.parseSingle(hit));
82
82
  const facets = [];
83
83
  for (const id in body.facets) {
84
84
  const f = body.facets[id];
85
85
  const facetId = FacetIdentifierSchema.parse({
86
86
  key: id
87
87
  });
88
- const facet = this.parseFacet(facetId, f, reqCtx);
88
+ const facet = this.parseFacet(facetId, f);
89
89
  facets.push(facet);
90
90
  }
91
91
  const result = createPaginatedResponseSchema(this.schema).parse({
@@ -102,7 +102,7 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
102
102
  result.facets = facets;
103
103
  return result;
104
104
  }
105
- parseFacet(facetIdentifier, facetValues, reqCtx) {
105
+ parseFacet(facetIdentifier, facetValues) {
106
106
  const result = ProductSearchResultFacetSchema.parse({
107
107
  identifier: facetIdentifier,
108
108
  name: facetIdentifier.key,
@@ -114,11 +114,11 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
114
114
  facet: facetIdentifier,
115
115
  key: vid
116
116
  });
117
- result.values.push(this.parseFacetValue(facetValueIdentifier, vid, fv, reqCtx));
117
+ result.values.push(this.parseFacetValue(facetValueIdentifier, vid, fv));
118
118
  }
119
119
  return result;
120
120
  }
121
- parseFacetValue(facetValueIdentifier, label, count, reqCtx) {
121
+ parseFacetValue(facetValueIdentifier, label, count) {
122
122
  return ProductSearchResultFacetValueSchema.parse({
123
123
  identifier: facetValueIdentifier,
124
124
  name: label,
@@ -1,6 +1,5 @@
1
1
  import { CapabilitiesSchema } from "@reactionary/core";
2
2
  const AlgoliaCapabilitiesSchema = CapabilitiesSchema.pick({
3
- product: true,
4
3
  productSearch: true,
5
4
  analytics: true
6
5
  }).partial();
@@ -1,4 +1,8 @@
1
- import type { Client, Cache } from "@reactionary/core";
1
+ import type { Cache, ProductSearchProvider, RequestContext } from "@reactionary/core";
2
2
  import type { AlgoliaCapabilities } from "../schema/capabilities.schema.js";
3
3
  import type { AlgoliaConfiguration } from "../schema/configuration.schema.js";
4
- export declare function withAlgoliaCapabilities(configuration: AlgoliaConfiguration, capabilities: AlgoliaCapabilities): (cache: Cache) => Partial<Client>;
4
+ type AlgoliaClient<T extends AlgoliaCapabilities> = (T['productSearch'] extends true ? {
5
+ productSearch: ProductSearchProvider;
6
+ } : object);
7
+ export declare function withAlgoliaCapabilities<T extends AlgoliaCapabilities>(configuration: AlgoliaConfiguration, capabilities: T): (cache: Cache, context: RequestContext) => AlgoliaClient<T>;
8
+ export {};
package/src/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './core/initialize.js';
2
- export * from './providers/product.provider.js';
3
2
  export * from './providers/product-search.provider.js';
4
3
  export * from './schema/configuration.schema.js';
5
4
  export * from './schema/capabilities.schema.js';
@@ -1,2 +1 @@
1
1
  export * from './product-search.provider.js';
2
- export * from './product.provider.js';
@@ -14,11 +14,11 @@ interface AlgoliaNativeRecord {
14
14
  }
15
15
  export declare class AlgoliaSearchProvider<T extends ProductSearchResultItem = ProductSearchResultItem> extends ProductSearchProvider<T> {
16
16
  protected config: AlgoliaConfiguration;
17
- constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, cache: Cache);
18
- queryByTerm(payload: ProductSearchQueryByTerm, reqCtx: RequestContext): Promise<ProductSearchResult>;
19
- protected parseSingle(body: AlgoliaNativeRecord, reqCtx: RequestContext): T;
20
- protected parseVariant(variant: AlgoliaNativeVariant, product: AlgoliaNativeRecord, reqCtx: RequestContext): ProductSearchResultItemVariant;
21
- protected parsePaginatedResult(body: SearchResponse<AlgoliaNativeRecord>, reqCtx: RequestContext): {
17
+ constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext);
18
+ queryByTerm(payload: ProductSearchQueryByTerm): Promise<ProductSearchResult>;
19
+ protected parseSingle(body: AlgoliaNativeRecord): T;
20
+ protected parseVariant(variant: AlgoliaNativeVariant, product: AlgoliaNativeRecord): ProductSearchResultItemVariant;
21
+ protected parsePaginatedResult(body: SearchResponse<AlgoliaNativeRecord>): {
22
22
  meta: {
23
23
  [x: string]: unknown;
24
24
  cache: {
@@ -34,7 +34,7 @@ export declare class AlgoliaSearchProvider<T extends ProductSearchResultItem = P
34
34
  totalPages: number;
35
35
  items: T[];
36
36
  };
37
- protected parseFacet(facetIdentifier: FacetIdentifier, facetValues: Record<string, number>, reqCtx: RequestContext): ProductSearchResultFacet;
38
- protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number, reqCtx: RequestContext): ProductSearchResultFacetValue;
37
+ protected parseFacet(facetIdentifier: FacetIdentifier, facetValues: Record<string, number>): ProductSearchResultFacet;
38
+ protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number): ProductSearchResultFacetValue;
39
39
  }
40
40
  export {};
@@ -1,6 +1,5 @@
1
1
  import type { z } from 'zod';
2
2
  export declare const AlgoliaCapabilitiesSchema: z.ZodObject<{
3
- product: z.ZodOptional<z.ZodBoolean>;
4
3
  analytics: z.ZodOptional<z.ZodBoolean>;
5
4
  productSearch: z.ZodOptional<z.ZodBoolean>;
6
5
  }, z.core.$loose>;
@@ -1,39 +0,0 @@
1
- import {
2
- ProductProvider
3
- } from "@reactionary/core";
4
- class AlgoliaProductProvider extends ProductProvider {
5
- constructor(config, schema, cache) {
6
- super(schema, cache);
7
- this.config = config;
8
- }
9
- async getById(payload, _reqCtx) {
10
- const result = this.newModel();
11
- result.identifier = { key: payload.id };
12
- result.name = `Algolia Product ${payload.id}`;
13
- result.slug = payload.id;
14
- result.description = "Product from Algolia";
15
- result.meta = {
16
- cache: { hit: false, key: payload.id },
17
- placeholder: true
18
- };
19
- return this.assert(result);
20
- }
21
- async getBySlug(payload, _reqCtx) {
22
- const result = this.newModel();
23
- result.identifier = { key: payload.slug };
24
- result.name = `Algolia Product ${payload.slug}`;
25
- result.slug = payload.slug;
26
- result.description = "Product from Algolia";
27
- result.meta = {
28
- cache: { hit: false, key: payload.slug },
29
- placeholder: true
30
- };
31
- return this.assert(result);
32
- }
33
- getBySKU(payload, reqCtx) {
34
- throw new Error("Method not implemented.");
35
- }
36
- }
37
- export {
38
- AlgoliaProductProvider
39
- };
@@ -1,11 +0,0 @@
1
- import type { Product, ProductQueryById, ProductQueryBySlug, RequestContext, Cache, ProductQueryBySKU } from '@reactionary/core';
2
- import { ProductProvider } from '@reactionary/core';
3
- import type { z } from 'zod';
4
- import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
5
- export declare class AlgoliaProductProvider<T extends Product = Product> extends ProductProvider<T> {
6
- protected config: AlgoliaConfiguration;
7
- constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, cache: Cache);
8
- getById(payload: ProductQueryById, _reqCtx: RequestContext): Promise<T>;
9
- getBySlug(payload: ProductQueryBySlug, _reqCtx: RequestContext): Promise<T>;
10
- getBySKU(payload: ProductQueryBySKU, reqCtx: RequestContext): Promise<T>;
11
- }