@reactionary/core 0.1.4 → 0.1.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.
- package/package.json +1 -1
- package/providers/product.provider.js +2 -1
- package/schemas/models/identifiers.model.js +7 -6
- package/schemas/models/product.model.js +2 -1
- package/schemas/queries/product-search.query.js +8 -2
- package/src/providers/product-search.provider.d.ts +20 -1
- package/src/schemas/models/identifiers.model.d.ts +20 -14
- package/src/schemas/models/product-search.model.d.ts +6 -0
- package/src/schemas/models/product.model.d.ts +31 -0
- package/src/schemas/mutations/analytics.mutation.d.ts +24 -0
- package/src/schemas/queries/product-search.query.d.ts +34 -1
package/package.json
CHANGED
|
@@ -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,
|
|
@@ -48,7 +48,8 @@ const ProductSchema = BaseModelSchema.extend({
|
|
|
48
48
|
published: z.boolean().describe("Indicates whether the product is published and visible to customers"),
|
|
49
49
|
sharedAttributes: z.array(ProductAttributeSchema).describe("A list of technical attributes associated with the product"),
|
|
50
50
|
options: z.array(ProductOptionSchema).describe("A list of options available for the product, such as size or color. Can be empty if product is single-sku"),
|
|
51
|
-
mainVariant: ProductVariantSchema.describe("The primary SKU for the product")
|
|
51
|
+
mainVariant: ProductVariantSchema.describe("The primary SKU for the product"),
|
|
52
|
+
variants: z.array(ProductVariantSchema).default([]).describe("A list of all SKUs for the product. Can be empty or omitted if product is single-sku")
|
|
52
53
|
}).describe("A product is a wrapper around sellable items. It contains all the shared information for a set of SKUs. All products have at least one SKU, but can potentially have hundreds.");
|
|
53
54
|
export {
|
|
54
55
|
ProductAttributeSchema,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
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<{
|
|
@@ -172,6 +172,37 @@ export declare const ProductSchema: z.ZodObject<{
|
|
|
172
172
|
}, z.core.$loose>;
|
|
173
173
|
}, z.core.$loose>>;
|
|
174
174
|
}, z.core.$loose>;
|
|
175
|
+
variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
176
|
+
identifier: z.ZodObject<{
|
|
177
|
+
sku: z.ZodString;
|
|
178
|
+
}, z.core.$loose>;
|
|
179
|
+
name: z.ZodString;
|
|
180
|
+
images: z.ZodArray<z.ZodObject<{
|
|
181
|
+
sourceUrl: z.ZodDefault<z.ZodString>;
|
|
182
|
+
altText: z.ZodDefault<z.ZodString>;
|
|
183
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
184
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
185
|
+
}, z.core.$loose>>;
|
|
186
|
+
ean: z.ZodString;
|
|
187
|
+
gtin: z.ZodString;
|
|
188
|
+
upc: z.ZodString;
|
|
189
|
+
barcode: z.ZodString;
|
|
190
|
+
options: z.ZodArray<z.ZodObject<{
|
|
191
|
+
identifier: z.ZodObject<{
|
|
192
|
+
key: z.ZodString;
|
|
193
|
+
}, z.core.$loose>;
|
|
194
|
+
name: z.ZodString;
|
|
195
|
+
value: z.ZodObject<{
|
|
196
|
+
identifier: z.ZodObject<{
|
|
197
|
+
option: z.ZodObject<{
|
|
198
|
+
key: z.ZodString;
|
|
199
|
+
}, z.core.$loose>;
|
|
200
|
+
key: z.ZodString;
|
|
201
|
+
}, z.core.$loose>;
|
|
202
|
+
label: z.ZodString;
|
|
203
|
+
}, z.core.$loose>;
|
|
204
|
+
}, z.core.$loose>>;
|
|
205
|
+
}, z.core.$loose>>>;
|
|
175
206
|
}, z.core.$loose>;
|
|
176
207
|
export type ProductVariant = InferType<typeof ProductVariantSchema>;
|
|
177
208
|
export type Product = InferType<typeof ProductSchema>;
|
|
@@ -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
|
|
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>;
|