@reactionary/fake 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.
- package/README.md +11 -0
- package/capabilities/analytics.capability.js +15 -0
- package/capabilities/cart.capability.js +261 -0
- package/capabilities/category.capability.js +160 -0
- package/capabilities/checkout.capability.js +231 -0
- package/capabilities/identity.capability.js +89 -0
- package/capabilities/index.js +15 -0
- package/capabilities/inventory.capability.js +59 -0
- package/capabilities/order-search.capability.js +74 -0
- package/capabilities/order.capability.js +81 -0
- package/capabilities/price.capability.js +99 -0
- package/capabilities/product-associations.capability.js +121 -0
- package/capabilities/product-reviews.capability.js +154 -0
- package/capabilities/product-search.capability.js +145 -0
- package/capabilities/product.capability.js +99 -0
- package/capabilities/profile.capability.js +130 -0
- package/capabilities/store.capability.js +59 -0
- package/core/initialize.js +235 -0
- package/core/initialize.types.js +8 -0
- package/factories/cart/cart.factory.js +17 -0
- package/factories/category/category.factory.js +17 -0
- package/factories/checkout/checkout.factory.js +22 -0
- package/factories/identity/identity.factory.js +12 -0
- package/factories/index.js +14 -0
- package/factories/inventory/inventory.factory.js +12 -0
- package/factories/order/order.factory.js +12 -0
- package/factories/order-search/order-search.factory.js +12 -0
- package/factories/price/price.factory.js +12 -0
- package/factories/product/product.factory.js +12 -0
- package/factories/product-associations/product-associations.factory.js +12 -0
- package/factories/product-reviews/product-reviews.factory.js +22 -0
- package/factories/product-search/product-search.factory.js +12 -0
- package/factories/profile/profile.factory.js +12 -0
- package/factories/store/store.factory.js +12 -0
- package/index.js +6 -0
- package/package.json +15 -0
- package/schema/capabilities.schema.js +41 -0
- package/schema/configuration.schema.js +18 -0
- package/src/capabilities/analytics.capability.d.ts +8 -0
- package/src/capabilities/cart.capability.d.ts +22 -0
- package/src/capabilities/category.capability.d.ts +20 -0
- package/src/capabilities/checkout.capability.d.ts +56 -0
- package/src/capabilities/identity.capability.d.ts +13 -0
- package/src/capabilities/index.d.ts +15 -0
- package/src/capabilities/inventory.capability.d.ts +10 -0
- package/src/capabilities/order-search.capability.d.ts +11 -0
- package/src/capabilities/order.capability.d.ts +11 -0
- package/src/capabilities/price.capability.d.ts +13 -0
- package/src/capabilities/product-associations.capability.d.ts +15 -0
- package/src/capabilities/product-reviews.capability.d.ts +13 -0
- package/src/capabilities/product-search.capability.d.ts +10 -0
- package/src/capabilities/product.capability.d.ts +12 -0
- package/src/capabilities/profile.capability.d.ts +18 -0
- package/src/capabilities/store.capability.d.ts +10 -0
- package/src/core/initialize.d.ts +5 -0
- package/src/core/initialize.types.d.ts +113 -0
- package/src/factories/cart/cart.factory.d.ts +9 -0
- package/src/factories/category/category.factory.d.ts +9 -0
- package/src/factories/checkout/checkout.factory.d.ts +11 -0
- package/src/factories/identity/identity.factory.d.ts +7 -0
- package/src/factories/index.d.ts +14 -0
- package/src/factories/inventory/inventory.factory.d.ts +7 -0
- package/src/factories/order/order.factory.d.ts +7 -0
- package/src/factories/order-search/order-search.factory.d.ts +7 -0
- package/src/factories/price/price.factory.d.ts +9 -0
- package/src/factories/product/product.factory.d.ts +7 -0
- package/src/factories/product-associations/product-associations.factory.d.ts +7 -0
- package/src/factories/product-reviews/product-reviews.factory.d.ts +11 -0
- package/src/factories/product-search/product-search.factory.d.ts +7 -0
- package/src/factories/profile/profile.factory.d.ts +7 -0
- package/src/factories/store/store.factory.d.ts +7 -0
- package/src/index.d.ts +6 -0
- package/src/schema/capabilities.schema.d.ts +117 -0
- package/src/schema/configuration.schema.d.ts +13 -0
- package/src/test/client-builder-product-extension.example.d.ts +1 -0
- package/src/test/test-utils.d.ts +2 -0
- package/src/utilities/jitter.d.ts +1 -0
- package/src/utilities/seed.d.ts +1 -0
- package/test/client-builder-product-extension.example.js +57 -0
- package/test/test-utils.js +16 -0
- package/utilities/jitter.js +13 -0
- package/utilities/seed.js +11 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { CartFactory, CategoryFactory, CheckoutFactory, ClientFromCapabilities, IdentityFactory, InventoryFactory, OrderFactory, OrderSearchFactory, PriceFactory, ProductAssociationsFactory, ProductFactory, ProductReviewsFactory, ProductSearchFactory, ProfileFactory, StoreFactory } from '@reactionary/core';
|
|
2
|
+
import type { FakeCapabilities } from '../schema/capabilities.schema.js';
|
|
3
|
+
import type { FakeCartFactory } from '../factories/cart/cart.factory.js';
|
|
4
|
+
import type { FakeCategoryFactory } from '../factories/category/category.factory.js';
|
|
5
|
+
import type { FakeCheckoutFactory } from '../factories/checkout/checkout.factory.js';
|
|
6
|
+
import type { FakeIdentityFactory } from '../factories/identity/identity.factory.js';
|
|
7
|
+
import type { FakeInventoryFactory } from '../factories/inventory/inventory.factory.js';
|
|
8
|
+
import type { FakeOrderFactory } from '../factories/order/order.factory.js';
|
|
9
|
+
import type { FakeOrderSearchFactory } from '../factories/order-search/order-search.factory.js';
|
|
10
|
+
import type { FakePriceFactory } from '../factories/price/price.factory.js';
|
|
11
|
+
import type { FakeProductAssociationsFactory } from '../factories/product-associations/product-associations.factory.js';
|
|
12
|
+
import type { FakeProductFactory } from '../factories/product/product.factory.js';
|
|
13
|
+
import type { FakeProductReviewsFactory } from '../factories/product-reviews/product-reviews.factory.js';
|
|
14
|
+
import type { FakeProductSearchFactory } from '../factories/product-search/product-search.factory.js';
|
|
15
|
+
import type { FakeProfileFactory } from '../factories/profile/profile.factory.js';
|
|
16
|
+
import type { FakeStoreFactory } from '../factories/store/store.factory.js';
|
|
17
|
+
import type { FakeCartCapability } from '../capabilities/cart.capability.js';
|
|
18
|
+
import type { FakeCategoryCapability } from '../capabilities/category.capability.js';
|
|
19
|
+
import type { FakeCheckoutCapability } from '../capabilities/checkout.capability.js';
|
|
20
|
+
import type { FakeIdentityCapability } from '../capabilities/identity.capability.js';
|
|
21
|
+
import type { FakeInventoryCapability } from '../capabilities/inventory.capability.js';
|
|
22
|
+
import type { FakeOrderCapability } from '../capabilities/order.capability.js';
|
|
23
|
+
import type { FakeOrderSearchCapability } from '../capabilities/order-search.capability.js';
|
|
24
|
+
import type { FakePriceCapability } from '../capabilities/price.capability.js';
|
|
25
|
+
import type { FakeProductAssociationsCapability } from '../capabilities/product-associations.capability.js';
|
|
26
|
+
import type { FakeProductCapability } from '../capabilities/product.capability.js';
|
|
27
|
+
import type { FakeProductReviewsCapability } from '../capabilities/product-reviews.capability.js';
|
|
28
|
+
import type { FakeProductSearchCapability } from '../capabilities/product-search.capability.js';
|
|
29
|
+
import type { FakeProfileCapability } from '../capabilities/profile.capability.js';
|
|
30
|
+
import type { FakeStoreCapability } from '../capabilities/store.capability.js';
|
|
31
|
+
type FakeCapabilityKey = keyof FakeCapabilities;
|
|
32
|
+
type EnabledCapability<TCapability> = TCapability extends {
|
|
33
|
+
enabled: true;
|
|
34
|
+
} ? true : false;
|
|
35
|
+
type NormalizeConfiguredCapabilities<T extends FakeCapabilities> = {
|
|
36
|
+
[K in FakeCapabilityKey]?: EnabledCapability<T[K]>;
|
|
37
|
+
};
|
|
38
|
+
type ExtractCapabilityFactory<TCapability, TContract, TDefaultFactory> = TCapability extends {
|
|
39
|
+
enabled: true;
|
|
40
|
+
factory?: infer TFactory;
|
|
41
|
+
} ? TFactory extends TContract ? TFactory : TDefaultFactory : TDefaultFactory;
|
|
42
|
+
type ExtractCapabilityImplementation<TCapability, TDefaultCapability> = TCapability extends {
|
|
43
|
+
enabled: true;
|
|
44
|
+
capability?: infer TCapabilityFactory;
|
|
45
|
+
} ? TCapabilityFactory extends (...args: unknown[]) => infer TResolvedCapability ? TResolvedCapability : TDefaultCapability : TDefaultCapability;
|
|
46
|
+
type FactoryContractMap = {
|
|
47
|
+
product: ProductFactory;
|
|
48
|
+
productSearch: ProductSearchFactory;
|
|
49
|
+
identity: IdentityFactory;
|
|
50
|
+
category: CategoryFactory;
|
|
51
|
+
cart: CartFactory;
|
|
52
|
+
inventory: InventoryFactory;
|
|
53
|
+
store: StoreFactory;
|
|
54
|
+
price: PriceFactory;
|
|
55
|
+
checkout: CheckoutFactory;
|
|
56
|
+
order: OrderFactory;
|
|
57
|
+
orderSearch: OrderSearchFactory;
|
|
58
|
+
profile: ProfileFactory;
|
|
59
|
+
productReviews: ProductReviewsFactory;
|
|
60
|
+
productAssociations: ProductAssociationsFactory;
|
|
61
|
+
};
|
|
62
|
+
type DefaultFactoryMap = {
|
|
63
|
+
product: FakeProductFactory;
|
|
64
|
+
productSearch: FakeProductSearchFactory;
|
|
65
|
+
identity: FakeIdentityFactory;
|
|
66
|
+
category: FakeCategoryFactory;
|
|
67
|
+
cart: FakeCartFactory;
|
|
68
|
+
inventory: FakeInventoryFactory;
|
|
69
|
+
store: FakeStoreFactory;
|
|
70
|
+
price: FakePriceFactory;
|
|
71
|
+
checkout: FakeCheckoutFactory;
|
|
72
|
+
order: FakeOrderFactory;
|
|
73
|
+
orderSearch: FakeOrderSearchFactory;
|
|
74
|
+
profile: FakeProfileFactory;
|
|
75
|
+
productReviews: FakeProductReviewsFactory;
|
|
76
|
+
productAssociations: FakeProductAssociationsFactory;
|
|
77
|
+
};
|
|
78
|
+
type ResolvedFactoryMap<T extends FakeCapabilities> = {
|
|
79
|
+
[K in FakeCapabilityKey]: ExtractCapabilityFactory<T[K], FactoryContractMap[K], DefaultFactoryMap[K]>;
|
|
80
|
+
};
|
|
81
|
+
type DefaultCapabilityMap<T extends FakeCapabilities> = {
|
|
82
|
+
product: FakeProductCapability<ResolvedFactoryMap<T>['product']>;
|
|
83
|
+
productSearch: FakeProductSearchCapability<ResolvedFactoryMap<T>['productSearch']>;
|
|
84
|
+
identity: FakeIdentityCapability<ResolvedFactoryMap<T>['identity']>;
|
|
85
|
+
category: FakeCategoryCapability<ResolvedFactoryMap<T>['category']>;
|
|
86
|
+
cart: FakeCartCapability<ResolvedFactoryMap<T>['cart']>;
|
|
87
|
+
inventory: FakeInventoryCapability<ResolvedFactoryMap<T>['inventory']>;
|
|
88
|
+
store: FakeStoreCapability<ResolvedFactoryMap<T>['store']>;
|
|
89
|
+
price: FakePriceCapability<ResolvedFactoryMap<T>['price']>;
|
|
90
|
+
checkout: FakeCheckoutCapability<ResolvedFactoryMap<T>['checkout']>;
|
|
91
|
+
order: FakeOrderCapability<ResolvedFactoryMap<T>['order']>;
|
|
92
|
+
orderSearch: FakeOrderSearchCapability<ResolvedFactoryMap<T>['orderSearch']>;
|
|
93
|
+
profile: FakeProfileCapability<ResolvedFactoryMap<T>['profile']>;
|
|
94
|
+
productReviews: FakeProductReviewsCapability<ResolvedFactoryMap<T>['productReviews']>;
|
|
95
|
+
productAssociations: FakeProductAssociationsCapability<ResolvedFactoryMap<T>['productAssociations']>;
|
|
96
|
+
};
|
|
97
|
+
type CapabilityImplementationMap<T extends FakeCapabilities> = {
|
|
98
|
+
[K in FakeCapabilityKey]: ExtractCapabilityImplementation<T[K], DefaultCapabilityMap<T>[K]>;
|
|
99
|
+
};
|
|
100
|
+
type EnabledCapabilityOverrideMap<T extends FakeCapabilities> = {
|
|
101
|
+
[K in FakeCapabilityKey as T[K] extends {
|
|
102
|
+
enabled: true;
|
|
103
|
+
} ? K : never]: CapabilityImplementationMap<T>[K];
|
|
104
|
+
};
|
|
105
|
+
export type FakeClientFromCapabilities<T extends FakeCapabilities> = Omit<ClientFromCapabilities<NormalizeConfiguredCapabilities<T>>, FakeCapabilityKey> & EnabledCapabilityOverrideMap<T>;
|
|
106
|
+
export declare function resolveCapabilityWithFactory<TFactory, TResolvedCapability, TCapabilityArgs>(capability: {
|
|
107
|
+
factory?: TFactory;
|
|
108
|
+
capability?: (args: TCapabilityArgs) => TResolvedCapability;
|
|
109
|
+
} | undefined, defaults: {
|
|
110
|
+
factory: TFactory;
|
|
111
|
+
capability: (args: TCapabilityArgs) => TResolvedCapability;
|
|
112
|
+
}, buildCapabilityArgs: (factory: TFactory) => TCapabilityArgs): TResolvedCapability;
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyCartIdentifierSchema, AnyCartSchema, CartFactory, CartIdentifierSchema, CartSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeCartFactory<TCartSchema extends AnyCartSchema = typeof CartSchema, TCartIdentifierSchema extends AnyCartIdentifierSchema = typeof CartIdentifierSchema> implements CartFactory<TCartSchema, TCartIdentifierSchema> {
|
|
4
|
+
readonly cartSchema: TCartSchema;
|
|
5
|
+
readonly cartIdentifierSchema: TCartIdentifierSchema;
|
|
6
|
+
constructor(cartSchema: TCartSchema, cartIdentifierSchema: TCartIdentifierSchema);
|
|
7
|
+
parseCart(_context: RequestContext, data: unknown): z.output<TCartSchema>;
|
|
8
|
+
parseCartIdentifier(_context: RequestContext, data: unknown): z.output<TCartIdentifierSchema>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyCategoryPaginatedResultSchema, AnyCategorySchema, CategoryFactory, CategoryPaginatedResultSchema, CategorySchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeCategoryFactory<TCategorySchema extends AnyCategorySchema = typeof CategorySchema, TCategoryPaginatedSchema extends AnyCategoryPaginatedResultSchema = typeof CategoryPaginatedResultSchema> implements CategoryFactory<TCategorySchema, TCategoryPaginatedSchema> {
|
|
4
|
+
readonly categorySchema: TCategorySchema;
|
|
5
|
+
readonly categoryPaginatedResultSchema: TCategoryPaginatedSchema;
|
|
6
|
+
constructor(categorySchema: TCategorySchema, categoryPaginatedResultSchema: TCategoryPaginatedSchema);
|
|
7
|
+
parseCategory(_context: RequestContext, data: unknown): z.output<TCategorySchema>;
|
|
8
|
+
parseCategoryPaginatedResult(_context: RequestContext, data: unknown): z.output<TCategoryPaginatedSchema>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyCheckoutSchema, AnyPaymentMethodSchema, AnyShippingMethodSchema, CheckoutFactory, CheckoutSchema, PaymentMethodSchema, RequestContext, ShippingMethodSchema } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeCheckoutFactory<TCheckoutSchema extends AnyCheckoutSchema = typeof CheckoutSchema, TShippingMethodSchema extends AnyShippingMethodSchema = typeof ShippingMethodSchema, TPaymentMethodSchema extends AnyPaymentMethodSchema = typeof PaymentMethodSchema> implements CheckoutFactory<TCheckoutSchema, TShippingMethodSchema, TPaymentMethodSchema> {
|
|
4
|
+
readonly checkoutSchema: TCheckoutSchema;
|
|
5
|
+
readonly shippingMethodSchema: TShippingMethodSchema;
|
|
6
|
+
readonly paymentMethodSchema: TPaymentMethodSchema;
|
|
7
|
+
constructor(checkoutSchema: TCheckoutSchema, shippingMethodSchema: TShippingMethodSchema, paymentMethodSchema: TPaymentMethodSchema);
|
|
8
|
+
parseCheckout(_context: RequestContext, data: unknown): z.output<TCheckoutSchema>;
|
|
9
|
+
parseShippingMethod(_context: RequestContext, data: unknown): z.output<TShippingMethodSchema>;
|
|
10
|
+
parsePaymentMethod(_context: RequestContext, data: unknown): z.output<TPaymentMethodSchema>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyIdentitySchema, IdentityFactory, IdentitySchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeIdentityFactory<TIdentitySchema extends AnyIdentitySchema = typeof IdentitySchema> implements IdentityFactory<TIdentitySchema> {
|
|
4
|
+
readonly identitySchema: TIdentitySchema;
|
|
5
|
+
constructor(identitySchema: TIdentitySchema);
|
|
6
|
+
parseIdentity(_context: RequestContext, data: unknown): z.output<TIdentitySchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './cart/cart.factory.js';
|
|
2
|
+
export * from './category/category.factory.js';
|
|
3
|
+
export * from './checkout/checkout.factory.js';
|
|
4
|
+
export * from './identity/identity.factory.js';
|
|
5
|
+
export * from './inventory/inventory.factory.js';
|
|
6
|
+
export * from './order-search/order-search.factory.js';
|
|
7
|
+
export * from './order/order.factory.js';
|
|
8
|
+
export * from './price/price.factory.js';
|
|
9
|
+
export * from './product-associations/product-associations.factory.js';
|
|
10
|
+
export * from './product-reviews/product-reviews.factory.js';
|
|
11
|
+
export * from './product-search/product-search.factory.js';
|
|
12
|
+
export * from './product/product.factory.js';
|
|
13
|
+
export * from './profile/profile.factory.js';
|
|
14
|
+
export * from './store/store.factory.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyInventorySchema, InventoryFactory, InventorySchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeInventoryFactory<TInventorySchema extends AnyInventorySchema = typeof InventorySchema> implements InventoryFactory<TInventorySchema> {
|
|
4
|
+
readonly inventorySchema: TInventorySchema;
|
|
5
|
+
constructor(inventorySchema: TInventorySchema);
|
|
6
|
+
parseInventory(_context: RequestContext, data: unknown): z.output<TInventorySchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyOrderSchema, OrderFactory, OrderSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeOrderFactory<TOrderSchema extends AnyOrderSchema = typeof OrderSchema> implements OrderFactory<TOrderSchema> {
|
|
4
|
+
readonly orderSchema: TOrderSchema;
|
|
5
|
+
constructor(orderSchema: TOrderSchema);
|
|
6
|
+
parseOrder(_context: RequestContext, data: unknown): z.output<TOrderSchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyOrderSearchResultSchema, OrderSearchFactory, OrderSearchQueryByTerm, OrderSearchResultSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeOrderSearchFactory<TOrderSearchResultSchema extends AnyOrderSearchResultSchema = typeof OrderSearchResultSchema> implements OrderSearchFactory<TOrderSearchResultSchema> {
|
|
4
|
+
readonly orderSearchResultSchema: TOrderSearchResultSchema;
|
|
5
|
+
constructor(orderSearchResultSchema: TOrderSearchResultSchema);
|
|
6
|
+
parseOrderSearchResult(_context: RequestContext, data: unknown, _query: OrderSearchQueryByTerm): z.output<TOrderSearchResultSchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyPriceSchema, PriceFactory, PriceSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakePriceFactory<TPriceSchema extends AnyPriceSchema = typeof PriceSchema> implements PriceFactory<TPriceSchema> {
|
|
4
|
+
readonly priceSchema: TPriceSchema;
|
|
5
|
+
constructor(priceSchema: TPriceSchema);
|
|
6
|
+
parsePrice(_context: RequestContext, data: unknown, _options?: {
|
|
7
|
+
includeDiscounts: boolean;
|
|
8
|
+
}): z.output<TPriceSchema>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyProductSchema, ProductFactory, ProductSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeProductFactory<TProductSchema extends AnyProductSchema = typeof ProductSchema> implements ProductFactory<TProductSchema> {
|
|
4
|
+
readonly productSchema: TProductSchema;
|
|
5
|
+
constructor(productSchema: TProductSchema);
|
|
6
|
+
parseProduct(_context: RequestContext, data: unknown): z.output<TProductSchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyProductAssociationSchema, ProductAssociationSchema, ProductAssociationsFactory, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeProductAssociationsFactory<TProductAssociationSchema extends AnyProductAssociationSchema = typeof ProductAssociationSchema> implements ProductAssociationsFactory<TProductAssociationSchema> {
|
|
4
|
+
readonly productAssociationSchema: TProductAssociationSchema;
|
|
5
|
+
constructor(productAssociationSchema: TProductAssociationSchema);
|
|
6
|
+
parseAssociation(_context: RequestContext, data: unknown): z.output<TProductAssociationSchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyProductRatingSummarySchema, AnyProductReviewPaginatedSchema, AnyProductReviewSchema, ProductRatingSummarySchema, ProductReviewPaginatedResultSchema, ProductReviewSchema, ProductReviewsFactory, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeProductReviewsFactory<TRatingSummarySchema extends AnyProductRatingSummarySchema = typeof ProductRatingSummarySchema, TReviewSchema extends AnyProductReviewSchema = typeof ProductReviewSchema, TReviewPaginatedSchema extends AnyProductReviewPaginatedSchema = typeof ProductReviewPaginatedResultSchema> implements ProductReviewsFactory<TRatingSummarySchema, TReviewSchema, TReviewPaginatedSchema> {
|
|
4
|
+
readonly ratingSummarySchema: TRatingSummarySchema;
|
|
5
|
+
readonly reviewSchema: TReviewSchema;
|
|
6
|
+
readonly reviewPaginatedSchema: TReviewPaginatedSchema;
|
|
7
|
+
constructor(ratingSummarySchema: TRatingSummarySchema, reviewSchema: TReviewSchema, reviewPaginatedSchema: TReviewPaginatedSchema);
|
|
8
|
+
parseRatingSummary(_context: RequestContext, data: unknown): z.output<TRatingSummarySchema>;
|
|
9
|
+
parseReview(_context: RequestContext, data: unknown): z.output<TReviewSchema>;
|
|
10
|
+
parseReviewPaginatedResult(_context: RequestContext, data: unknown): z.output<TReviewPaginatedSchema>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyProductSearchResultSchema, ProductSearchFactory, ProductSearchQueryByTerm, ProductSearchResultSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeProductSearchFactory<TProductSearchResultSchema extends AnyProductSearchResultSchema = typeof ProductSearchResultSchema> implements ProductSearchFactory<TProductSearchResultSchema> {
|
|
4
|
+
readonly productSearchResultSchema: TProductSearchResultSchema;
|
|
5
|
+
constructor(productSearchResultSchema: TProductSearchResultSchema);
|
|
6
|
+
parseSearchResult(_context: RequestContext, data: unknown, _query: ProductSearchQueryByTerm): z.output<TProductSearchResultSchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyProfileSchema, ProfileFactory, ProfileSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeProfileFactory<TProfileSchema extends AnyProfileSchema = typeof ProfileSchema> implements ProfileFactory<TProfileSchema> {
|
|
4
|
+
readonly profileSchema: TProfileSchema;
|
|
5
|
+
constructor(profileSchema: TProfileSchema);
|
|
6
|
+
parseProfile(_context: RequestContext, data: unknown): z.output<TProfileSchema>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyStoreSchema, RequestContext, StoreFactory, StoreSchema } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeStoreFactory<TStoreSchema extends AnyStoreSchema = typeof StoreSchema> implements StoreFactory<TStoreSchema> {
|
|
4
|
+
readonly storeSchema: TStoreSchema;
|
|
5
|
+
constructor(storeSchema: TStoreSchema);
|
|
6
|
+
parseStore(_context: RequestContext, data: unknown): z.output<TStoreSchema>;
|
|
7
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Cache, CartFactory, CartFactoryWithOutput, CartCapability, CategoryFactory, CategoryFactoryWithOutput, CategoryCapability, CheckoutFactory, CheckoutFactoryWithOutput, CheckoutCapability, IdentityFactory, IdentityFactoryWithOutput, IdentityCapability, InventoryFactory, InventoryFactoryWithOutput, InventoryCapability, OrderFactory, OrderFactoryWithOutput, OrderCapability, OrderSearchFactory, OrderSearchFactoryWithOutput, OrderSearchCapability, PriceFactory, PriceFactoryWithOutput, PriceCapability, ProductAssociationsFactory, ProductAssociationsFactoryWithOutput, ProductAssociationsCapability, ProductFactory, ProductFactoryWithOutput, ProductCapability, ProductReviewsFactory, ProductReviewsFactoryWithOutput, ProductReviewsCapability, ProductSearchFactory, ProductSearchFactoryWithOutput, ProductSearchCapability, ProfileFactory, ProfileFactoryWithOutput, ProfileCapability, RequestContext, StoreFactory, StoreFactoryWithOutput, StoreCapability } from '@reactionary/core';
|
|
2
|
+
import type { FakeConfiguration } from './configuration.schema.js';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
export declare const FakeCapabilitiesSchema: z.ZodObject<{
|
|
5
|
+
product: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
6
|
+
enabled: z.ZodBoolean;
|
|
7
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
8
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
9
|
+
}, z.core.$loose>>>;
|
|
10
|
+
productSearch: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
11
|
+
enabled: z.ZodBoolean;
|
|
12
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
13
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
14
|
+
}, z.core.$loose>>>;
|
|
15
|
+
identity: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
16
|
+
enabled: z.ZodBoolean;
|
|
17
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
18
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
19
|
+
}, z.core.$loose>>>;
|
|
20
|
+
category: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
21
|
+
enabled: z.ZodBoolean;
|
|
22
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
23
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
24
|
+
}, z.core.$loose>>>;
|
|
25
|
+
cart: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
26
|
+
enabled: z.ZodBoolean;
|
|
27
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
28
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
29
|
+
}, z.core.$loose>>>;
|
|
30
|
+
inventory: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
31
|
+
enabled: z.ZodBoolean;
|
|
32
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
33
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
34
|
+
}, z.core.$loose>>>;
|
|
35
|
+
store: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
36
|
+
enabled: z.ZodBoolean;
|
|
37
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
38
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
39
|
+
}, z.core.$loose>>>;
|
|
40
|
+
price: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
41
|
+
enabled: z.ZodBoolean;
|
|
42
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
43
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
44
|
+
}, z.core.$loose>>>;
|
|
45
|
+
checkout: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
46
|
+
enabled: z.ZodBoolean;
|
|
47
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
48
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
49
|
+
}, z.core.$loose>>>;
|
|
50
|
+
order: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
51
|
+
enabled: z.ZodBoolean;
|
|
52
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
53
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
54
|
+
}, z.core.$loose>>>;
|
|
55
|
+
orderSearch: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
56
|
+
enabled: z.ZodBoolean;
|
|
57
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
58
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
59
|
+
}, z.core.$loose>>>;
|
|
60
|
+
profile: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
61
|
+
enabled: z.ZodBoolean;
|
|
62
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
63
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
64
|
+
}, z.core.$loose>>>;
|
|
65
|
+
productReviews: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
66
|
+
enabled: z.ZodBoolean;
|
|
67
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
68
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
69
|
+
}, z.core.$loose>>>;
|
|
70
|
+
productAssociations: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
71
|
+
enabled: z.ZodBoolean;
|
|
72
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
73
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
74
|
+
}, z.core.$loose>>>;
|
|
75
|
+
}, z.core.$loose>;
|
|
76
|
+
export interface FakeCapabilityFactoryArgs<TFactory> {
|
|
77
|
+
cache: Cache;
|
|
78
|
+
context: RequestContext;
|
|
79
|
+
config: FakeConfiguration;
|
|
80
|
+
factory: TFactory;
|
|
81
|
+
}
|
|
82
|
+
export interface FakeCapabilityConfig<TFactory, TCapability> {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
factory?: TFactory;
|
|
85
|
+
capability?: (args: FakeCapabilityFactoryArgs<TFactory>) => TCapability;
|
|
86
|
+
}
|
|
87
|
+
export type FakeProductCapabilityConfig = FakeCapabilityConfig<ProductFactoryWithOutput<ProductFactory>, ProductCapability>;
|
|
88
|
+
export type FakeProductSearchCapabilityConfig = FakeCapabilityConfig<ProductSearchFactoryWithOutput<ProductSearchFactory>, ProductSearchCapability>;
|
|
89
|
+
export type FakeIdentityCapabilityConfig = FakeCapabilityConfig<IdentityFactoryWithOutput<IdentityFactory>, IdentityCapability>;
|
|
90
|
+
export type FakeCategoryCapabilityConfig = FakeCapabilityConfig<CategoryFactoryWithOutput<CategoryFactory>, CategoryCapability>;
|
|
91
|
+
export type FakeCartCapabilityConfig = FakeCapabilityConfig<CartFactoryWithOutput<CartFactory>, CartCapability>;
|
|
92
|
+
export type FakeInventoryCapabilityConfig = FakeCapabilityConfig<InventoryFactoryWithOutput<InventoryFactory>, InventoryCapability>;
|
|
93
|
+
export type FakeStoreCapabilityConfig = FakeCapabilityConfig<StoreFactoryWithOutput<StoreFactory>, StoreCapability>;
|
|
94
|
+
export type FakePriceCapabilityConfig = FakeCapabilityConfig<PriceFactoryWithOutput<PriceFactory>, PriceCapability>;
|
|
95
|
+
export type FakeCheckoutCapabilityConfig = FakeCapabilityConfig<CheckoutFactoryWithOutput<CheckoutFactory>, CheckoutCapability>;
|
|
96
|
+
export type FakeOrderCapabilityConfig = FakeCapabilityConfig<OrderFactoryWithOutput<OrderFactory>, OrderCapability>;
|
|
97
|
+
export type FakeOrderSearchCapabilityConfig = FakeCapabilityConfig<OrderSearchFactoryWithOutput<OrderSearchFactory>, OrderSearchCapability>;
|
|
98
|
+
export type FakeProfileCapabilityConfig = FakeCapabilityConfig<ProfileFactoryWithOutput<ProfileFactory>, ProfileCapability>;
|
|
99
|
+
export type FakeProductReviewsCapabilityConfig = FakeCapabilityConfig<ProductReviewsFactoryWithOutput<ProductReviewsFactory>, ProductReviewsCapability>;
|
|
100
|
+
export type FakeProductAssociationsCapabilityConfig = FakeCapabilityConfig<ProductAssociationsFactoryWithOutput<ProductAssociationsFactory>, ProductAssociationsCapability>;
|
|
101
|
+
export type FakeCapabilities = {
|
|
102
|
+
product?: FakeProductCapabilityConfig;
|
|
103
|
+
productSearch?: FakeProductSearchCapabilityConfig;
|
|
104
|
+
identity?: FakeIdentityCapabilityConfig;
|
|
105
|
+
category?: FakeCategoryCapabilityConfig;
|
|
106
|
+
cart?: FakeCartCapabilityConfig;
|
|
107
|
+
inventory?: FakeInventoryCapabilityConfig;
|
|
108
|
+
store?: FakeStoreCapabilityConfig;
|
|
109
|
+
price?: FakePriceCapabilityConfig;
|
|
110
|
+
checkout?: FakeCheckoutCapabilityConfig;
|
|
111
|
+
order?: FakeOrderCapabilityConfig;
|
|
112
|
+
orderSearch?: FakeOrderSearchCapabilityConfig;
|
|
113
|
+
profile?: FakeProfileCapabilityConfig;
|
|
114
|
+
productReviews?: FakeProductReviewsCapabilityConfig;
|
|
115
|
+
productAssociations?: FakeProductAssociationsCapabilityConfig;
|
|
116
|
+
};
|
|
117
|
+
export type ParsedFakeCapabilities = z.infer<typeof FakeCapabilitiesSchema>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const FakeConfigurationSchema: z.ZodObject<{
|
|
3
|
+
jitter: z.ZodDefault<z.ZodObject<{
|
|
4
|
+
mean: z.ZodNumber;
|
|
5
|
+
deviation: z.ZodNumber;
|
|
6
|
+
}, z.core.$loose>>;
|
|
7
|
+
seeds: z.ZodObject<{
|
|
8
|
+
product: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
search: z.ZodDefault<z.ZodNumber>;
|
|
10
|
+
category: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
}, z.core.$loose>;
|
|
12
|
+
}, z.core.$loose>;
|
|
13
|
+
export type FakeConfiguration = z.infer<typeof FakeConfigurationSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jitter(duration: number, deviation: number): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function calcSeed(input: string): number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClientBuilder,
|
|
3
|
+
NoOpCache,
|
|
4
|
+
ProductSchema,
|
|
5
|
+
createInitialRequestContext
|
|
6
|
+
} from "@reactionary/core";
|
|
7
|
+
import * as z from "zod";
|
|
8
|
+
import { withFakeCapabilities } from "../core/initialize.js";
|
|
9
|
+
import { FakeProductFactory } from "../factories/product/product.factory.js";
|
|
10
|
+
const assertType = (_value) => {
|
|
11
|
+
};
|
|
12
|
+
const assertNotAny = (_value) => {
|
|
13
|
+
};
|
|
14
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
15
|
+
extendedValue: z.string()
|
|
16
|
+
});
|
|
17
|
+
class ExtendedFakeProductFactory extends FakeProductFactory {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(ExtendedProductSchema);
|
|
20
|
+
}
|
|
21
|
+
parseProduct(context, data) {
|
|
22
|
+
const base = super.parseProduct(context, data);
|
|
23
|
+
return this.productSchema.parse({
|
|
24
|
+
...base,
|
|
25
|
+
extendedValue: "from-fake-factory"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const config = {
|
|
30
|
+
jitter: {
|
|
31
|
+
mean: 0,
|
|
32
|
+
deviation: 0
|
|
33
|
+
},
|
|
34
|
+
seeds: {
|
|
35
|
+
product: 1,
|
|
36
|
+
search: 1,
|
|
37
|
+
category: 1
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const client = new ClientBuilder(createInitialRequestContext()).withCache(new NoOpCache()).withCapability(
|
|
41
|
+
withFakeCapabilities(config, {
|
|
42
|
+
product: {
|
|
43
|
+
enabled: true,
|
|
44
|
+
factory: new ExtendedFakeProductFactory()
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
).build();
|
|
48
|
+
client.product.getById({
|
|
49
|
+
identifier: { key: "example-product-id" }
|
|
50
|
+
}).then((result) => {
|
|
51
|
+
assertNotAny(result);
|
|
52
|
+
if (result.success) {
|
|
53
|
+
assertNotAny(result.value);
|
|
54
|
+
assertNotAny(result.value.extendedValue);
|
|
55
|
+
assertType(result.value.extendedValue);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
async function jitter(duration, deviation) {
|
|
2
|
+
const j = gaussianRandom(duration, deviation);
|
|
3
|
+
return new Promise((resolve) => setTimeout(resolve, j));
|
|
4
|
+
}
|
|
5
|
+
function gaussianRandom(mean, deviation) {
|
|
6
|
+
const u = 1 - Math.random();
|
|
7
|
+
const v = Math.random();
|
|
8
|
+
const z = Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
|
|
9
|
+
return z * deviation + mean;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
jitter
|
|
13
|
+
};
|