@reactionary/core 0.3.13 → 0.3.15

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.3.13",
3
+ "version": "0.3.15",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
@@ -20,3 +20,4 @@ export * from "./checkout.model.js";
20
20
  export * from "./payment.model.js";
21
21
  export * from "./order-search.model.js";
22
22
  export * from "./product-recommendations.model.js";
23
+ export * from "./product-associations.model.js";
@@ -2,24 +2,24 @@ import * as z from "zod";
2
2
  import { ProductIdentifierSchema, ProductAssociationsIdentifierSchema, ProductVariantIdentifierSchema } from "./identifiers.model.js";
3
3
  import { ProductSearchResultItemSchema } from "./product-search.model.js";
4
4
  import { BaseModelSchema } from "./base.model.js";
5
- const BaseProductAssociationsSchema = BaseModelSchema.extend({
5
+ const BaseProductAssociationSchema = BaseModelSchema.extend({
6
6
  associationIdentifier: ProductAssociationsIdentifierSchema.meta({ description: "The identifier for the product recommendation, which includes a key and an algorithm and any other vendor specific/instance specific data " })
7
7
  });
8
- const ProductAssociationsIdOnlySchema = BaseProductAssociationsSchema.extend({
8
+ const ProductAssociationIdOnlySchema = BaseProductAssociationSchema.extend({
9
9
  associationReturnType: z.literal("idOnly").meta({ description: "The type of recommendation return" }),
10
10
  product: ProductIdentifierSchema.meta({ description: "The identifier for the recommended product." })
11
11
  });
12
- const ProductAssociationsProductSearchResultItemSchema = BaseProductAssociationsSchema.extend({
12
+ const ProductAssociationProductSearchResultItemSchema = BaseProductAssociationSchema.extend({
13
13
  associationReturnType: z.literal("productSearchResultItem").meta({ description: "The type of recommendation return" }),
14
14
  product: ProductSearchResultItemSchema.meta({ description: "The recommended product, including its identifier, name, slug, and variants. This can be used to display the recommended product directly on the frontend without needing to make an additional request to fetch the product details." })
15
15
  });
16
- const ProductAssociationsSchema = z.discriminatedUnion("associationReturnType", [
17
- ProductAssociationsIdOnlySchema,
18
- ProductAssociationsProductSearchResultItemSchema
16
+ const ProductAssociationSchema = z.discriminatedUnion("associationReturnType", [
17
+ ProductAssociationIdOnlySchema,
18
+ ProductAssociationProductSearchResultItemSchema
19
19
  ]);
20
20
  export {
21
- BaseProductAssociationsSchema,
22
- ProductAssociationsIdOnlySchema,
23
- ProductAssociationsProductSearchResultItemSchema,
24
- ProductAssociationsSchema
21
+ BaseProductAssociationSchema,
22
+ ProductAssociationIdOnlySchema,
23
+ ProductAssociationProductSearchResultItemSchema,
24
+ ProductAssociationSchema
25
25
  };
@@ -3,14 +3,16 @@ import { BaseQuerySchema } from "./base.query.js";
3
3
  import { ProductIdentifierSchema, ProductVariantIdentifierSchema } from "../models/identifiers.model.js";
4
4
  import { CartItemSchema } from "../models/cart.model.js";
5
5
  const ProductAssociationsGetAccessoriesQuerySchema = BaseQuerySchema.extend({
6
- forProductVariant: ProductVariantIdentifierSchema.describe("The product variant identifier for which to get accessory recommendations. The provider should return recommendations that are relevant to this product, e.g., products that are frequently bought together, products that are similar in style or category, or products that are popular among users with similar preferences."),
6
+ forProduct: ProductIdentifierSchema.describe("The product identifier for which to get accessory recommendations. The provider should return recommendations that are relevant to this product, e.g., products that are frequently bought together, products that are similar in style or category, or products that are popular among users with similar preferences."),
7
7
  numberOfAccessories: z.number().min(1).max(12).meta({ description: "The number of accessory recommendations requested. The provider may return fewer than this number, but should not return more." })
8
8
  });
9
9
  const ProductAssociationsGetSparepartsQuerySchema = BaseQuerySchema.extend({
10
- forProductVariant: ProductVariantIdentifierSchema.describe("The product variant identifier for which to get similar item recommendations. The provider should return recommendations that are relevant to this product, e.g., products that are frequently bought together, products that are similar in style or category, or products that are popular among users with similar preferences.")
10
+ forProduct: ProductIdentifierSchema.describe("The product identifier for which to get similar item recommendations. The provider should return recommendations that are relevant to this product, e.g., products that are frequently bought together, products that are similar in style or category, or products that are popular among users with similar preferences."),
11
+ numberOfSpareparts: z.number().min(1).max(12).meta({ description: "The number of spare part recommendations requested. The provider may return fewer than this number, but should not return more." })
11
12
  });
12
13
  const ProductAssociationsGetReplacementsQuerySchema = BaseQuerySchema.extend({
13
- forProductVariant: ProductVariantIdentifierSchema.describe("The product variant identifier for which to get replacement recommendations. The provider should return recommendations that are relevant to this product, e.g., products that are frequently bought together, products that are similar in style or category, or products that are popular among users with similar preferences.")
14
+ forProduct: ProductIdentifierSchema.describe("The product identifier for which to get replacement recommendations. The provider should return recommendations that are relevant to this product, e.g., products that are frequently bought together, products that are similar in style or category, or products that are popular among users with similar preferences."),
15
+ numberOfReplacements: z.number().min(1).max(12).meta({ description: "The number of replacement recommendations requested. The provider may return fewer than this number, but should not return more." })
14
16
  });
15
17
  export {
16
18
  ProductAssociationsGetAccessoriesQuerySchema,
@@ -1,6 +1,7 @@
1
- import type { ProductVariantIdentifier } from "../schemas/index.js";
2
1
  import type { ProductAssociationsGetAccessoriesQuery, ProductAssociationsGetSparepartsQuery, ProductAssociationsGetReplacementsQuery } from "../schemas/queries/product-associations.query.js";
3
2
  import { BaseProvider } from "./base.provider.js";
3
+ import type { Result } from '../schemas/result.js';
4
+ import type { ProductAssociation } from '../schemas/models/product-associations.model.js';
4
5
  /**
5
6
  * The product association provider is responsible for providing evidence based associations between products, such as
6
7
  * accessories, spareparts, and replacements. These associations are typically used to provide recommendations to customers on the product detail page, but can also be used in other contexts such as the cart or post-purchase, but
@@ -16,20 +17,26 @@ export declare abstract class ProductAssociationsProvider extends BaseProvider {
16
17
  *
17
18
  * Usecase:
18
19
  * - PDP: Accessories for this product
20
+ *
21
+ * TODO: This should be a PaginatedResult
19
22
  */
20
- abstract getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<ProductVariantIdentifier[]>;
23
+ abstract getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<ProductAssociation[]>>;
21
24
  /**
22
25
  * Returns a list of product identifiers which are spareparts to the given product.
23
26
  * Spareparts are products which are necessary for the use of the main product, but are not typically purchased alongside it. Examples of spareparts include:
24
27
  *
25
28
  * Usecase:
26
- * - PDP: Accessories for this product
29
+ * - PDP: Spareparts for this product
30
+ *
31
+ * TODO: This should be a PaginatedResult
27
32
  */
28
- abstract getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<ProductVariantIdentifier[]>;
33
+ abstract getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<ProductAssociation[]>>;
29
34
  /**
30
35
  * This product is replaced by these equivalent or newer products
36
+ *
37
+ * TODO: This should be a PaginatedResult
31
38
  * @param query
32
39
  */
33
- abstract getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<ProductVariantIdentifier[]>;
40
+ abstract getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<ProductAssociation[]>>;
34
41
  getResourceName(): string;
35
42
  }
@@ -20,3 +20,4 @@ export * from './checkout.model.js';
20
20
  export * from './payment.model.js';
21
21
  export * from './order-search.model.js';
22
22
  export * from './product-recommendations.model.js';
23
+ export * from './product-associations.model.js';
@@ -1,11 +1,11 @@
1
1
  import * as z from "zod";
2
2
  import type { InferType } from "../../zod-utils.js";
3
- export declare const BaseProductAssociationsSchema: z.ZodObject<{
3
+ export declare const BaseProductAssociationSchema: z.ZodObject<{
4
4
  associationIdentifier: z.ZodObject<{
5
5
  key: z.ZodString;
6
6
  }, z.core.$loose>;
7
7
  }, z.core.$loose>;
8
- export declare const ProductAssociationsIdOnlySchema: z.ZodObject<{
8
+ export declare const ProductAssociationIdOnlySchema: z.ZodObject<{
9
9
  associationIdentifier: z.ZodObject<{
10
10
  key: z.ZodString;
11
11
  }, z.core.$loose>;
@@ -14,7 +14,7 @@ export declare const ProductAssociationsIdOnlySchema: z.ZodObject<{
14
14
  key: z.ZodString;
15
15
  }, z.core.$loose>;
16
16
  }, z.core.$loose>;
17
- export declare const ProductAssociationsProductSearchResultItemSchema: z.ZodObject<{
17
+ export declare const ProductAssociationProductSearchResultItemSchema: z.ZodObject<{
18
18
  associationIdentifier: z.ZodObject<{
19
19
  key: z.ZodString;
20
20
  }, z.core.$loose>;
@@ -53,7 +53,7 @@ export declare const ProductAssociationsProductSearchResultItemSchema: z.ZodObje
53
53
  }, z.core.$loose>>;
54
54
  }, z.core.$loose>;
55
55
  }, z.core.$loose>;
56
- export declare const ProductAssociationsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
56
+ export declare const ProductAssociationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
57
57
  associationIdentifier: z.ZodObject<{
58
58
  key: z.ZodString;
59
59
  }, z.core.$loose>;
@@ -100,6 +100,6 @@ export declare const ProductAssociationsSchema: z.ZodDiscriminatedUnion<[z.ZodOb
100
100
  }, z.core.$loose>>;
101
101
  }, z.core.$loose>;
102
102
  }, z.core.$loose>], "associationReturnType">;
103
- export type ProductAssociationsIdOnly = InferType<typeof ProductAssociationsIdOnlySchema>;
104
- export type ProductAssociationsSearchItem = InferType<typeof ProductAssociationsProductSearchResultItemSchema>;
105
- export type ProductAssociations = InferType<typeof ProductAssociationsSchema>;
103
+ export type ProductAssociationIdOnly = InferType<typeof ProductAssociationIdOnlySchema>;
104
+ export type ProductAssociationSearchItem = InferType<typeof ProductAssociationProductSearchResultItemSchema>;
105
+ export type ProductAssociation = InferType<typeof ProductAssociationSchema>;
@@ -1,19 +1,21 @@
1
1
  import * as z from "zod";
2
2
  export declare const ProductAssociationsGetAccessoriesQuerySchema: z.ZodObject<{
3
- forProductVariant: z.ZodObject<{
4
- sku: z.ZodString;
3
+ forProduct: z.ZodObject<{
4
+ key: z.ZodString;
5
5
  }, z.core.$loose>;
6
6
  numberOfAccessories: z.ZodNumber;
7
7
  }, z.core.$loose>;
8
8
  export declare const ProductAssociationsGetSparepartsQuerySchema: z.ZodObject<{
9
- forProductVariant: z.ZodObject<{
10
- sku: z.ZodString;
9
+ forProduct: z.ZodObject<{
10
+ key: z.ZodString;
11
11
  }, z.core.$loose>;
12
+ numberOfSpareparts: z.ZodNumber;
12
13
  }, z.core.$loose>;
13
14
  export declare const ProductAssociationsGetReplacementsQuerySchema: z.ZodObject<{
14
- forProductVariant: z.ZodObject<{
15
- sku: z.ZodString;
15
+ forProduct: z.ZodObject<{
16
+ key: z.ZodString;
16
17
  }, z.core.$loose>;
18
+ numberOfReplacements: z.ZodNumber;
17
19
  }, z.core.$loose>;
18
20
  export type ProductAssociationsGetAccessoriesQuery = z.infer<typeof ProductAssociationsGetAccessoriesQuerySchema>;
19
21
  export type ProductAssociationsGetSparepartsQuery = z.infer<typeof ProductAssociationsGetSparepartsQuerySchema>;