@reactionary/core 0.6.1 → 0.6.3

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.
Files changed (92) hide show
  1. package/cache/memory-cache.js +2 -4
  2. package/cache/noop-cache.js +1 -3
  3. package/cache/redis-cache.js +2 -1
  4. package/{providers/analytics.provider.js → capabilities/analytics.capability.js} +11 -10
  5. package/{providers/base.provider.js → capabilities/base.capability.js} +4 -2
  6. package/capabilities/cart.capability.js +9 -0
  7. package/capabilities/category.capability.js +9 -0
  8. package/capabilities/checkout.capability.js +9 -0
  9. package/{providers/identity.provider.js → capabilities/identity.capability.js} +3 -3
  10. package/capabilities/index.js +18 -0
  11. package/{providers/inventory.provider.js → capabilities/inventory.capability.js} +3 -3
  12. package/capabilities/order-search.capability.js +9 -0
  13. package/{providers/order.provider.js → capabilities/order.capability.js} +3 -3
  14. package/{providers/price.provider.js → capabilities/price.capability.js} +3 -3
  15. package/capabilities/product-associations.capability.js +9 -0
  16. package/capabilities/product-list.capability.js +10 -0
  17. package/{providers/product-recommendations.provider.js → capabilities/product-recommendations.capability.js} +23 -22
  18. package/{providers/product-reviews.provider.js → capabilities/product-reviews.capability.js} +3 -3
  19. package/capabilities/product-search.capability.js +15 -0
  20. package/{providers/product.provider.js → capabilities/product.capability.js} +3 -3
  21. package/capabilities/profile.capability.js +9 -0
  22. package/capabilities/store.capability.js +9 -0
  23. package/client/client-builder.js +47 -15
  24. package/decorators/reactionary.decorator.js +30 -32
  25. package/factories/cart.factory.js +0 -0
  26. package/factories/category.factory.js +0 -0
  27. package/factories/checkout.factory.js +0 -0
  28. package/factories/identity.factory.js +0 -0
  29. package/factories/index.js +15 -0
  30. package/factories/inventory.factory.js +0 -0
  31. package/factories/order-search.factory.js +0 -0
  32. package/factories/order.factory.js +0 -0
  33. package/factories/price.factory.js +0 -0
  34. package/factories/product-associations.factory.js +0 -0
  35. package/factories/product-list.factory.js +0 -0
  36. package/factories/product-reviews.factory.js +0 -0
  37. package/factories/product-search.factory.js +0 -0
  38. package/factories/product.factory.js +0 -0
  39. package/factories/profile.factory.js +0 -0
  40. package/factories/store.factory.js +0 -0
  41. package/index.js +2 -1
  42. package/package.json +8 -8
  43. package/src/{providers/analytics.provider.d.ts → capabilities/analytics.capability.d.ts} +5 -5
  44. package/src/{providers/base.provider.d.ts → capabilities/base.capability.d.ts} +2 -2
  45. package/src/{providers/cart.provider.d.ts → capabilities/cart.capability.d.ts} +10 -10
  46. package/src/{providers/category.provider.d.ts → capabilities/category.capability.d.ts} +9 -9
  47. package/src/{providers/checkout.provider.d.ts → capabilities/checkout.capability.d.ts} +11 -11
  48. package/src/{providers/identity.provider.d.ts → capabilities/identity.capability.d.ts} +7 -7
  49. package/src/capabilities/index.d.ts +18 -0
  50. package/src/{providers/inventory.provider.d.ts → capabilities/inventory.capability.d.ts} +4 -4
  51. package/src/{providers/order-search.provider.d.ts → capabilities/order-search.capability.d.ts} +3 -3
  52. package/src/{providers/order.provider.d.ts → capabilities/order.capability.d.ts} +4 -4
  53. package/src/{providers/price.provider.d.ts → capabilities/price.capability.d.ts} +5 -5
  54. package/src/{providers/product-associations.provider.d.ts → capabilities/product-associations.capability.d.ts} +5 -5
  55. package/src/{providers/product-list.provider.d.ts → capabilities/product-list.capability.d.ts} +9 -9
  56. package/src/{providers/product-recommendations.provider.d.ts → capabilities/product-recommendations.capability.d.ts} +6 -6
  57. package/src/{providers/product-reviews.provider.d.ts → capabilities/product-reviews.capability.d.ts} +5 -5
  58. package/src/{providers/product-search.provider.d.ts → capabilities/product-search.capability.d.ts} +5 -28
  59. package/src/{providers/product.provider.d.ts → capabilities/product.capability.d.ts} +6 -6
  60. package/src/{providers/profile.provider.d.ts → capabilities/profile.capability.d.ts} +9 -9
  61. package/src/{providers/store.provider.d.ts → capabilities/store.capability.d.ts} +3 -3
  62. package/src/client/client-builder.d.ts +10 -1
  63. package/src/client/client.d.ts +29 -29
  64. package/src/decorators/reactionary.decorator.d.ts +5 -5
  65. package/src/factories/cart.factory.d.ts +18 -0
  66. package/src/factories/category.factory.d.ts +17 -0
  67. package/src/factories/checkout.factory.d.ts +24 -0
  68. package/src/factories/identity.factory.d.ts +12 -0
  69. package/src/factories/index.d.ts +15 -0
  70. package/src/factories/inventory.factory.d.ts +12 -0
  71. package/src/factories/order-search.factory.d.ts +13 -0
  72. package/src/factories/order.factory.d.ts +12 -0
  73. package/src/factories/price.factory.d.ts +16 -0
  74. package/src/factories/product-associations.factory.d.ts +12 -0
  75. package/src/factories/product-list.factory.d.ts +27 -0
  76. package/src/factories/product-reviews.factory.d.ts +22 -0
  77. package/src/factories/product-search.factory.d.ts +13 -0
  78. package/src/factories/product.factory.d.ts +12 -0
  79. package/src/factories/profile.factory.d.ts +12 -0
  80. package/src/factories/store.factory.d.ts +12 -0
  81. package/src/index.d.ts +3 -1
  82. package/providers/cart.provider.js +0 -9
  83. package/providers/category.provider.js +0 -9
  84. package/providers/checkout.provider.js +0 -9
  85. package/providers/index.js +0 -18
  86. package/providers/order-search.provider.js +0 -9
  87. package/providers/product-associations.provider.js +0 -9
  88. package/providers/product-list.provider.js +0 -10
  89. package/providers/product-search.provider.js +0 -9
  90. package/providers/profile.provider.js +0 -9
  91. package/providers/store.provider.js +0 -9
  92. package/src/providers/index.d.ts +0 -18
