@reactionary/source 0.3.18 → 0.6.2
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 +28 -14
- package/core/src/client/client-builder.ts +54 -6
- package/core/src/factories/cart.factory.ts +40 -0
- package/core/src/factories/category.factory.ts +40 -0
- package/core/src/factories/checkout.factory.ts +59 -0
- package/core/src/factories/identity.factory.ts +26 -0
- package/core/src/factories/index.ts +15 -0
- package/core/src/factories/inventory.factory.ts +26 -0
- package/core/src/factories/order-search.factory.ts +33 -0
- package/core/src/factories/order.factory.ts +21 -0
- package/core/src/factories/price.factory.ts +29 -0
- package/core/src/factories/product-associations.factory.ts +30 -0
- package/core/src/factories/product-list.factory.ts +82 -0
- package/core/src/factories/product-reviews.factory.ts +58 -0
- package/core/src/factories/product-search.factory.ts +31 -0
- package/core/src/factories/product.factory.ts +21 -0
- package/core/src/factories/profile.factory.ts +23 -0
- package/core/src/factories/store.factory.ts +21 -0
- package/core/src/index.ts +3 -1
- package/core/src/providers/cart.provider.ts +12 -10
- package/core/src/providers/category.provider.ts +9 -7
- package/core/src/providers/checkout.provider.ts +14 -10
- package/core/src/providers/identity.provider.ts +7 -7
- package/core/src/providers/inventory.provider.ts +4 -4
- package/core/src/providers/order-search.provider.ts +4 -2
- package/core/src/providers/order.provider.ts +4 -4
- package/core/src/providers/price.provider.ts +5 -5
- package/core/src/providers/product-associations.provider.ts +6 -4
- package/core/src/providers/product-list.provider.ts +13 -8
- package/core/src/providers/product-reviews.provider.ts +8 -4
- package/core/src/providers/product-search.provider.ts +15 -28
- package/core/src/providers/product.provider.ts +6 -6
- package/core/src/providers/profile.provider.ts +8 -8
- package/core/src/providers/store.provider.ts +2 -2
- package/core/src/test/client-builder.spec.ts +81 -0
- package/examples/node/package.json +7 -7
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +10 -4
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +8 -2
- package/examples/node/src/basic/basic-node-setup.spec.ts +5 -1
- package/examples/node/src/basic/client-creation.spec.ts +3 -3
- package/examples/node/src/utils.ts +41 -41
- package/examples/node/tsconfig.lib.json +2 -1
- package/package.json +1 -1
- package/providers/algolia/src/core/initialize.ts +76 -21
- package/providers/algolia/src/core/initialize.types.ts +107 -0
- package/providers/algolia/src/factories/index.ts +1 -0
- package/providers/algolia/src/factories/product-search/product-search.factory.ts +182 -0
- package/providers/algolia/src/index.ts +2 -2
- package/providers/algolia/src/providers/analytics.provider.ts +4 -4
- package/providers/algolia/src/providers/product-search.provider.ts +67 -184
- package/providers/algolia/src/schema/capabilities.schema.ts +81 -7
- package/providers/algolia/src/test/analytics.spec.ts +9 -1
- package/providers/algolia/src/test/client-builder-product-search-extension.example.ts +85 -0
- package/providers/commercetools/src/core/capability-descriptors.ts +324 -0
- package/providers/commercetools/src/core/initialize.ts +35 -151
- package/providers/commercetools/src/core/initialize.types.ts +174 -0
- package/providers/commercetools/src/factories/cart/cart.factory.ts +142 -0
- package/providers/commercetools/src/factories/category/category.factory.ts +77 -0
- package/providers/commercetools/src/factories/checkout/checkout-initializer-overrides.example.ts +94 -0
- package/providers/commercetools/src/factories/checkout/checkout.factory.ts +338 -0
- package/providers/commercetools/src/factories/identity/identity.factory.ts +26 -0
- package/providers/commercetools/src/factories/inventory/inventory.factory.ts +49 -0
- package/providers/commercetools/src/factories/order/order.factory.ts +149 -0
- package/providers/commercetools/src/factories/order-search/order-search.factory.ts +108 -0
- package/providers/commercetools/src/factories/price/price.factory.ts +76 -0
- package/providers/commercetools/src/factories/product/product-factory-baseline.example.ts +14 -0
- package/providers/commercetools/src/factories/product/product-factory-schema-and-parse-extension.example.ts +35 -0
- package/providers/commercetools/src/factories/product/product-factory-schema-extension.example.ts +23 -0
- package/providers/commercetools/src/factories/product/product-initializer-factory-extension.example.ts +41 -0
- package/providers/commercetools/src/factories/product/product-provider-custom-method-only.example.ts +47 -0
- package/providers/commercetools/src/factories/product/product-provider-schema-signature-extension.example.ts +61 -0
- package/providers/commercetools/src/factories/product/product.factory.ts +220 -0
- package/providers/commercetools/src/factories/product/utils.example.ts +9 -0
- package/providers/commercetools/src/factories/product-associations/product-associations.factory.ts +103 -0
- package/providers/commercetools/src/factories/product-list/product-list.factory.ts +122 -0
- package/providers/commercetools/src/factories/product-reviews/product-reviews.factory.ts +81 -0
- package/providers/commercetools/src/factories/product-search/product-search.factory.ts +182 -0
- package/providers/commercetools/src/factories/profile/profile.factory.ts +94 -0
- package/providers/commercetools/src/factories/store/store.factory.ts +49 -0
- package/providers/commercetools/src/index.ts +15 -0
- package/providers/commercetools/src/providers/cart.provider.ts +67 -193
- package/providers/commercetools/src/providers/category.provider.ts +24 -64
- package/providers/commercetools/src/providers/checkout.provider.ts +50 -322
- package/providers/commercetools/src/providers/identity.provider.ts +35 -15
- package/providers/commercetools/src/providers/inventory.provider.ts +13 -31
- package/providers/commercetools/src/providers/order-search.provider.ts +16 -110
- package/providers/commercetools/src/providers/order.provider.ts +13 -144
- package/providers/commercetools/src/providers/price.provider.ts +37 -51
- package/providers/commercetools/src/providers/product-associations.provider.ts +39 -104
- package/providers/commercetools/src/providers/product-list.provider.ts +38 -23
- package/providers/commercetools/src/providers/product-reviews.provider.ts +34 -14
- package/providers/commercetools/src/providers/product-search.provider.ts +17 -170
- package/providers/commercetools/src/providers/product.provider.ts +20 -199
- package/providers/commercetools/src/providers/profile.provider.ts +27 -73
- package/providers/commercetools/src/providers/store.provider.ts +13 -31
- package/providers/commercetools/src/schema/capabilities.schema.ts +258 -20
- package/providers/commercetools/src/test/caching.spec.ts +18 -2
- package/providers/commercetools/src/test/client-builder-merge-extensions.example.ts +125 -0
- package/providers/fake/src/core/initialize.ts +213 -44
- package/providers/fake/src/core/initialize.types.ts +164 -0
- package/providers/fake/src/factories/cart/cart.factory.ts +34 -0
- package/providers/fake/src/factories/category/category.factory.ts +40 -0
- package/providers/fake/src/factories/checkout/checkout.factory.ts +53 -0
- package/providers/fake/src/factories/identity/identity.factory.ts +25 -0
- package/providers/fake/src/factories/index.ts +14 -0
- package/providers/fake/src/factories/inventory/inventory.factory.ts +25 -0
- package/providers/fake/src/factories/order/order.factory.ts +22 -0
- package/providers/fake/src/factories/order-search/order-search.factory.ts +27 -0
- package/providers/fake/src/factories/price/price.factory.ts +26 -0
- package/providers/fake/src/factories/product/product.factory.ts +22 -0
- package/providers/fake/src/factories/product-associations/product-associations.factory.ts +25 -0
- package/providers/fake/src/factories/product-reviews/product-reviews.factory.ts +53 -0
- package/providers/fake/src/factories/product-search/product-search.factory.ts +27 -0
- package/providers/fake/src/factories/profile/profile.factory.ts +22 -0
- package/providers/fake/src/factories/store/store.factory.ts +22 -0
- package/providers/fake/src/index.ts +2 -0
- package/providers/fake/src/providers/cart.provider.ts +23 -14
- package/providers/fake/src/providers/category.provider.ts +120 -105
- package/providers/fake/src/providers/checkout.provider.ts +39 -20
- package/providers/fake/src/providers/identity.provider.ts +40 -34
- package/providers/fake/src/providers/inventory.provider.ts +26 -24
- package/providers/fake/src/providers/order-search.provider.ts +38 -30
- package/providers/fake/src/providers/order.provider.ts +21 -37
- package/providers/fake/src/providers/price.provider.ts +42 -34
- package/providers/fake/src/providers/product-associations.provider.ts +23 -10
- package/providers/fake/src/providers/product-reviews.provider.ts +71 -69
- package/providers/fake/src/providers/product-search.provider.ts +43 -70
- package/providers/fake/src/providers/product.provider.ts +34 -32
- package/providers/fake/src/providers/profile.provider.ts +62 -55
- package/providers/fake/src/providers/store.provider.ts +38 -22
- package/providers/fake/src/schema/capabilities.schema.ts +175 -18
- package/providers/fake/src/test/cart.provider.spec.ts +20 -3
- package/providers/fake/src/test/category.provider.spec.ts +4 -1
- package/providers/fake/src/test/checkout.provider.spec.ts +12 -2
- package/providers/fake/src/test/client-builder-product-extension.example.ts +75 -0
- package/providers/fake/src/test/order-search.provider.spec.ts +4 -7
- package/providers/fake/src/test/order.provider.spec.ts +4 -6
- package/providers/fake/src/test/price.provider.spec.ts +3 -1
- package/providers/fake/src/test/product.provider.spec.ts +8 -2
- package/providers/fake/src/test/profile.provider.spec.ts +4 -2
- package/providers/google-analytics/src/core/initialize.ts +37 -12
- package/providers/google-analytics/src/core/initialize.types.ts +47 -0
- package/providers/google-analytics/src/index.ts +1 -0
- package/providers/google-analytics/src/schema/capabilities.schema.ts +31 -5
- package/providers/medusa/src/core/initialize.ts +324 -81
- package/providers/medusa/src/core/initialize.types.ts +184 -0
- package/providers/medusa/src/factories/cart/cart.factory.ts +34 -0
- package/providers/medusa/src/factories/category/category.factory.ts +37 -0
- package/providers/medusa/src/factories/checkout/checkout.factory.ts +50 -0
- package/providers/medusa/src/factories/identity/identity.factory.ts +22 -0
- package/providers/medusa/src/factories/index.ts +12 -0
- package/providers/medusa/src/factories/inventory/inventory.factory.ts +25 -0
- package/providers/medusa/src/factories/order/order.factory.ts +22 -0
- package/providers/medusa/src/factories/order-search/order-search.factory.ts +27 -0
- package/providers/medusa/src/factories/price/price.factory.ts +26 -0
- package/providers/medusa/src/factories/product/product.factory.ts +22 -0
- package/providers/medusa/src/factories/product-associations/product-associations.factory.ts +25 -0
- package/providers/medusa/src/factories/product-search/product-search.factory.ts +27 -0
- package/providers/medusa/src/factories/profile/profile.factory.ts +22 -0
- package/providers/medusa/src/index.ts +2 -0
- package/providers/medusa/src/providers/cart.provider.ts +33 -20
- package/providers/medusa/src/providers/category.provider.ts +30 -12
- package/providers/medusa/src/providers/checkout.provider.ts +42 -17
- package/providers/medusa/src/providers/identity.provider.ts +1 -1
- package/providers/medusa/src/providers/inventory.provider.ts +21 -7
- package/providers/medusa/src/providers/order-search.provider.ts +16 -5
- package/providers/medusa/src/providers/order.provider.ts +17 -5
- package/providers/medusa/src/providers/price.provider.ts +26 -7
- package/providers/medusa/src/providers/product-associations.provider.ts +19 -8
- package/providers/medusa/src/providers/product-search.provider.ts +19 -31
- package/providers/medusa/src/providers/product.provider.ts +47 -11
- package/providers/medusa/src/providers/profile.provider.ts +35 -11
- package/providers/medusa/src/schema/capabilities.schema.ts +229 -18
- package/providers/medusa/src/test/cart.provider.spec.ts +18 -2
- package/providers/medusa/src/test/category.provider.spec.ts +4 -1
- package/providers/medusa/src/test/checkout.spec.ts +9 -9
- package/providers/medusa/src/test/inventory.provider.spec.ts +3 -1
- package/providers/medusa/src/test/large-cart.provider.spec.ts +8 -2
- package/providers/medusa/src/test/price.provider.spec.ts +8 -1
- package/providers/medusa/src/test/product.provider.spec.ts +3 -1
- package/providers/medusa/src/test/search.provider.spec.ts +16 -3
- package/providers/meilisearch/src/core/initialize.ts +88 -21
- package/providers/meilisearch/src/core/initialize.types.ts +119 -0
- package/providers/meilisearch/src/factories/index.ts +2 -0
- package/providers/meilisearch/src/factories/order-search/order-search.factory.ts +27 -0
- package/providers/meilisearch/src/factories/product-search/product-search.factory.ts +27 -0
- package/providers/meilisearch/src/index.ts +2 -0
- package/providers/meilisearch/src/providers/index.ts +1 -0
- package/providers/meilisearch/src/providers/order-search.provider.ts +21 -6
- package/providers/meilisearch/src/providers/product-search.provider.ts +24 -8
- package/providers/meilisearch/src/schema/capabilities.schema.ts +95 -8
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyCheckoutSchema,
|
|
3
|
+
AnyPaymentMethodSchema,
|
|
4
|
+
AnyShippingMethodSchema,
|
|
5
|
+
CheckoutFactory,
|
|
6
|
+
CheckoutSchema,
|
|
7
|
+
PaymentMethodSchema,
|
|
8
|
+
RequestContext,
|
|
9
|
+
ShippingMethodSchema,
|
|
10
|
+
} from '@reactionary/core';
|
|
11
|
+
import type * as z from 'zod';
|
|
12
|
+
|
|
13
|
+
export class MedusaCheckoutFactory<
|
|
14
|
+
TCheckoutSchema extends AnyCheckoutSchema = typeof CheckoutSchema,
|
|
15
|
+
TShippingMethodSchema extends AnyShippingMethodSchema = typeof ShippingMethodSchema,
|
|
16
|
+
TPaymentMethodSchema extends AnyPaymentMethodSchema = typeof PaymentMethodSchema,
|
|
17
|
+
> implements CheckoutFactory<TCheckoutSchema, TShippingMethodSchema, TPaymentMethodSchema>
|
|
18
|
+
{
|
|
19
|
+
public readonly checkoutSchema: TCheckoutSchema;
|
|
20
|
+
public readonly shippingMethodSchema: TShippingMethodSchema;
|
|
21
|
+
public readonly paymentMethodSchema: TPaymentMethodSchema;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
checkoutSchema: TCheckoutSchema,
|
|
25
|
+
shippingMethodSchema: TShippingMethodSchema,
|
|
26
|
+
paymentMethodSchema: TPaymentMethodSchema,
|
|
27
|
+
) {
|
|
28
|
+
this.checkoutSchema = checkoutSchema;
|
|
29
|
+
this.shippingMethodSchema = shippingMethodSchema;
|
|
30
|
+
this.paymentMethodSchema = paymentMethodSchema;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public parseCheckout(_context: RequestContext, data: unknown): z.output<TCheckoutSchema> {
|
|
34
|
+
return this.checkoutSchema.parse(data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public parseShippingMethod(
|
|
38
|
+
_context: RequestContext,
|
|
39
|
+
data: unknown,
|
|
40
|
+
): z.output<TShippingMethodSchema> {
|
|
41
|
+
return this.shippingMethodSchema.parse(data);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public parsePaymentMethod(
|
|
45
|
+
_context: RequestContext,
|
|
46
|
+
data: unknown,
|
|
47
|
+
): z.output<TPaymentMethodSchema> {
|
|
48
|
+
return this.paymentMethodSchema.parse(data);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyIdentitySchema,
|
|
3
|
+
IdentityFactory,
|
|
4
|
+
IdentitySchema,
|
|
5
|
+
RequestContext,
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import type * as z from 'zod';
|
|
8
|
+
|
|
9
|
+
export class MedusaIdentityFactory<
|
|
10
|
+
TIdentitySchema extends AnyIdentitySchema = typeof IdentitySchema,
|
|
11
|
+
> implements IdentityFactory<TIdentitySchema>
|
|
12
|
+
{
|
|
13
|
+
public readonly identitySchema: TIdentitySchema;
|
|
14
|
+
|
|
15
|
+
constructor(identitySchema: TIdentitySchema) {
|
|
16
|
+
this.identitySchema = identitySchema;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public parseIdentity(_context: RequestContext, data: unknown): z.output<TIdentitySchema> {
|
|
20
|
+
return this.identitySchema.parse(data);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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/order.factory.js';
|
|
7
|
+
export * from './order-search/order-search.factory.js';
|
|
8
|
+
export * from './price/price.factory.js';
|
|
9
|
+
export * from './product/product.factory.js';
|
|
10
|
+
export * from './product-associations/product-associations.factory.js';
|
|
11
|
+
export * from './product-search/product-search.factory.js';
|
|
12
|
+
export * from './profile/profile.factory.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyInventorySchema,
|
|
3
|
+
InventoryFactory,
|
|
4
|
+
InventorySchema,
|
|
5
|
+
RequestContext,
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import type * as z from 'zod';
|
|
8
|
+
|
|
9
|
+
export class MedusaInventoryFactory<
|
|
10
|
+
TInventorySchema extends AnyInventorySchema = typeof InventorySchema,
|
|
11
|
+
> implements InventoryFactory<TInventorySchema>
|
|
12
|
+
{
|
|
13
|
+
public readonly inventorySchema: TInventorySchema;
|
|
14
|
+
|
|
15
|
+
constructor(inventorySchema: TInventorySchema) {
|
|
16
|
+
this.inventorySchema = inventorySchema;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public parseInventory(
|
|
20
|
+
_context: RequestContext,
|
|
21
|
+
data: unknown,
|
|
22
|
+
): z.output<TInventorySchema> {
|
|
23
|
+
return this.inventorySchema.parse(data);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyOrderSchema,
|
|
3
|
+
OrderFactory,
|
|
4
|
+
OrderSchema,
|
|
5
|
+
RequestContext,
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import type * as z from 'zod';
|
|
8
|
+
|
|
9
|
+
export class MedusaOrderFactory<
|
|
10
|
+
TOrderSchema extends AnyOrderSchema = typeof OrderSchema,
|
|
11
|
+
> implements OrderFactory<TOrderSchema>
|
|
12
|
+
{
|
|
13
|
+
public readonly orderSchema: TOrderSchema;
|
|
14
|
+
|
|
15
|
+
constructor(orderSchema: TOrderSchema) {
|
|
16
|
+
this.orderSchema = orderSchema;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public parseOrder(_context: RequestContext, data: unknown): z.output<TOrderSchema> {
|
|
20
|
+
return this.orderSchema.parse(data);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyOrderSearchResultSchema,
|
|
3
|
+
OrderSearchFactory,
|
|
4
|
+
OrderSearchQueryByTerm,
|
|
5
|
+
OrderSearchResultSchema,
|
|
6
|
+
RequestContext,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
import type * as z from 'zod';
|
|
9
|
+
|
|
10
|
+
export class MedusaOrderSearchFactory<
|
|
11
|
+
TOrderSearchResultSchema extends AnyOrderSearchResultSchema = typeof OrderSearchResultSchema,
|
|
12
|
+
> implements OrderSearchFactory<TOrderSearchResultSchema>
|
|
13
|
+
{
|
|
14
|
+
public readonly orderSearchResultSchema: TOrderSearchResultSchema;
|
|
15
|
+
|
|
16
|
+
constructor(orderSearchResultSchema: TOrderSearchResultSchema) {
|
|
17
|
+
this.orderSearchResultSchema = orderSearchResultSchema;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public parseOrderSearchResult(
|
|
21
|
+
_context: RequestContext,
|
|
22
|
+
data: unknown,
|
|
23
|
+
_query: OrderSearchQueryByTerm,
|
|
24
|
+
): z.output<TOrderSearchResultSchema> {
|
|
25
|
+
return this.orderSearchResultSchema.parse(data);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyPriceSchema,
|
|
3
|
+
PriceFactory,
|
|
4
|
+
PriceSchema,
|
|
5
|
+
RequestContext,
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import type * as z from 'zod';
|
|
8
|
+
|
|
9
|
+
export class MedusaPriceFactory<
|
|
10
|
+
TPriceSchema extends AnyPriceSchema = typeof PriceSchema,
|
|
11
|
+
> implements PriceFactory<TPriceSchema>
|
|
12
|
+
{
|
|
13
|
+
public readonly priceSchema: TPriceSchema;
|
|
14
|
+
|
|
15
|
+
constructor(priceSchema: TPriceSchema) {
|
|
16
|
+
this.priceSchema = priceSchema;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public parsePrice(
|
|
20
|
+
_context: RequestContext,
|
|
21
|
+
data: unknown,
|
|
22
|
+
_options?: { includeDiscounts: boolean },
|
|
23
|
+
): z.output<TPriceSchema> {
|
|
24
|
+
return this.priceSchema.parse(data);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyProductSchema,
|
|
3
|
+
ProductFactory,
|
|
4
|
+
ProductSchema,
|
|
5
|
+
RequestContext,
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import type * as z from 'zod';
|
|
8
|
+
|
|
9
|
+
export class MedusaProductFactory<
|
|
10
|
+
TProductSchema extends AnyProductSchema = typeof ProductSchema,
|
|
11
|
+
> implements ProductFactory<TProductSchema>
|
|
12
|
+
{
|
|
13
|
+
public readonly productSchema: TProductSchema;
|
|
14
|
+
|
|
15
|
+
constructor(productSchema: TProductSchema) {
|
|
16
|
+
this.productSchema = productSchema;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public parseProduct(_context: RequestContext, data: unknown): z.output<TProductSchema> {
|
|
20
|
+
return this.productSchema.parse(data);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyProductAssociationSchema,
|
|
3
|
+
ProductAssociationSchema,
|
|
4
|
+
ProductAssociationsFactory,
|
|
5
|
+
RequestContext,
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import type * as z from 'zod';
|
|
8
|
+
|
|
9
|
+
export class MedusaProductAssociationsFactory<
|
|
10
|
+
TProductAssociationSchema extends AnyProductAssociationSchema = typeof ProductAssociationSchema,
|
|
11
|
+
> implements ProductAssociationsFactory<TProductAssociationSchema>
|
|
12
|
+
{
|
|
13
|
+
public readonly productAssociationSchema: TProductAssociationSchema;
|
|
14
|
+
|
|
15
|
+
constructor(productAssociationSchema: TProductAssociationSchema) {
|
|
16
|
+
this.productAssociationSchema = productAssociationSchema;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public parseAssociation(
|
|
20
|
+
_context: RequestContext,
|
|
21
|
+
data: unknown,
|
|
22
|
+
): z.output<TProductAssociationSchema> {
|
|
23
|
+
return this.productAssociationSchema.parse(data);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyProductSearchResultSchema,
|
|
3
|
+
ProductSearchFactory,
|
|
4
|
+
ProductSearchQueryByTerm,
|
|
5
|
+
ProductSearchResultSchema,
|
|
6
|
+
RequestContext,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
import type * as z from 'zod';
|
|
9
|
+
|
|
10
|
+
export class MedusaProductSearchFactory<
|
|
11
|
+
TProductSearchResultSchema extends AnyProductSearchResultSchema = typeof ProductSearchResultSchema,
|
|
12
|
+
> implements ProductSearchFactory<TProductSearchResultSchema>
|
|
13
|
+
{
|
|
14
|
+
public readonly productSearchResultSchema: TProductSearchResultSchema;
|
|
15
|
+
|
|
16
|
+
constructor(productSearchResultSchema: TProductSearchResultSchema) {
|
|
17
|
+
this.productSearchResultSchema = productSearchResultSchema;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public parseSearchResult(
|
|
21
|
+
_context: RequestContext,
|
|
22
|
+
data: unknown,
|
|
23
|
+
_query: ProductSearchQueryByTerm,
|
|
24
|
+
): z.output<TProductSearchResultSchema> {
|
|
25
|
+
return this.productSearchResultSchema.parse(data);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyProfileSchema,
|
|
3
|
+
ProfileFactory,
|
|
4
|
+
ProfileSchema,
|
|
5
|
+
RequestContext,
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import type * as z from 'zod';
|
|
8
|
+
|
|
9
|
+
export class MedusaProfileFactory<
|
|
10
|
+
TProfileSchema extends AnyProfileSchema = typeof ProfileSchema,
|
|
11
|
+
> implements ProfileFactory<TProfileSchema>
|
|
12
|
+
{
|
|
13
|
+
public readonly profileSchema: TProfileSchema;
|
|
14
|
+
|
|
15
|
+
constructor(profileSchema: TProfileSchema) {
|
|
16
|
+
this.profileSchema = profileSchema;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public parseProfile(_context: RequestContext, data: unknown): z.output<TProfileSchema> {
|
|
20
|
+
return this.profileSchema.parse(data);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -2,7 +2,9 @@ export * from './schema/configuration.schema.js';
|
|
|
2
2
|
export * from './schema/medusa.schema.js';
|
|
3
3
|
export * from './schema/capabilities.schema.js';
|
|
4
4
|
export * from './core/initialize.js';
|
|
5
|
+
export * from './core/initialize.types.js';
|
|
5
6
|
export * from './core/client.js';
|
|
7
|
+
export * from './factories/index.js';
|
|
6
8
|
export * from './providers/cart.provider.js';
|
|
7
9
|
export * from './providers/identity.provider.js';
|
|
8
10
|
export * from './providers/inventory.provider.js';
|
|
@@ -3,6 +3,10 @@ import type {
|
|
|
3
3
|
Cart,
|
|
4
4
|
CartIdentifier,
|
|
5
5
|
CartItem,
|
|
6
|
+
CartFactory,
|
|
7
|
+
CartFactoryCartOutput,
|
|
8
|
+
CartFactoryIdentifierOutput,
|
|
9
|
+
CartFactoryWithOutput,
|
|
6
10
|
CartMutationApplyCoupon,
|
|
7
11
|
CartMutationChangeCurrency,
|
|
8
12
|
CartMutationDeleteCart,
|
|
@@ -49,11 +53,18 @@ import {
|
|
|
49
53
|
parseMedusaItemPrice,
|
|
50
54
|
} from '../utils/medusa-helpers.js';
|
|
51
55
|
import type { StoreAddCartLineItem, StoreCart, StoreCartAddPromotion, StoreCartLineItem, StoreCartRemovePromotion, StoreCartResponse, StoreCreateCart, StoreProduct, StoreUpdateCart, StoreUpdateCartLineItem } from '@medusajs/types';
|
|
56
|
+
import type { MedusaCartFactory } from '../factories/cart/cart.factory.js';
|
|
52
57
|
|
|
53
58
|
const debug = createDebug('reactionary:medusa:cart');
|
|
54
59
|
|
|
55
|
-
export class MedusaCartProvider
|
|
60
|
+
export class MedusaCartProvider<
|
|
61
|
+
TFactory extends CartFactory = MedusaCartFactory,
|
|
62
|
+
> extends CartProvider<
|
|
63
|
+
CartFactoryCartOutput<TFactory>,
|
|
64
|
+
CartFactoryIdentifierOutput<TFactory>
|
|
65
|
+
> {
|
|
56
66
|
protected config: MedusaConfiguration;
|
|
67
|
+
protected factory: CartFactoryWithOutput<TFactory>;
|
|
57
68
|
/**
|
|
58
69
|
* This controls which fields are always included when fetching a cart
|
|
59
70
|
* You can override this in a subclass to add more fields as needed.
|
|
@@ -66,10 +77,12 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
66
77
|
config: MedusaConfiguration,
|
|
67
78
|
cache: Cache,
|
|
68
79
|
context: RequestContext,
|
|
69
|
-
public medusaApi: MedusaAPI
|
|
80
|
+
public medusaApi: MedusaAPI,
|
|
81
|
+
factory: CartFactoryWithOutput<TFactory>,
|
|
70
82
|
) {
|
|
71
83
|
super(cache, context);
|
|
72
84
|
this.config = config;
|
|
85
|
+
this.factory = factory;
|
|
73
86
|
}
|
|
74
87
|
|
|
75
88
|
@Reactionary({
|
|
@@ -78,7 +91,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
78
91
|
})
|
|
79
92
|
public override async getById(
|
|
80
93
|
payload: CartQueryById
|
|
81
|
-
): Promise<Result<
|
|
94
|
+
): Promise<Result<CartFactoryCartOutput<TFactory>, NotFoundError>> {
|
|
82
95
|
try {
|
|
83
96
|
const client = await this.getClient();
|
|
84
97
|
const medusaId = payload.cart as MedusaCartIdentifier;
|
|
@@ -132,7 +145,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
132
145
|
})
|
|
133
146
|
public override async add(
|
|
134
147
|
payload: CartMutationItemAdd
|
|
135
|
-
): Promise<Result<
|
|
148
|
+
): Promise<Result<CartFactoryCartOutput<TFactory>>> {
|
|
136
149
|
try {
|
|
137
150
|
const client = await this.getClient();
|
|
138
151
|
|
|
@@ -190,7 +203,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
190
203
|
})
|
|
191
204
|
public override async remove(
|
|
192
205
|
payload: CartMutationItemRemove
|
|
193
|
-
): Promise<Result<
|
|
206
|
+
): Promise<Result<CartFactoryCartOutput<TFactory>>> {
|
|
194
207
|
try {
|
|
195
208
|
const client = await this.getClient();
|
|
196
209
|
const medusaId = payload.cart as MedusaCartIdentifier;
|
|
@@ -231,7 +244,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
231
244
|
})
|
|
232
245
|
public override async changeQuantity(
|
|
233
246
|
payload: CartMutationItemQuantityChange
|
|
234
|
-
): Promise<Result<
|
|
247
|
+
): Promise<Result<CartFactoryCartOutput<TFactory>>> {
|
|
235
248
|
if (payload.quantity < 1) {
|
|
236
249
|
throw new Error(
|
|
237
250
|
'Changing quantity to 0 is not allowed. Use the remove call instead.'
|
|
@@ -267,7 +280,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
267
280
|
outputSchema: CartIdentifierSchema,
|
|
268
281
|
})
|
|
269
282
|
public override async getActiveCartId(): Promise<
|
|
270
|
-
Result<
|
|
283
|
+
Result<CartFactoryIdentifierOutput<TFactory>, NotFoundError>
|
|
271
284
|
> {
|
|
272
285
|
try {
|
|
273
286
|
const client = await this.getClient();
|
|
@@ -278,12 +291,10 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
278
291
|
if (activeCartId) {
|
|
279
292
|
try {
|
|
280
293
|
await client.store.cart.retrieve(activeCartId);
|
|
281
|
-
return success(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
})
|
|
286
|
-
);
|
|
294
|
+
return success(this.factory.parseCartIdentifier(this.context, {
|
|
295
|
+
key: activeCartId,
|
|
296
|
+
region_id: (await this.medusaApi.getActiveRegion()).id,
|
|
297
|
+
}));
|
|
287
298
|
} catch {
|
|
288
299
|
// Cart doesn't exist, create new one
|
|
289
300
|
}
|
|
@@ -360,7 +371,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
360
371
|
})
|
|
361
372
|
public override async applyCouponCode(
|
|
362
373
|
payload: CartMutationApplyCoupon
|
|
363
|
-
): Promise<Result<
|
|
374
|
+
): Promise<Result<CartFactoryCartOutput<TFactory>>> {
|
|
364
375
|
try {
|
|
365
376
|
const client = await this.getClient();
|
|
366
377
|
const medusaId = payload.cart as MedusaCartIdentifier;
|
|
@@ -414,7 +425,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
414
425
|
})
|
|
415
426
|
public override async removeCouponCode(
|
|
416
427
|
payload: CartMutationRemoveCoupon
|
|
417
|
-
): Promise<Result<
|
|
428
|
+
): Promise<Result<CartFactoryCartOutput<TFactory>>> {
|
|
418
429
|
try {
|
|
419
430
|
const client = await this.getClient();
|
|
420
431
|
const medusaId = payload.cart as MedusaCartIdentifier;
|
|
@@ -468,7 +479,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
468
479
|
})
|
|
469
480
|
public override async changeCurrency(
|
|
470
481
|
payload: CartMutationChangeCurrency
|
|
471
|
-
): Promise<Result<
|
|
482
|
+
): Promise<Result<CartFactoryCartOutput<TFactory>>> {
|
|
472
483
|
try {
|
|
473
484
|
const client = await this.getClient();
|
|
474
485
|
|
|
@@ -512,7 +523,9 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
512
523
|
}
|
|
513
524
|
|
|
514
525
|
|
|
515
|
-
protected async createCart(
|
|
526
|
+
protected async createCart(
|
|
527
|
+
currency?: string,
|
|
528
|
+
): Promise<CartFactoryIdentifierOutput<TFactory>> {
|
|
516
529
|
try {
|
|
517
530
|
const client = await this.getClient();
|
|
518
531
|
|
|
@@ -524,7 +537,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
524
537
|
);
|
|
525
538
|
|
|
526
539
|
if (response.cart) {
|
|
527
|
-
const cartIdentifier =
|
|
540
|
+
const cartIdentifier = this.factory.parseCartIdentifier(this.context, {
|
|
528
541
|
key: response.cart.id,
|
|
529
542
|
region_id: response.cart.region_id,
|
|
530
543
|
});
|
|
@@ -601,7 +614,7 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
601
614
|
* @param remote
|
|
602
615
|
* @returns
|
|
603
616
|
*/
|
|
604
|
-
protected parseSingle(remote: StoreCart):
|
|
617
|
+
protected parseSingle(remote: StoreCart): CartFactoryCartOutput<TFactory> {
|
|
605
618
|
const identifier = MedusaCartIdentifierSchema.parse({
|
|
606
619
|
key: remote.id,
|
|
607
620
|
region_id: remote.region_id,
|
|
@@ -659,6 +672,6 @@ export class MedusaCartProvider extends CartProvider {
|
|
|
659
672
|
},
|
|
660
673
|
} satisfies Cart;
|
|
661
674
|
|
|
662
|
-
return result;
|
|
675
|
+
return this.factory.parseCart(this.context, result);
|
|
663
676
|
}
|
|
664
677
|
}
|
|
@@ -2,7 +2,15 @@ import type {
|
|
|
2
2
|
StoreProductCategory,
|
|
3
3
|
StoreProductCategoryListResponse,
|
|
4
4
|
} from '@medusajs/types';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
Category,
|
|
7
|
+
Cache,
|
|
8
|
+
CategoryFactory,
|
|
9
|
+
CategoryFactoryCategoryOutput,
|
|
10
|
+
CategoryFactoryPaginatedOutput,
|
|
11
|
+
CategoryFactoryWithOutput,
|
|
12
|
+
CategoryPaginatedResult,
|
|
13
|
+
} from '@reactionary/core';
|
|
6
14
|
import {
|
|
7
15
|
CategoryIdentifierSchema,
|
|
8
16
|
CategoryProvider,
|
|
@@ -28,18 +36,27 @@ import {
|
|
|
28
36
|
} from '@reactionary/core';
|
|
29
37
|
import type { MedusaAPI, MedusaConfiguration } from '../index.js';
|
|
30
38
|
import * as z from 'zod';
|
|
39
|
+
import type { MedusaCategoryFactory } from '../factories/category/category.factory.js';
|
|
31
40
|
|
|
32
|
-
export class MedusaCategoryProvider
|
|
41
|
+
export class MedusaCategoryProvider<
|
|
42
|
+
TFactory extends CategoryFactory = MedusaCategoryFactory,
|
|
43
|
+
> extends CategoryProvider<
|
|
44
|
+
CategoryFactoryCategoryOutput<TFactory>,
|
|
45
|
+
CategoryFactoryPaginatedOutput<TFactory>
|
|
46
|
+
> {
|
|
33
47
|
protected config: MedusaConfiguration;
|
|
48
|
+
protected factory: CategoryFactoryWithOutput<TFactory>;
|
|
34
49
|
|
|
35
50
|
constructor(
|
|
36
51
|
config: MedusaConfiguration,
|
|
37
52
|
cache: Cache,
|
|
38
53
|
context: RequestContext,
|
|
39
|
-
public medusaApi: MedusaAPI
|
|
54
|
+
public medusaApi: MedusaAPI,
|
|
55
|
+
factory: CategoryFactoryWithOutput<TFactory>,
|
|
40
56
|
) {
|
|
41
57
|
super(cache, context);
|
|
42
58
|
this.config = config;
|
|
59
|
+
this.factory = factory;
|
|
43
60
|
}
|
|
44
61
|
|
|
45
62
|
protected async resolveCategoryIdByExternalId(
|
|
@@ -82,7 +99,9 @@ export class MedusaCategoryProvider extends CategoryProvider {
|
|
|
82
99
|
inputSchema: CategoryQueryByIdSchema,
|
|
83
100
|
outputSchema: CategorySchema,
|
|
84
101
|
})
|
|
85
|
-
public override async getById(
|
|
102
|
+
public override async getById(
|
|
103
|
+
payload: CategoryQueryById,
|
|
104
|
+
): Promise<Result<CategoryFactoryCategoryOutput<TFactory>, NotFoundError>> {
|
|
86
105
|
const candidate = await this.resolveCategoryIdByExternalId(payload.id.key);
|
|
87
106
|
if (!candidate) {
|
|
88
107
|
return error<NotFoundError>({
|
|
@@ -107,7 +126,7 @@ export class MedusaCategoryProvider extends CategoryProvider {
|
|
|
107
126
|
})
|
|
108
127
|
public override async getBySlug(
|
|
109
128
|
payload: CategoryQueryBySlug
|
|
110
|
-
): Promise<Result<
|
|
129
|
+
): Promise<Result<CategoryFactoryCategoryOutput<TFactory>, NotFoundError>> {
|
|
111
130
|
const sdk = await this.medusaApi.getClient();
|
|
112
131
|
|
|
113
132
|
const categoryResult = await sdk.store.category.list(this.getBySlugPayload(payload));
|
|
@@ -126,7 +145,7 @@ export class MedusaCategoryProvider extends CategoryProvider {
|
|
|
126
145
|
})
|
|
127
146
|
public override async getBreadcrumbPathToCategory(
|
|
128
147
|
payload: CategoryQueryForBreadcrumb
|
|
129
|
-
): Promise<Result<
|
|
148
|
+
): Promise<Result<CategoryFactoryCategoryOutput<TFactory>[]>> {
|
|
130
149
|
const actualCategoryId = await this.resolveCategoryIdByExternalId(
|
|
131
150
|
payload.id.key
|
|
132
151
|
);
|
|
@@ -140,7 +159,7 @@ export class MedusaCategoryProvider extends CategoryProvider {
|
|
|
140
159
|
include_ancestors_tree: true,
|
|
141
160
|
});
|
|
142
161
|
|
|
143
|
-
let results = new Array<
|
|
162
|
+
let results = new Array<CategoryFactoryCategoryOutput<TFactory>>();
|
|
144
163
|
let current: StoreProductCategory | null = path.product_category;
|
|
145
164
|
while (current) {
|
|
146
165
|
results.push(this.parseSingle(current));
|
|
@@ -209,7 +228,7 @@ export class MedusaCategoryProvider extends CategoryProvider {
|
|
|
209
228
|
return success(result);
|
|
210
229
|
}
|
|
211
230
|
|
|
212
|
-
protected parseSingle(_body: StoreProductCategory):
|
|
231
|
+
protected parseSingle(_body: StoreProductCategory): CategoryFactoryCategoryOutput<TFactory> {
|
|
213
232
|
const identifier = CategoryIdentifierSchema.parse({
|
|
214
233
|
key: _body.metadata?.['external_id'] || '',
|
|
215
234
|
});
|
|
@@ -230,12 +249,12 @@ export class MedusaCategoryProvider extends CategoryProvider {
|
|
|
230
249
|
images: [],
|
|
231
250
|
} satisfies Category;
|
|
232
251
|
|
|
233
|
-
return result;
|
|
252
|
+
return this.factory.parseCategory(this.context, result);
|
|
234
253
|
}
|
|
235
254
|
|
|
236
255
|
protected parsePaginatedResult(
|
|
237
256
|
body: StoreProductCategoryListResponse
|
|
238
|
-
) {
|
|
257
|
+
): CategoryFactoryPaginatedOutput<TFactory> {
|
|
239
258
|
const items = body.product_categories.map((x) => this.parseSingle(x));
|
|
240
259
|
|
|
241
260
|
const totalPages = Math.ceil(
|
|
@@ -254,7 +273,6 @@ export class MedusaCategoryProvider extends CategoryProvider {
|
|
|
254
273
|
items: items,
|
|
255
274
|
} satisfies CategoryPaginatedResult;
|
|
256
275
|
|
|
257
|
-
return result;
|
|
276
|
+
return this.factory.parseCategoryPaginatedResult(this.context, result);
|
|
258
277
|
}
|
|
259
278
|
}
|
|
260
|
-
|