@reactionary/core 0.1.5 → 0.1.7

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
@@ -26,12 +26,6 @@ const ProductOptionValueIdentifierSchema = z.looseObject({
26
26
  const ProductIdentifierSchema = z.looseObject({
27
27
  key: z.string()
28
28
  });
29
- const ProductSearchIdentifierSchema = z.looseObject({
30
- term: z.string(),
31
- facets: z.array(FacetValueIdentifierSchema),
32
- filters: z.array(z.string()),
33
- paginationOptions: PaginationOptionsSchema
34
- });
35
29
  const CartIdentifierSchema = z.looseObject({
36
30
  key: z.string()
37
31
  });
@@ -89,6 +83,13 @@ const PaymentInstructionIdentifierSchema = z.looseObject({
89
83
  const PickupPointIdentifierSchema = z.looseObject({
90
84
  key: z.string()
91
85
  });
86
+ const ProductSearchIdentifierSchema = z.looseObject({
87
+ term: z.string().describe("The search term used to find products."),
88
+ facets: z.array(FacetValueIdentifierSchema).describe("The facets applied to filter the search results."),
89
+ filters: z.array(z.string()).describe("Additional filters applied to the search results."),
90
+ paginationOptions: PaginationOptionsSchema.describe("Pagination options for the search results."),
91
+ categoryFilter: FacetValueIdentifierSchema.optional().describe("An optional category filter applied to the search results.")
92
+ });
92
93
  export {
93
94
  AddressIdentifierSchema,
94
95
  CartIdentifierSchema,
@@ -1,8 +1,14 @@
1
- import { BaseQuerySchema } from "./base.query.js";
1
+ import { z } from "zod";
2
+ import { CategorySchema } from "../models/category.model.js";
2
3
  import { ProductSearchIdentifierSchema } from "../models/identifiers.model.js";
4
+ import { BaseQuerySchema } from "./base.query.js";
3
5
  const ProductSearchQueryByTermSchema = BaseQuerySchema.extend({
4
6
  search: ProductSearchIdentifierSchema
5
7
  });
8
+ const ProductSearchQueryCreateNavigationFilterSchema = z.looseObject({
9
+ categoryPath: z.array(CategorySchema).describe("An array representing the breadcrumb path to a category, from root to the specific category.")
10
+ }).describe("Payload to create a category navigation filter from a breadcrumb path.");
6
11
  export {
7
- ProductSearchQueryByTermSchema
12
+ ProductSearchQueryByTermSchema,
13
+ ProductSearchQueryCreateNavigationFilterSchema
8
14
  };
@@ -1,10 +1,29 @@
1
1
  import type { FacetIdentifier, FacetValueIdentifier } from '../index.js';
2
2
  import type { ProductSearchResult, ProductSearchResultFacet, ProductSearchResultFacetValue, ProductSearchResultItemVariant } from '../schemas/models/product-search.model.js';
3
- import type { ProductSearchQueryByTerm } from '../schemas/queries/product-search.query.js';
3
+ import type { ProductSearchQueryByTerm, ProductSearchQueryCreateNavigationFilter } from '../schemas/queries/product-search.query.js';
4
4
  import { BaseProvider } from './base.provider.js';
5
5
  export declare abstract class ProductSearchProvider extends BaseProvider {
6
6
  protected getResourceName(): string;
7
7
  abstract queryByTerm(payload: ProductSearchQueryByTerm): Promise<ProductSearchResult>;
8
+ /**
9
+ * Since each platform has it own way of representing categories and their hierarchy, we leave it to the platform to tell us how to get from a
10
+ * category breadcrumb path to a global category navigation filter that can be applied to product searches.
11
+ *
12
+ * So, the CLP pattern would be
13
+ *
14
+ * const c: Category = await categoryProvider.getBySlug({ slug: 'some-category' });
15
+ * const breadcrumbPath: Category[] = await categoryProvider.getBreadcrumbPathToCategory({ id: c.identifier });
16
+ * const categoryFilter: FacetValueIdentifier = categoryNavigationProvider.createCategoryNavigationFilterBreadcrumbs(breadcrumbPath);
17
+ * const searchResult: ProductSearchResult = await productSearchProvider.queryByTerm({ term: 'some search', facets: [], categoryFilter: [categoryFilter], ... });
18
+ *
19
+ * from here, you would maybe get facets back with subcategories, but those are relative to the current category filter you have applied, so you
20
+ * do not need any special handling for that.
21
+ *
22
+ * Usecase: You are rendering a category page and you want to run a product search to find everything in that category (or below).
23
+ *
24
+ * @param categoryPath
25
+ */
26
+ abstract createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<FacetValueIdentifier>;
8
27
  /**
9
28
  * Parses a facet value from the search response.
10
29
  * @param facetValueIdentifier The identifier for the facet value.
@@ -30,20 +30,6 @@ export declare const ProductOptionValueIdentifierSchema: z.ZodObject<{
30
30
  export declare const ProductIdentifierSchema: z.ZodObject<{
31
31
  key: z.ZodString;
32
32
  }, z.core.$loose>;
33
- export declare const ProductSearchIdentifierSchema: z.ZodObject<{
34
- term: z.ZodString;
35
- facets: z.ZodArray<z.ZodObject<{
36
- facet: z.ZodObject<{
37
- key: z.ZodString;
38
- }, z.core.$loose>;
39
- key: z.ZodString;
40
- }, z.core.$strip>>;
41
- filters: z.ZodArray<z.ZodString>;
42
- paginationOptions: z.ZodObject<{
43
- pageNumber: z.ZodDefault<z.ZodNumber>;
44
- pageSize: z.ZodDefault<z.ZodNumber>;
45
- }, z.core.$loose>;
46
- }, z.core.$loose>;
47
33
  export declare const CartIdentifierSchema: z.ZodObject<{
48
34
  key: z.ZodString;
49
35
  }, z.core.$loose>;
@@ -110,6 +96,26 @@ export declare const PaymentInstructionIdentifierSchema: z.ZodObject<{
110
96
  export declare const PickupPointIdentifierSchema: z.ZodObject<{
111
97
  key: z.ZodString;
112
98
  }, z.core.$loose>;
99
+ export declare const ProductSearchIdentifierSchema: z.ZodObject<{
100
+ term: z.ZodString;
101
+ facets: z.ZodArray<z.ZodObject<{
102
+ facet: z.ZodObject<{
103
+ key: z.ZodString;
104
+ }, z.core.$loose>;
105
+ key: z.ZodString;
106
+ }, z.core.$strip>>;
107
+ filters: z.ZodArray<z.ZodString>;
108
+ paginationOptions: z.ZodObject<{
109
+ pageNumber: z.ZodDefault<z.ZodNumber>;
110
+ pageSize: z.ZodDefault<z.ZodNumber>;
111
+ }, z.core.$loose>;
112
+ categoryFilter: z.ZodOptional<z.ZodObject<{
113
+ facet: z.ZodObject<{
114
+ key: z.ZodString;
115
+ }, z.core.$loose>;
116
+ key: z.ZodString;
117
+ }, z.core.$strip>>;
118
+ }, z.core.$loose>;
113
119
  export type ProductIdentifier = InferType<typeof ProductIdentifierSchema>;
114
120
  export type ProductVariantIdentifier = InferType<typeof ProductVariantIdentifierSchema>;
115
121
  export type SearchIdentifier = InferType<typeof ProductSearchIdentifierSchema>;
@@ -159,6 +159,12 @@ export declare const ProductSearchResultSchema: z.ZodObject<{
159
159
  pageNumber: z.ZodDefault<z.ZodNumber>;
160
160
  pageSize: z.ZodDefault<z.ZodNumber>;
161
161
  }, z.core.$loose>;
162
+ categoryFilter: z.ZodOptional<z.ZodObject<{
163
+ facet: z.ZodObject<{
164
+ key: z.ZodString;
165
+ }, z.core.$loose>;
166
+ key: z.ZodString;
167
+ }, z.core.$strip>>;
162
168
  }, z.core.$loose>;
163
169
  facets: z.ZodArray<z.ZodObject<{
164
170
  identifier: z.ZodObject<{
@@ -15,6 +15,12 @@ export declare const AnalyticsMutationSearchEventSchema: z.ZodObject<{
15
15
  pageNumber: z.ZodDefault<z.ZodNumber>;
16
16
  pageSize: z.ZodDefault<z.ZodNumber>;
17
17
  }, z.core.$loose>;
18
+ categoryFilter: z.ZodOptional<z.ZodObject<{
19
+ facet: z.ZodObject<{
20
+ key: z.ZodString;
21
+ }, z.core.$loose>;
22
+ key: z.ZodString;
23
+ }, z.core.$strip>>;
18
24
  }, z.core.$loose>;
19
25
  products: z.ZodArray<z.ZodObject<{
20
26
  key: z.ZodString;
@@ -35,6 +41,12 @@ export declare const AnalyticsMutationSearchProductClickEventSchema: z.ZodObject
35
41
  pageNumber: z.ZodDefault<z.ZodNumber>;
36
42
  pageSize: z.ZodDefault<z.ZodNumber>;
37
43
  }, z.core.$loose>;
44
+ categoryFilter: z.ZodOptional<z.ZodObject<{
45
+ facet: z.ZodObject<{
46
+ key: z.ZodString;
47
+ }, z.core.$loose>;
48
+ key: z.ZodString;
49
+ }, z.core.$strip>>;
38
50
  }, z.core.$loose>;
39
51
  product: z.ZodObject<{
40
52
  key: z.ZodString;
@@ -56,6 +68,12 @@ export declare const AnalyticsMutationSchema: z.ZodUnion<readonly [z.ZodObject<{
56
68
  pageNumber: z.ZodDefault<z.ZodNumber>;
57
69
  pageSize: z.ZodDefault<z.ZodNumber>;
58
70
  }, z.core.$loose>;
71
+ categoryFilter: z.ZodOptional<z.ZodObject<{
72
+ facet: z.ZodObject<{
73
+ key: z.ZodString;
74
+ }, z.core.$loose>;
75
+ key: z.ZodString;
76
+ }, z.core.$strip>>;
59
77
  }, z.core.$loose>;
60
78
  products: z.ZodArray<z.ZodObject<{
61
79
  key: z.ZodString;
@@ -75,6 +93,12 @@ export declare const AnalyticsMutationSchema: z.ZodUnion<readonly [z.ZodObject<{
75
93
  pageNumber: z.ZodDefault<z.ZodNumber>;
76
94
  pageSize: z.ZodDefault<z.ZodNumber>;
77
95
  }, z.core.$loose>;
96
+ categoryFilter: z.ZodOptional<z.ZodObject<{
97
+ facet: z.ZodObject<{
98
+ key: z.ZodString;
99
+ }, z.core.$loose>;
100
+ key: z.ZodString;
101
+ }, z.core.$strip>>;
78
102
  }, z.core.$loose>;
79
103
  product: z.ZodObject<{
80
104
  key: z.ZodString;
@@ -1,4 +1,4 @@
1
- import type { z } from 'zod';
1
+ import { z } from 'zod';
2
2
  import type { InferType } from '../../zod-utils.js';
3
3
  export declare const ProductSearchQueryByTermSchema: z.ZodObject<{
4
4
  search: z.ZodObject<{
@@ -14,6 +14,39 @@ export declare const ProductSearchQueryByTermSchema: z.ZodObject<{
14
14
  pageNumber: z.ZodDefault<z.ZodNumber>;
15
15
  pageSize: z.ZodDefault<z.ZodNumber>;
16
16
  }, z.core.$loose>;
17
+ categoryFilter: z.ZodOptional<z.ZodObject<{
18
+ facet: z.ZodObject<{
19
+ key: z.ZodString;
20
+ }, z.core.$loose>;
21
+ key: z.ZodString;
22
+ }, z.core.$strip>>;
17
23
  }, z.core.$loose>;
18
24
  }, z.core.$loose>;
25
+ export declare const ProductSearchQueryCreateNavigationFilterSchema: z.ZodObject<{
26
+ categoryPath: z.ZodArray<z.ZodObject<{
27
+ meta: z.ZodDefault<z.ZodObject<{
28
+ cache: z.ZodDefault<z.ZodObject<{
29
+ hit: z.ZodDefault<z.ZodBoolean>;
30
+ key: z.ZodDefault<z.ZodString>;
31
+ }, z.core.$loose>>;
32
+ placeholder: z.ZodDefault<z.ZodBoolean>;
33
+ }, z.core.$loose>>;
34
+ identifier: z.ZodDefault<z.ZodObject<{
35
+ key: z.ZodString;
36
+ }, z.core.$loose>>;
37
+ name: z.ZodDefault<z.ZodString>;
38
+ slug: z.ZodDefault<z.ZodString>;
39
+ text: z.ZodDefault<z.ZodString>;
40
+ images: z.ZodDefault<z.ZodArray<z.ZodObject<{
41
+ sourceUrl: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
42
+ altText: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
43
+ width: z.ZodNonOptional<z.ZodOptional<z.ZodNumber>>;
44
+ height: z.ZodNonOptional<z.ZodOptional<z.ZodNumber>>;
45
+ }, z.core.$loose>>>;
46
+ parentCategory: z.ZodOptional<z.ZodObject<{
47
+ key: z.ZodString;
48
+ }, z.core.$loose>>;
49
+ }, z.core.$loose>>;
50
+ }, z.core.$loose>;
19
51
  export type ProductSearchQueryByTerm = InferType<typeof ProductSearchQueryByTermSchema>;
52
+ export type ProductSearchQueryCreateNavigationFilter = InferType<typeof ProductSearchQueryCreateNavigationFilterSchema>;