@@ -1,10 +1,10 @@
1
- import type { FacetIdentifier, FacetValueIdentifier, Result } from '../index.js';
2
- import type { ProductSearchResult, ProductSearchResultFacet, ProductSearchResultFacetValue, ProductSearchResultItemVariant } from '../schemas/models/product-search.model.js';
1
+ import type { FacetValueIdentifier, Result } from '../index.js';
2
+ import type { ProductSearchResult } from '../schemas/models/product-search.model.js';
3
3
  import type { ProductSearchQueryByTerm, ProductSearchQueryCreateNavigationFilter } from '../schemas/queries/product-search.query.js';
4
- import { BaseProvider } from './base.provider.js';
5
- export declare abstract class ProductSearchProvider extends BaseProvider {
4
+ import { BaseCapability } from './base.capability.js';
5
+ export declare abstract class ProductSearchCapability<TProductSearchResult extends ProductSearchResult = ProductSearchResult> extends BaseCapability {
6
6
  protected getResourceName(): string;
7
- abstract queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchResult>>;
7
+ abstract queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<TProductSearchResult>>;
8
8
  /**
9
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
10
  * category breadcrumb path to a global category navigation filter that can be applied to product searches.
@@ -24,27 +24,4 @@ export declare abstract class ProductSearchProvider extends BaseProvider {
24
24
  * @param categoryPath
25
25
  */
26
26
  abstract createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>>;
27
- /**
28
- * Parses a facet value from the search response.
29
- * @param facetValueIdentifier The identifier for the facet value.
30
- * @param label The label for the facet value.
31
- * @param count The count for the facet value.
32
- */
33
- protected abstract parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number): ProductSearchResultFacetValue;
34
- /**
35
- * Parses a facet from the search response.
36
- * @param facetIdentifier The identifier for the facet.
37
- * @param facetValue The value for the facet.
38
- *
39
- * Usecase: Override this to customize the parsing of facets.
40
- */
41
- protected abstract parseFacet(facetIdentifier: FacetIdentifier, facetValue: unknown): ProductSearchResultFacet;
42
- /**
43
- * Parses a product variant from the search response.
44
- * @param variant The variant data from the search response.
45
- * @param product The product data from the search response.
46
- *
47
- * Usecase: Override this to customize the parsing of product variants.
48
- */
49
- protected abstract parseVariant(variant: unknown, product: unknown): ProductSearchResultItemVariant;
50
27
  }
@@ -1,9 +1,9 @@
1
1
  import type { Product } from '../schemas/models/product.model.js';
2
- import { BaseProvider } from './base.provider.js';
2
+ import { BaseCapability } from './base.capability.js';
3
3
  import type { ProductQueryById, ProductQueryBySKU, ProductQueryBySlug } from '../schemas/queries/product.query.js';
4
4
  import type { Result } from '../schemas/result.js';
5
5
  import type { NotFoundError } from '../schemas/index.js';
6
- export declare abstract class ProductProvider extends BaseProvider {
6
+ export declare abstract class ProductCapability<TProduct extends Product = Product> extends BaseCapability {
7
7
  /**
8
8
  * Get a product by its ID.
9
9
  * @param payload The query payload containing the product ID.
@@ -14,7 +14,7 @@ export declare abstract class ProductProvider extends BaseProvider {
14
14
  * Marketing will TYPICALLY recommend products, and in some cases maybe HeroVariants of a product.
15
15
  * In that case, you would need to resolve the product to its hero variant first, and then get the SKU from there.
16
16
  */
17
- abstract getById(payload: ProductQueryById): Promise<Result<Product>>;
17
+ abstract getById(payload: ProductQueryById): Promise<Result<TProduct>>;
18
18
  /**
19
19
  * Get a product by its slug.
20
20
  * @param payload The query payload containing the product slug.
@@ -22,7 +22,7 @@ export declare abstract class ProductProvider extends BaseProvider {
22
22
  *
23
23
  * Usecase: You are rendering a product detail page, and you need to fetch the product by its slug.
24
24
  */
25
- abstract getBySlug(payload: ProductQueryBySlug): Promise<Result<Product, NotFoundError>>;
25
+ abstract getBySlug(payload: ProductQueryBySlug): Promise<Result<TProduct, NotFoundError>>;
26
26
  /**
27
27
  * Get a product by its SKU
28
28
  * @param payload
@@ -32,8 +32,8 @@ export declare abstract class ProductProvider extends BaseProvider {
32
32
  * and you need to fetch the product details for that SKU. You will get the a Product back, with the variant matching the SKU set as heroSku.
33
33
  * It might also be used on a quick-order page, or product recommendations from external system.
34
34
  */
35
- abstract getBySKU(payload: ProductQueryBySKU): Promise<Result<Product>>;
36
- protected createEmptyProduct(id: string): Product;
35
+ abstract getBySKU(payload: ProductQueryBySKU): Promise<Result<TProduct>>;
36
+ protected createEmptyProduct(id: string): TProduct;
37
37
  /**
38
38
  * The resource name, used for caching and logging.
39
39
  * @returns
@@ -3,15 +3,15 @@ import type { Profile } from '../schemas/models/index.js';
3
3
  import type { ProfileMutationAddShippingAddress, ProfileMutationMakeShippingAddressDefault, ProfileMutationRemoveShippingAddress, ProfileMutationSetBillingAddress, ProfileMutationUpdate, ProfileMutationUpdateShippingAddress } from '../schemas/mutations/index.js';
4
4
  import type { ProfileQuerySelf as ProfileQueryById } from '../schemas/queries/index.js';
5
5
  import type { Result } from '../schemas/result.js';
6
- import { BaseProvider } from './base.provider.js';
7
- export declare abstract class ProfileProvider extends BaseProvider {
6
+ import { BaseCapability } from './base.capability.js';
7
+ export declare abstract class ProfileCapability<TProfile extends Profile = Profile> extends BaseCapability {
8
8
  /**
9
9
  * Returns the profile of the currently authenticated (registered) user.
10
10
  *
11
11
  * Usecase: Fetch the profile of the logged-in user for display in header, or account settings.
12
12
  * @param payload
13
13
  */
14
- abstract getById(payload: ProfileQueryById): Promise<Result<Profile, NotFoundError>>;
14
+ abstract getById(payload: ProfileQueryById): Promise<Result<TProfile, NotFoundError>>;
15
15
  /**
16
16
  * Updates the base profile information of the currently authenticated (registered) user.
17
17
  *
@@ -23,7 +23,7 @@ export declare abstract class ProfileProvider extends BaseProvider {
23
23
  * Usecase: Update the user's name, email, or phone number.
24
24
  * @param payload
25
25
  */
26
- abstract update(payload: ProfileMutationUpdate): Promise<Result<Profile, NotFoundError>>;
26
+ abstract update(payload: ProfileMutationUpdate): Promise<Result<TProfile, NotFoundError>>;
27
27
  /**
28
28
  * Creates a new shipping address for the currently authenticated (registered) user.
29
29
  * Does not set it as default automatically.
@@ -32,7 +32,7 @@ export declare abstract class ProfileProvider extends BaseProvider {
32
32
  * done at checkout should be considered local to that session, unless the addressbook is empty.
33
33
  * @param payload
34
34
  */
35
- abstract addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<Profile, NotFoundError>>;
35
+ abstract addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<TProfile, NotFoundError>>;
36
36
  /**
37
37
  * Updates an existing shipping address for the currently authenticated (registered) user.
38
38
  *
@@ -40,7 +40,7 @@ export declare abstract class ProfileProvider extends BaseProvider {
40
40
  * done at checkout should be considered local to that session/order, unless the addressbook is empty.
41
41
  * @param payload
42
42
  */
43
- abstract updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<Profile, NotFoundError>>;
43
+ abstract updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<TProfile, NotFoundError>>;
44
44
  /**
45
45
  * Removes an existing shipping address for the currently authenticated (registered) user.
46
46
  *
@@ -49,14 +49,14 @@ export declare abstract class ProfileProvider extends BaseProvider {
49
49
  * Usecase: User deletes a shipping address from their profile.
50
50
  * @param payload
51
51
  */
52
- abstract removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<Profile, NotFoundError>>;
52
+ abstract removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<TProfile, NotFoundError>>;
53
53
  /**
54
54
  * Configures an existing shipping address as the default shipping address for the currently authenticated (registered) user.
55
55
  *
56
56
  * Usecase: User selects a default shipping address in their profile.
57
57
  * @param payload
58
58
  */
59
- abstract makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<Profile, NotFoundError>>;
59
+ abstract makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<TProfile, NotFoundError>>;
60
60
  /**
61
61
  * Sets the current/active billing address for the currently authenticated (registered) user.
62
62
  *
@@ -66,6 +66,6 @@ export declare abstract class ProfileProvider extends BaseProvider {
66
66
  * entity being billed, and as such it makes sense to have a single authoritative billing address.
67
67
  * @param payload
68
68
  */
69
- abstract setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<Profile, NotFoundError>>;
69
+ abstract setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<TProfile, NotFoundError>>;
70
70
  protected getResourceName(): string;
71
71
  }
@@ -1,8 +1,8 @@
1
1
  import type { Store } from '../schemas/models/store.model.js';
2
2
  import type { StoreQueryByProximity } from '../schemas/queries/index.js';
3
3
  import type { Result } from '../schemas/result.js';
4
- import { BaseProvider } from './base.provider.js';
5
- export declare abstract class StoreProvider extends BaseProvider {
6
- abstract queryByProximity(payload: StoreQueryByProximity): Promise<Result<Array<Store>>>;
4
+ import { BaseCapability } from './base.capability.js';
5
+ export declare abstract class StoreCapability<TStore extends Store = Store> extends BaseCapability {
6
+ abstract queryByProximity(payload: StoreQueryByProximity): Promise<Result<Array<TStore>>>;
7
7
  protected getResourceName(): string;
8
8
  }
@@ -1,17 +1,26 @@
1
1
  import type { Cache } from '../cache/cache.interface.js';
2
2
  import type { Client } from './client.js';
3
3
  import { type RequestContext } from '../schemas/session.schema.js';
4
- type CapabilityFactory<T> = (cache: Cache, context: RequestContext) => T;
4
+ export interface ClientBuilderFactoryArgs {
5
+ cache: Cache;
6
+ context: RequestContext;
7
+ }
8
+ export type CapabilityFactory<T> = ((cache: Cache, context: RequestContext) => T) | ((args: ClientBuilderFactoryArgs) => T);
5
9
  type MergeCapabilities<Acc, New> = Omit<Acc, keyof New> & New;
10
+ export type CapabilityCollisionStrategy = 'last-wins' | 'first-wins' | 'throw';
6
11
  export declare class ClientBuilder<TClient = Client> {
7
12
  private factories;
8
13
  private cache;
9
14
  private context;
15
+ private collisionStrategy;
10
16
  constructor(context: RequestContext);
11
17
  withCapability<TNew extends Partial<Client>>(factory: CapabilityFactory<TNew>): ClientBuilder<MergeCapabilities<TClient, TNew>>;
12
18
  withCache(cache: Cache): ClientBuilder<TClient>;
19
+ withCollisionStrategy(strategy: CapabilityCollisionStrategy): ClientBuilder<TClient>;
13
20
  build(): TClient & {
14
21
  cache: Cache;
15
22
  };
23
+ private resolveFactory;
24
+ private mergeCapabilities;
16
25
  }
17
26
  export {};
@@ -1,33 +1,33 @@
1
- import type { ProductProvider } from "../providers/product.provider.js";
2
- import type { ProductSearchProvider } from "../providers/product-search.provider.js";
3
- import type { IdentityProvider } from '../providers/identity.provider.js';
4
- import type { CartProvider } from "../providers/cart.provider.js";
5
- import type { PriceProvider } from "../providers/price.provider.js";
6
- import type { InventoryProvider } from "../providers/inventory.provider.js";
1
+ import type { ProductCapability } from "../capabilities/product.capability.js";
2
+ import type { ProductSearchCapability } from "../capabilities/product-search.capability.js";
3
+ import type { IdentityCapability } from '../capabilities/identity.capability.js';
4
+ import type { CartCapability } from "../capabilities/cart.capability.js";
5
+ import type { PriceCapability } from "../capabilities/price.capability.js";
6
+ import type { InventoryCapability } from "../capabilities/inventory.capability.js";
7
7
  import type { Cache } from "../cache/cache.interface.js";
8
- import type { CategoryProvider } from "../providers/category.provider.js";
9
- import type { AnalyticsProvider, CheckoutProvider, OrderProvider, ProductListProvider, ProfileProvider, StoreProvider } from "../providers/index.js";
10
- import type { OrderSearchProvider } from "../providers/order-search.provider.js";
11
- import type { ProductRecommendationsProvider } from "../providers/product-recommendations.provider.js";
12
- import type { ProductAssociationsProvider } from "../providers/product-associations.provider.js";
13
- import type { ProductReviewsProvider } from "../providers/product-reviews.provider.js";
8
+ import type { CategoryCapability } from "../capabilities/category.capability.js";
9
+ import type { AnalyticsCapability, CheckoutCapability, OrderCapability, ProductListCapability, ProfileCapability, StoreCapability } from "../capabilities/index.js";
10
+ import type { OrderSearchCapability } from "../capabilities/order-search.capability.js";
11
+ import type { ProductRecommendationsCapability } from "../capabilities/product-recommendations.capability.js";
12
+ import type { ProductAssociationsCapability } from "../capabilities/product-associations.capability.js";
13
+ import type { ProductReviewsCapability } from "../capabilities/product-reviews.capability.js";
14
14
  export interface Client {
15
- product: ProductProvider;
16
- productSearch: ProductSearchProvider;
17
- productRecommendations: ProductRecommendationsProvider;
18
- productAssociations: ProductAssociationsProvider;
19
- productReviews: ProductReviewsProvider;
20
- productList: ProductListProvider;
21
- identity: IdentityProvider;
15
+ product: ProductCapability;
16
+ productSearch: ProductSearchCapability;
17
+ productRecommendations: ProductRecommendationsCapability;
18
+ productAssociations: ProductAssociationsCapability;
19
+ productReviews: ProductReviewsCapability;
20
+ productList: ProductListCapability;
21
+ identity: IdentityCapability;
22
22
  cache: Cache;
23
- cart: CartProvider;
24
- checkout: CheckoutProvider;
25
- analytics: AnalyticsProvider;
26
- price: PriceProvider;
27
- inventory: InventoryProvider;
28
- category: CategoryProvider;
29
- profile: ProfileProvider;
30
- store: StoreProvider;
31
- order: OrderProvider;
32
- orderSearch: OrderSearchProvider;
23
+ cart: CartCapability;
24
+ checkout: CheckoutCapability;
25
+ analytics: AnalyticsCapability;
26
+ price: PriceCapability;
27
+ inventory: InventoryCapability;
28
+ category: CategoryCapability;
29
+ profile: ProfileCapability;
30
+ store: StoreCapability;
31
+ order: OrderCapability;
32
+ orderSearch: OrderSearchCapability;
33
33
  }
@@ -1,10 +1,10 @@
1
1
  import type { Tracer } from '@opentelemetry/api';
2
2
  import * as z from 'zod';
3
- import type { BaseProvider } from '../providers/index.js';
3
+ import type { BaseCapability } from '../capabilities/index.js';
4
4
  import { type Result } from '../schemas/result.js';
5
5
  export declare function getTracer(): Tracer;
6
6
  /**
7
- * The options associated with annotating a provider function and marking
7
+ * The options associated with annotating a capability function and marking
8
8
  * it as a reactionary entrypoint to be called
9
9
  */
10
10
  export declare class ReactionaryDecoratorOptions {
@@ -39,11 +39,11 @@ export declare class ReactionaryDecoratorOptions {
39
39
  outputSchema: z.ZodType;
40
40
  }
41
41
  /**
42
- * Decorator for provider functions to provide functionality such as caching, tracing and type-checked
42
+ * Decorator for capability functions to provide functionality such as caching, tracing and type-checked
43
43
  * assertion through Zod. It should only be used with publically accessible queries or mutations on
44
- * providers.
44
+ * capabilities.
45
45
  */
46
- export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseProvider, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
46
+ export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseCapability, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
47
47
  /**
48
48
  * Utility function to handle input validation.
49
49
  */
@@ -0,0 +1,18 @@
1
+ import type * as z from 'zod';
2
+ import type { CartSchema } from '../schemas/models/cart.model.js';
3
+ import type { CartIdentifierSchema } from '../schemas/models/identifiers.model.js';
4
+ import type { RequestContext } from '../schemas/session.schema.js';
5
+ export type AnyCartSchema = z.ZodType<z.output<typeof CartSchema>>;
6
+ export type AnyCartIdentifierSchema = z.ZodType<z.output<typeof CartIdentifierSchema>>;
7
+ export interface CartFactory<TCartSchema extends AnyCartSchema = AnyCartSchema, TCartIdentifierSchema extends AnyCartIdentifierSchema = AnyCartIdentifierSchema> {
8
+ cartSchema: TCartSchema;
9
+ cartIdentifierSchema: TCartIdentifierSchema;
10
+ parseCart(context: RequestContext, data: unknown): z.output<TCartSchema>;
11
+ parseCartIdentifier(context: RequestContext, data: unknown): z.output<TCartIdentifierSchema>;
12
+ }
13
+ export type CartFactoryCartOutput<TFactory extends CartFactory> = ReturnType<TFactory['parseCart']>;
14
+ export type CartFactoryIdentifierOutput<TFactory extends CartFactory> = ReturnType<TFactory['parseCartIdentifier']>;
15
+ export type CartFactoryWithOutput<TFactory extends CartFactory> = Omit<TFactory, 'parseCart' | 'parseCartIdentifier'> & {
16
+ parseCart(context: RequestContext, data: unknown): CartFactoryCartOutput<TFactory>;
17
+ parseCartIdentifier(context: RequestContext, data: unknown): CartFactoryIdentifierOutput<TFactory>;
18
+ };
@@ -0,0 +1,17 @@
1
+ import type * as z from 'zod';
2
+ import type { CategoryPaginatedResultSchema, CategorySchema } from '../schemas/models/category.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyCategorySchema = z.ZodType<z.output<typeof CategorySchema>>;
5
+ export type AnyCategoryPaginatedResultSchema = z.ZodType<z.output<typeof CategoryPaginatedResultSchema>>;
6
+ export interface CategoryFactory<TCategorySchema extends AnyCategorySchema = AnyCategorySchema, TCategoryPaginatedSchema extends AnyCategoryPaginatedResultSchema = AnyCategoryPaginatedResultSchema> {
7
+ categorySchema: TCategorySchema;
8
+ categoryPaginatedResultSchema: TCategoryPaginatedSchema;
9
+ parseCategory(context: RequestContext, data: unknown): z.output<TCategorySchema>;
10
+ parseCategoryPaginatedResult(context: RequestContext, data: unknown): z.output<TCategoryPaginatedSchema>;
11
+ }
12
+ export type CategoryFactoryCategoryOutput<TFactory extends CategoryFactory> = ReturnType<TFactory['parseCategory']>;
13
+ export type CategoryFactoryPaginatedOutput<TFactory extends CategoryFactory> = ReturnType<TFactory['parseCategoryPaginatedResult']>;
14
+ export type CategoryFactoryWithOutput<TFactory extends CategoryFactory> = Omit<TFactory, 'parseCategory' | 'parseCategoryPaginatedResult'> & {
15
+ parseCategory(context: RequestContext, data: unknown): CategoryFactoryCategoryOutput<TFactory>;
16
+ parseCategoryPaginatedResult(context: RequestContext, data: unknown): CategoryFactoryPaginatedOutput<TFactory>;
17
+ };
@@ -0,0 +1,24 @@
1
+ import type * as z from 'zod';
2
+ import type { CheckoutSchema } from '../schemas/models/checkout.model.js';
3
+ import type { PaymentMethodSchema } from '../schemas/models/payment.model.js';
4
+ import type { ShippingMethodSchema } from '../schemas/models/shipping-method.model.js';
5
+ import type { RequestContext } from '../schemas/session.schema.js';
6
+ export type AnyCheckoutSchema = z.ZodType<z.output<typeof CheckoutSchema>>;
7
+ export type AnyShippingMethodSchema = z.ZodType<z.output<typeof ShippingMethodSchema>>;
8
+ export type AnyPaymentMethodSchema = z.ZodType<z.output<typeof PaymentMethodSchema>>;
9
+ export interface CheckoutFactory<TCheckoutSchema extends AnyCheckoutSchema = AnyCheckoutSchema, TShippingMethodSchema extends AnyShippingMethodSchema = AnyShippingMethodSchema, TPaymentMethodSchema extends AnyPaymentMethodSchema = AnyPaymentMethodSchema> {
10
+ checkoutSchema: TCheckoutSchema;
11
+ shippingMethodSchema: TShippingMethodSchema;
12
+ paymentMethodSchema: TPaymentMethodSchema;
13
+ parseCheckout(context: RequestContext, data: unknown): z.output<TCheckoutSchema>;
14
+ parseShippingMethod(context: RequestContext, data: unknown): z.output<TShippingMethodSchema>;
15
+ parsePaymentMethod(context: RequestContext, data: unknown): z.output<TPaymentMethodSchema>;
16
+ }
17
+ export type CheckoutFactoryCheckoutOutput<TFactory extends CheckoutFactory> = ReturnType<TFactory['parseCheckout']>;
18
+ export type CheckoutFactoryShippingMethodOutput<TFactory extends CheckoutFactory> = ReturnType<TFactory['parseShippingMethod']>;
19
+ export type CheckoutFactoryPaymentMethodOutput<TFactory extends CheckoutFactory> = ReturnType<TFactory['parsePaymentMethod']>;
20
+ export type CheckoutFactoryWithOutput<TFactory extends CheckoutFactory> = Omit<TFactory, 'parseCheckout' | 'parseShippingMethod' | 'parsePaymentMethod'> & {
21
+ parseCheckout(context: RequestContext, data: unknown): CheckoutFactoryCheckoutOutput<TFactory>;
22
+ parseShippingMethod(context: RequestContext, data: unknown): CheckoutFactoryShippingMethodOutput<TFactory>;
23
+ parsePaymentMethod(context: RequestContext, data: unknown): CheckoutFactoryPaymentMethodOutput<TFactory>;
24
+ };
@@ -0,0 +1,12 @@
1
+ import type * as z from 'zod';
2
+ import type { IdentitySchema } from '../schemas/models/identity.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyIdentitySchema = z.ZodType<z.output<typeof IdentitySchema>>;
5
+ export interface IdentityFactory<TIdentitySchema extends AnyIdentitySchema = AnyIdentitySchema> {
6
+ identitySchema: TIdentitySchema;
7
+ parseIdentity(context: RequestContext, data: unknown): z.output<TIdentitySchema>;
8
+ }
9
+ export type IdentityFactoryOutput<TFactory extends IdentityFactory> = ReturnType<TFactory['parseIdentity']>;
10
+ export type IdentityFactoryWithOutput<TFactory extends IdentityFactory> = Omit<TFactory, 'parseIdentity'> & {
11
+ parseIdentity(context: RequestContext, data: unknown): IdentityFactoryOutput<TFactory>;
12
+ };
@@ -0,0 +1,15 @@
1
+ export * from './cart.factory.js';
2
+ export * from './category.factory.js';
3
+ export * from './checkout.factory.js';
4
+ export * from './identity.factory.js';
5
+ export * from './inventory.factory.js';
6
+ export * from './order.factory.js';
7
+ export * from './order-search.factory.js';
8
+ export * from './price.factory.js';
9
+ export * from './product.factory.js';
10
+ export * from './product-associations.factory.js';
11
+ export * from './product-list.factory.js';
12
+ export * from './product-reviews.factory.js';
13
+ export * from './product-search.factory.js';
14
+ export * from './profile.factory.js';
15
+ export * from './store.factory.js';
@@ -0,0 +1,12 @@
1
+ import type * as z from 'zod';
2
+ import type { InventorySchema } from '../schemas/models/inventory.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyInventorySchema = z.ZodType<z.output<typeof InventorySchema>>;
5
+ export interface InventoryFactory<TInventorySchema extends AnyInventorySchema = AnyInventorySchema> {
6
+ inventorySchema: TInventorySchema;
7
+ parseInventory(context: RequestContext, data: unknown): z.output<TInventorySchema>;
8
+ }
9
+ export type InventoryFactoryOutput<TFactory extends InventoryFactory> = ReturnType<TFactory['parseInventory']>;
10
+ export type InventoryFactoryWithOutput<TFactory extends InventoryFactory> = Omit<TFactory, 'parseInventory'> & {
11
+ parseInventory(context: RequestContext, data: unknown): InventoryFactoryOutput<TFactory>;
12
+ };
@@ -0,0 +1,13 @@
1
+ import type * as z from 'zod';
2
+ import type { OrderSearchResultSchema } from '../schemas/models/order-search.model.js';
3
+ import type { OrderSearchQueryByTerm } from '../schemas/queries/order-search.query.js';
4
+ import type { RequestContext } from '../schemas/session.schema.js';
5
+ export type AnyOrderSearchResultSchema = z.ZodType<z.output<typeof OrderSearchResultSchema>>;
6
+ export interface OrderSearchFactory<TOrderSearchResultSchema extends AnyOrderSearchResultSchema = AnyOrderSearchResultSchema> {
7
+ orderSearchResultSchema: TOrderSearchResultSchema;
8
+ parseOrderSearchResult(context: RequestContext, data: unknown, query: OrderSearchQueryByTerm): z.output<TOrderSearchResultSchema>;
9
+ }
10
+ export type OrderSearchFactoryOutput<TFactory extends OrderSearchFactory> = ReturnType<TFactory['parseOrderSearchResult']>;
11
+ export type OrderSearchFactoryWithOutput<TFactory extends OrderSearchFactory> = Omit<TFactory, 'parseOrderSearchResult'> & {
12
+ parseOrderSearchResult(context: RequestContext, data: unknown, query: OrderSearchQueryByTerm): OrderSearchFactoryOutput<TFactory>;
13
+ };
@@ -0,0 +1,12 @@
1
+ import type * as z from 'zod';
2
+ import type { OrderSchema } from '../schemas/models/order.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyOrderSchema = z.ZodType<z.output<typeof OrderSchema>>;
5
+ export interface OrderFactory<TOrderSchema extends AnyOrderSchema = AnyOrderSchema> {
6
+ orderSchema: TOrderSchema;
7
+ parseOrder(context: RequestContext, data: unknown): z.output<TOrderSchema>;
8
+ }
9
+ export type OrderFactoryOutput<TFactory extends OrderFactory> = ReturnType<TFactory['parseOrder']>;
10
+ export type OrderFactoryWithOutput<TFactory extends OrderFactory> = Omit<TFactory, 'parseOrder'> & {
11
+ parseOrder(context: RequestContext, data: unknown): OrderFactoryOutput<TFactory>;
12
+ };
@@ -0,0 +1,16 @@
1
+ import type * as z from 'zod';
2
+ import type { PriceSchema } from '../schemas/models/price.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyPriceSchema = z.ZodType<z.output<typeof PriceSchema>>;
5
+ export interface PriceFactory<TPriceSchema extends AnyPriceSchema = AnyPriceSchema> {
6
+ priceSchema: TPriceSchema;
7
+ parsePrice(context: RequestContext, data: unknown, options?: {
8
+ includeDiscounts: boolean;
9
+ }): z.output<TPriceSchema>;
10
+ }
11
+ export type PriceFactoryOutput<TFactory extends PriceFactory> = ReturnType<TFactory['parsePrice']>;
12
+ export type PriceFactoryWithOutput<TFactory extends PriceFactory> = Omit<TFactory, 'parsePrice'> & {
13
+ parsePrice(context: RequestContext, data: unknown, options?: {
14
+ includeDiscounts: boolean;
15
+ }): PriceFactoryOutput<TFactory>;
16
+ };
@@ -0,0 +1,12 @@
1
+ import type * as z from 'zod';
2
+ import type { ProductAssociationSchema } from '../schemas/models/product-associations.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyProductAssociationSchema = z.ZodType<z.output<typeof ProductAssociationSchema>>;
5
+ export interface ProductAssociationsFactory<TProductAssociationSchema extends AnyProductAssociationSchema = AnyProductAssociationSchema> {
6
+ productAssociationSchema: TProductAssociationSchema;
7
+ parseAssociation(context: RequestContext, data: unknown): z.output<TProductAssociationSchema>;
8
+ }
9
+ export type ProductAssociationsFactoryOutput<TFactory extends ProductAssociationsFactory> = ReturnType<TFactory['parseAssociation']>;
10
+ export type ProductAssociationsFactoryWithOutput<TFactory extends ProductAssociationsFactory> = Omit<TFactory, 'parseAssociation'> & {
11
+ parseAssociation(context: RequestContext, data: unknown): ProductAssociationsFactoryOutput<TFactory>;
12
+ };
@@ -0,0 +1,27 @@
1
+ import type * as z from 'zod';
2
+ import type { ProductListItemPaginatedResultsSchema, ProductListItemSchema, ProductListPaginatedResultsSchema, ProductListSchema } from '../schemas/models/product-list.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyProductListSchema = z.ZodType<z.output<typeof ProductListSchema>>;
5
+ export type AnyProductListItemSchema = z.ZodType<z.output<typeof ProductListItemSchema>>;
6
+ export type AnyProductListPaginatedSchema = z.ZodType<z.output<typeof ProductListPaginatedResultsSchema>>;
7
+ export type AnyProductListItemPaginatedSchema = z.ZodType<z.output<typeof ProductListItemPaginatedResultsSchema>>;
8
+ export interface ProductListFactory<TProductListSchema extends AnyProductListSchema = AnyProductListSchema, TProductListItemSchema extends AnyProductListItemSchema = AnyProductListItemSchema, TProductListPaginatedSchema extends AnyProductListPaginatedSchema = AnyProductListPaginatedSchema, TProductListItemPaginatedSchema extends AnyProductListItemPaginatedSchema = AnyProductListItemPaginatedSchema> {
9
+ productListSchema: TProductListSchema;
10
+ productListItemSchema: TProductListItemSchema;
11
+ productListPaginatedSchema: TProductListPaginatedSchema;
12
+ productListItemPaginatedSchema: TProductListItemPaginatedSchema;
13
+ parseProductList(context: RequestContext, data: unknown): z.output<TProductListSchema>;
14
+ parseProductListItem(context: RequestContext, data: unknown): z.output<TProductListItemSchema>;
15
+ parseProductListPaginatedResult(context: RequestContext, data: unknown): z.output<TProductListPaginatedSchema>;
16
+ parseProductListItemPaginatedResult(context: RequestContext, data: unknown): z.output<TProductListItemPaginatedSchema>;
17
+ }
18
+ export type ProductListFactoryListOutput<TFactory extends ProductListFactory> = ReturnType<TFactory['parseProductList']>;
19
+ export type ProductListFactoryItemOutput<TFactory extends ProductListFactory> = ReturnType<TFactory['parseProductListItem']>;
20
+ export type ProductListFactoryListPaginatedOutput<TFactory extends ProductListFactory> = ReturnType<TFactory['parseProductListPaginatedResult']>;
21
+ export type ProductListFactoryItemPaginatedOutput<TFactory extends ProductListFactory> = ReturnType<TFactory['parseProductListItemPaginatedResult']>;
22
+ export type ProductListFactoryWithOutput<TFactory extends ProductListFactory> = Omit<TFactory, 'parseProductList' | 'parseProductListItem' | 'parseProductListPaginatedResult' | 'parseProductListItemPaginatedResult'> & {
23
+ parseProductList(context: RequestContext, data: unknown): ProductListFactoryListOutput<TFactory>;
24
+ parseProductListItem(context: RequestContext, data: unknown): ProductListFactoryItemOutput<TFactory>;
25
+ parseProductListPaginatedResult(context: RequestContext, data: unknown): ProductListFactoryListPaginatedOutput<TFactory>;
26
+ parseProductListItemPaginatedResult(context: RequestContext, data: unknown): ProductListFactoryItemPaginatedOutput<TFactory>;
27
+ };
@@ -0,0 +1,22 @@
1
+ import type * as z from 'zod';
2
+ import type { ProductRatingSummarySchema, ProductReviewPaginatedResultSchema, ProductReviewSchema } from '../schemas/models/product-reviews.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyProductRatingSummarySchema = z.ZodType<z.output<typeof ProductRatingSummarySchema>>;
5
+ export type AnyProductReviewSchema = z.ZodType<z.output<typeof ProductReviewSchema>>;
6
+ export type AnyProductReviewPaginatedSchema = z.ZodType<z.output<typeof ProductReviewPaginatedResultSchema>>;
7
+ export interface ProductReviewsFactory<TRatingSummarySchema extends AnyProductRatingSummarySchema = AnyProductRatingSummarySchema, TReviewSchema extends AnyProductReviewSchema = AnyProductReviewSchema, TReviewPaginatedSchema extends AnyProductReviewPaginatedSchema = AnyProductReviewPaginatedSchema> {
8
+ ratingSummarySchema: TRatingSummarySchema;
9
+ reviewSchema: TReviewSchema;
10
+ reviewPaginatedSchema: TReviewPaginatedSchema;
11
+ parseRatingSummary(context: RequestContext, data: unknown): z.output<TRatingSummarySchema>;
12
+ parseReview(context: RequestContext, data: unknown): z.output<TReviewSchema>;
13
+ parseReviewPaginatedResult(context: RequestContext, data: unknown): z.output<TReviewPaginatedSchema>;
14
+ }
15
+ export type ProductReviewsFactoryRatingOutput<TFactory extends ProductReviewsFactory> = ReturnType<TFactory['parseRatingSummary']>;
16
+ export type ProductReviewsFactoryReviewOutput<TFactory extends ProductReviewsFactory> = ReturnType<TFactory['parseReview']>;
17
+ export type ProductReviewsFactoryReviewPaginatedOutput<TFactory extends ProductReviewsFactory> = ReturnType<TFactory['parseReviewPaginatedResult']>;
18
+ export type ProductReviewsFactoryWithOutput<TFactory extends ProductReviewsFactory> = Omit<TFactory, 'parseRatingSummary' | 'parseReview' | 'parseReviewPaginatedResult'> & {
19
+ parseRatingSummary(context: RequestContext, data: unknown): ProductReviewsFactoryRatingOutput<TFactory>;
20
+ parseReview(context: RequestContext, data: unknown): ProductReviewsFactoryReviewOutput<TFactory>;
21
+ parseReviewPaginatedResult(context: RequestContext, data: unknown): ProductReviewsFactoryReviewPaginatedOutput<TFactory>;
22
+ };
@@ -0,0 +1,13 @@
1
+ import type * as z from 'zod';
2
+ import type { ProductSearchResultSchema } from '../schemas/models/product-search.model.js';
3
+ import type { ProductSearchQueryByTerm } from '../schemas/queries/product-search.query.js';
4
+ import type { RequestContext } from '../schemas/session.schema.js';
5
+ export type AnyProductSearchResultSchema = z.ZodType<z.output<typeof ProductSearchResultSchema>>;
6
+ export interface ProductSearchFactory<TProductSearchResultSchema extends AnyProductSearchResultSchema = AnyProductSearchResultSchema> {
7
+ productSearchResultSchema: TProductSearchResultSchema;
8
+ parseSearchResult(context: RequestContext, data: unknown, query: ProductSearchQueryByTerm): z.output<TProductSearchResultSchema>;
9
+ }
10
+ export type ProductSearchFactoryOutput<TFactory extends ProductSearchFactory> = ReturnType<TFactory['parseSearchResult']>;
11
+ export type ProductSearchFactoryWithOutput<TFactory extends ProductSearchFactory> = Omit<TFactory, 'parseSearchResult'> & {
12
+ parseSearchResult(context: RequestContext, data: unknown, query: ProductSearchQueryByTerm): ProductSearchFactoryOutput<TFactory>;
13
+ };
@@ -0,0 +1,12 @@
1
+ import type * as z from 'zod';
2
+ import type { ProductSchema } from '../schemas/models/product.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyProductSchema = z.ZodType<z.output<typeof ProductSchema>>;
5
+ export interface ProductFactory<TProductSchema extends AnyProductSchema = AnyProductSchema> {
6
+ productSchema: TProductSchema;
7
+ parseProduct(context: RequestContext, data: unknown): z.output<TProductSchema>;
8
+ }
9
+ export type ProductFactoryOutput<TFactory extends ProductFactory> = ReturnType<TFactory['parseProduct']>;
10
+ export type ProductFactoryWithOutput<TFactory extends ProductFactory> = Omit<TFactory, 'parseProduct'> & {
11
+ parseProduct(context: RequestContext, data: unknown): ProductFactoryOutput<TFactory>;
12
+ };
@@ -0,0 +1,12 @@
1
+ import type * as z from 'zod';
2
+ import type { ProfileSchema } from '../schemas/models/profile.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyProfileSchema = z.ZodType<z.output<typeof ProfileSchema>>;
5
+ export interface ProfileFactory<TProfileSchema extends AnyProfileSchema = AnyProfileSchema> {
6
+ profileSchema: TProfileSchema;
7
+ parseProfile(context: RequestContext, data: unknown): z.output<TProfileSchema>;
8
+ }
9
+ export type ProfileFactoryOutput<TFactory extends ProfileFactory> = ReturnType<TFactory['parseProfile']>;
10
+ export type ProfileFactoryWithOutput<TFactory extends ProfileFactory> = Omit<TFactory, 'parseProfile'> & {
11
+ parseProfile(context: RequestContext, data: unknown): ProfileFactoryOutput<TFactory>;
12
+ };
@@ -0,0 +1,12 @@
1
+ import type * as z from 'zod';
2
+ import type { StoreSchema } from '../schemas/models/store.model.js';
3
+ import type { RequestContext } from '../schemas/session.schema.js';
4
+ export type AnyStoreSchema = z.ZodType<z.output<typeof StoreSchema>>;
5
+ export interface StoreFactory<TStoreSchema extends AnyStoreSchema = AnyStoreSchema> {
6
+ storeSchema: TStoreSchema;
7
+ parseStore(context: RequestContext, data: unknown): z.output<TStoreSchema>;
8
+ }
9
+ export type StoreFactoryOutput<TFactory extends StoreFactory> = ReturnType<TFactory['parseStore']>;
10
+ export type StoreFactoryWithOutput<TFactory extends StoreFactory> = Omit<TFactory, 'parseStore'> & {
11
+ parseStore(context: RequestContext, data: unknown): StoreFactoryOutput<TFactory>;
12
+ };
package/src/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './cache/index.js';
2
2
  export * from './client/index.js';
3
3
  export * from './decorators/index.js';
4
- export * from './providers/index.js';
4
+ export * from './factories/index.js';
5
+ export * from './capabilities/index.js';
5
6
  export * from './schemas/index.js';
6
7
  export * from './initialization.js';
8
+ export type { InferType } from './zod-utils.js';
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class CartProvider extends BaseProvider {
3
- getResourceName() {
4
- return "cart";
5
- }
6
- }
7
- export {
8
- CartProvider
9
- };
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class CategoryProvider extends BaseProvider {
3
- getResourceName() {
4
- return "category";
5
- }
6
- }
7
- export {
8
- CategoryProvider
9
- };
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class CheckoutProvider extends BaseProvider {
3
- getResourceName() {
4
- return "checkout";
5
- }
6
- }
7
- export {
8
- CheckoutProvider
9
- };