@reactionary/core 0.6.1 → 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/client/client-builder.js +35 -5
- package/factories/cart.factory.js +0 -0
- package/factories/category.factory.js +0 -0
- package/factories/checkout.factory.js +0 -0
- package/factories/identity.factory.js +0 -0
- package/factories/index.js +15 -0
- package/factories/inventory.factory.js +0 -0
- package/factories/order-search.factory.js +0 -0
- package/factories/order.factory.js +0 -0
- package/factories/price.factory.js +0 -0
- package/factories/product-associations.factory.js +0 -0
- package/factories/product-list.factory.js +0 -0
- package/factories/product-reviews.factory.js +0 -0
- package/factories/product-search.factory.js +0 -0
- package/factories/product.factory.js +0 -0
- package/factories/profile.factory.js +0 -0
- package/factories/store.factory.js +0 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/providers/product-search.provider.js +6 -0
- package/src/client/client-builder.d.ts +10 -1
- package/src/factories/cart.factory.d.ts +18 -0
- package/src/factories/category.factory.d.ts +17 -0
- package/src/factories/checkout.factory.d.ts +24 -0
- package/src/factories/identity.factory.d.ts +12 -0
- package/src/factories/index.d.ts +15 -0
- package/src/factories/inventory.factory.d.ts +12 -0
- package/src/factories/order-search.factory.d.ts +13 -0
- package/src/factories/order.factory.d.ts +12 -0
- package/src/factories/price.factory.d.ts +16 -0
- package/src/factories/product-associations.factory.d.ts +12 -0
- package/src/factories/product-list.factory.d.ts +27 -0
- package/src/factories/product-reviews.factory.d.ts +22 -0
- package/src/factories/product-search.factory.d.ts +13 -0
- package/src/factories/product.factory.d.ts +12 -0
- package/src/factories/profile.factory.d.ts +12 -0
- package/src/factories/store.factory.d.ts +12 -0
- package/src/index.d.ts +2 -0
- package/src/providers/cart.provider.d.ts +9 -9
- package/src/providers/category.provider.d.ts +6 -6
- package/src/providers/checkout.provider.d.ts +10 -10
- package/src/providers/identity.provider.d.ts +6 -6
- package/src/providers/inventory.provider.d.ts +3 -3
- package/src/providers/order-search.provider.d.ts +2 -2
- package/src/providers/order.provider.d.ts +3 -3
- package/src/providers/price.provider.d.ts +4 -4
- package/src/providers/product-associations.provider.d.ts +4 -4
- package/src/providers/product-list.provider.d.ts +8 -8
- package/src/providers/product-reviews.provider.d.ts +4 -4
- package/src/providers/product-search.provider.d.ts +4 -27
- package/src/providers/product.provider.d.ts +5 -5
- package/src/providers/profile.provider.d.ts +8 -8
- package/src/providers/store.provider.d.ts +2 -2
package/client/client-builder.js
CHANGED
|
@@ -7,6 +7,7 @@ import { MulticastProductRecommendationsProvider } from "../providers/product-re
|
|
|
7
7
|
class ClientBuilder {
|
|
8
8
|
constructor(context) {
|
|
9
9
|
this.factories = [];
|
|
10
|
+
this.collisionStrategy = "last-wins";
|
|
10
11
|
this.context = context;
|
|
11
12
|
}
|
|
12
13
|
withCapability(factory) {
|
|
@@ -14,6 +15,7 @@ class ClientBuilder {
|
|
|
14
15
|
newBuilder.factories = [...this.factories, factory];
|
|
15
16
|
newBuilder.cache = this.cache;
|
|
16
17
|
newBuilder.context = this.context;
|
|
18
|
+
newBuilder.collisionStrategy = this.collisionStrategy;
|
|
17
19
|
return newBuilder;
|
|
18
20
|
}
|
|
19
21
|
withCache(cache) {
|
|
@@ -21,6 +23,15 @@ class ClientBuilder {
|
|
|
21
23
|
newBuilder.factories = [...this.factories];
|
|
22
24
|
newBuilder.cache = cache;
|
|
23
25
|
newBuilder.context = this.context;
|
|
26
|
+
newBuilder.collisionStrategy = this.collisionStrategy;
|
|
27
|
+
return newBuilder;
|
|
28
|
+
}
|
|
29
|
+
withCollisionStrategy(strategy) {
|
|
30
|
+
const newBuilder = new ClientBuilder(this.context);
|
|
31
|
+
newBuilder.factories = [...this.factories];
|
|
32
|
+
newBuilder.cache = this.cache;
|
|
33
|
+
newBuilder.context = this.context;
|
|
34
|
+
newBuilder.collisionStrategy = strategy;
|
|
24
35
|
return newBuilder;
|
|
25
36
|
}
|
|
26
37
|
build() {
|
|
@@ -33,11 +44,8 @@ class ClientBuilder {
|
|
|
33
44
|
const mergedAnalytics = [];
|
|
34
45
|
const mergedProductRecommendationsProviders = [];
|
|
35
46
|
for (const factory of this.factories) {
|
|
36
|
-
const provider = factory
|
|
37
|
-
client =
|
|
38
|
-
...client,
|
|
39
|
-
...provider
|
|
40
|
-
};
|
|
47
|
+
const provider = this.resolveFactory(factory, sharedCache, this.context);
|
|
48
|
+
client = this.mergeProviders(client, provider);
|
|
41
49
|
if (provider.analytics) {
|
|
42
50
|
mergedAnalytics.push(provider.analytics);
|
|
43
51
|
}
|
|
@@ -53,6 +61,28 @@ class ClientBuilder {
|
|
|
53
61
|
};
|
|
54
62
|
return completeClient;
|
|
55
63
|
}
|
|
64
|
+
resolveFactory(factory, cache, context) {
|
|
65
|
+
if (factory.length <= 1) {
|
|
66
|
+
return factory({ cache, context });
|
|
67
|
+
}
|
|
68
|
+
return factory(cache, context);
|
|
69
|
+
}
|
|
70
|
+
mergeProviders(target, source) {
|
|
71
|
+
const result = { ...target };
|
|
72
|
+
for (const key of Object.keys(source)) {
|
|
73
|
+
const hasExisting = Object.prototype.hasOwnProperty.call(result, key);
|
|
74
|
+
if (hasExisting) {
|
|
75
|
+
if (this.collisionStrategy === "first-wins") {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (this.collisionStrategy === "throw") {
|
|
79
|
+
throw new Error(`Capability collision detected for "${key}"`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
result[key] = source[key];
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
56
86
|
}
|
|
57
87
|
export {
|
|
58
88
|
ClientBuilder
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -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";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./cache/index.js";
|
|
2
2
|
export * from "./client/index.js";
|
|
3
3
|
export * from "./decorators/index.js";
|
|
4
|
+
export * from "./factories/index.js";
|
|
4
5
|
export * from "./providers/index.js";
|
|
5
6
|
export * from "./schemas/index.js";
|
|
6
7
|
export * from "./initialization.js";
|
package/package.json
CHANGED
|
@@ -3,6 +3,12 @@ class ProductSearchProvider extends BaseProvider {
|
|
|
3
3
|
getResourceName() {
|
|
4
4
|
return "product-search";
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Parses a facet value from the search response.
|
|
8
|
+
* @param facetValueIdentifier The identifier for the facet value.
|
|
9
|
+
* @param label The label for the facet value.
|
|
10
|
+
* @param count The count for the facet value.
|
|
11
|
+
*/
|
|
6
12
|
}
|
|
7
13
|
export {
|
|
8
14
|
ProductSearchProvider
|
|
@@ -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
|
-
|
|
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 mergeProviders;
|
|
16
25
|
}
|
|
17
26
|
export {};
|
|
@@ -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 './factories/index.js';
|
|
4
5
|
export * from './providers/index.js';
|
|
5
6
|
export * from './schemas/index.js';
|
|
6
7
|
export * from './initialization.js';
|
|
8
|
+
export type { InferType } from './zod-utils.js';
|
|
@@ -8,7 +8,7 @@ import { BaseProvider } from "./base.provider.js";
|
|
|
8
8
|
/**
|
|
9
9
|
* @group Providers
|
|
10
10
|
*/
|
|
11
|
-
export declare abstract class CartProvider extends BaseProvider {
|
|
11
|
+
export declare abstract class CartProvider<TCart extends Cart = Cart, TCartIdentifier extends CartIdentifier = CartIdentifier> extends BaseProvider {
|
|
12
12
|
/**
|
|
13
13
|
* Get cart by ID.
|
|
14
14
|
*
|
|
@@ -16,14 +16,14 @@ export declare abstract class CartProvider extends BaseProvider {
|
|
|
16
16
|
* @param payload
|
|
17
17
|
* @param session
|
|
18
18
|
*/
|
|
19
|
-
abstract getById(payload: CartQueryById): Promise<Result<
|
|
19
|
+
abstract getById(payload: CartQueryById): Promise<Result<TCart, NotFoundError>>;
|
|
20
20
|
/**
|
|
21
21
|
* Get the active cart id for the user.
|
|
22
22
|
*
|
|
23
23
|
* Usecase: Most common usecase during site load, or after login. You want to get the active cart for the user, so you can display it in the minicart.
|
|
24
24
|
* @param session
|
|
25
25
|
*/
|
|
26
|
-
abstract getActiveCartId(): Promise<Result<
|
|
26
|
+
abstract getActiveCartId(): Promise<Result<TCartIdentifier, NotFoundError>>;
|
|
27
27
|
/**
|
|
28
28
|
* Add item to cart. If no cart exists, create a new one. Returns the updated and recalculated cart.
|
|
29
29
|
* Does not automatically consolidate items, so if you want to have second add of same item to increase quantity,
|
|
@@ -33,7 +33,7 @@ export declare abstract class CartProvider extends BaseProvider {
|
|
|
33
33
|
* @param payload
|
|
34
34
|
* @param session
|
|
35
35
|
*/
|
|
36
|
-
abstract add(payload: CartMutationItemAdd): Promise<Result<
|
|
36
|
+
abstract add(payload: CartMutationItemAdd): Promise<Result<TCart>>;
|
|
37
37
|
/**
|
|
38
38
|
* Remove item from cart. If the cart is empty after removal, delete the cart. Returns the updated and recalculated cart.
|
|
39
39
|
*
|
|
@@ -41,7 +41,7 @@ export declare abstract class CartProvider extends BaseProvider {
|
|
|
41
41
|
* @param payload
|
|
42
42
|
* @param session
|
|
43
43
|
*/
|
|
44
|
-
abstract remove(payload: CartMutationItemRemove): Promise<Result<
|
|
44
|
+
abstract remove(payload: CartMutationItemRemove): Promise<Result<TCart>>;
|
|
45
45
|
/**
|
|
46
46
|
* Change quantity of item in cart. If the cart is empty after change, delete the cart. Returns the updated and recalculated cart.
|
|
47
47
|
* Changing quantity to 0 is not allowed. Use the remove call instead. This is done to avoid accidental removal of item.
|
|
@@ -51,7 +51,7 @@ export declare abstract class CartProvider extends BaseProvider {
|
|
|
51
51
|
* @param payload
|
|
52
52
|
* @param session
|
|
53
53
|
*/
|
|
54
|
-
abstract changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<
|
|
54
|
+
abstract changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<TCart>>;
|
|
55
55
|
/**
|
|
56
56
|
* Deletes the entire cart.
|
|
57
57
|
*
|
|
@@ -67,7 +67,7 @@ export declare abstract class CartProvider extends BaseProvider {
|
|
|
67
67
|
* @param payload
|
|
68
68
|
* @param session
|
|
69
69
|
*/
|
|
70
|
-
abstract applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<
|
|
70
|
+
abstract applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<TCart>>;
|
|
71
71
|
/**
|
|
72
72
|
* Removes a coupon code from the cart. Returns the updated and recalculated cart.
|
|
73
73
|
*
|
|
@@ -75,7 +75,7 @@ export declare abstract class CartProvider extends BaseProvider {
|
|
|
75
75
|
* @param payload
|
|
76
76
|
* @param session
|
|
77
77
|
*/
|
|
78
|
-
abstract removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<
|
|
78
|
+
abstract removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<TCart>>;
|
|
79
79
|
/**
|
|
80
80
|
* Changes the currency of the cart.
|
|
81
81
|
*
|
|
@@ -83,6 +83,6 @@ export declare abstract class CartProvider extends BaseProvider {
|
|
|
83
83
|
* @param newCurrency
|
|
84
84
|
* @param session
|
|
85
85
|
*/
|
|
86
|
-
abstract changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<
|
|
86
|
+
abstract changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<TCart>>;
|
|
87
87
|
protected getResourceName(): string;
|
|
88
88
|
}
|
|
@@ -10,7 +10,7 @@ import { BaseProvider } from "./base.provider.js";
|
|
|
10
10
|
*
|
|
11
11
|
* @group Foo
|
|
12
12
|
*/
|
|
13
|
-
export declare abstract class CategoryProvider extends BaseProvider {
|
|
13
|
+
export declare abstract class CategoryProvider<TCategory extends Category = Category, TCategoryPaginatedResult extends CategoryPaginatedResult = CategoryPaginatedResult> extends BaseProvider {
|
|
14
14
|
/**
|
|
15
15
|
* Get a single category by its ID. Cannot return null, because HOW did you come across a categories ID that does not exist?
|
|
16
16
|
*
|
|
@@ -26,7 +26,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
|
|
|
26
26
|
* @param id
|
|
27
27
|
* @param session
|
|
28
28
|
*/
|
|
29
|
-
abstract getById(payload: CategoryQueryById): Promise<Result<
|
|
29
|
+
abstract getById(payload: CategoryQueryById): Promise<Result<TCategory, NotFoundError>>;
|
|
30
30
|
/**
|
|
31
31
|
* Gets a single category by its seo slug
|
|
32
32
|
*
|
|
@@ -34,7 +34,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
|
|
|
34
34
|
* @param slug the slug
|
|
35
35
|
* @param session
|
|
36
36
|
*/
|
|
37
|
-
abstract getBySlug(payload: CategoryQueryBySlug): Promise<Result<
|
|
37
|
+
abstract getBySlug(payload: CategoryQueryBySlug): Promise<Result<TCategory, NotFoundError>>;
|
|
38
38
|
/**
|
|
39
39
|
* Gets the breadcrumb path to the category, i.e. all parents up to the root.
|
|
40
40
|
* The returned order is from root to leaf.
|
|
@@ -43,7 +43,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
|
|
|
43
43
|
* @param id
|
|
44
44
|
* @param session
|
|
45
45
|
*/
|
|
46
|
-
abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<
|
|
46
|
+
abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<TCategory[]>>;
|
|
47
47
|
/**
|
|
48
48
|
* Finds all child categories of a given category.
|
|
49
49
|
*
|
|
@@ -54,7 +54,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
|
|
|
54
54
|
* @param id The ID of the parent category.
|
|
55
55
|
* @param session The session information.
|
|
56
56
|
*/
|
|
57
|
-
abstract findChildCategories(payload: CategoryQueryForChildCategories): Promise<Result<
|
|
57
|
+
abstract findChildCategories(payload: CategoryQueryForChildCategories): Promise<Result<TCategoryPaginatedResult>>;
|
|
58
58
|
/**
|
|
59
59
|
* Returns all top categories, i.e. categories without a parent.
|
|
60
60
|
*
|
|
@@ -62,6 +62,6 @@ export declare abstract class CategoryProvider extends BaseProvider {
|
|
|
62
62
|
* @param paginationOptions
|
|
63
63
|
* @param session
|
|
64
64
|
*/
|
|
65
|
-
abstract findTopCategories(payload: CategoryQueryForTopCategories): Promise<Result<
|
|
65
|
+
abstract findTopCategories(payload: CategoryQueryForTopCategories): Promise<Result<TCategoryPaginatedResult>>;
|
|
66
66
|
protected getResourceName(): string;
|
|
67
67
|
}
|
|
@@ -4,7 +4,7 @@ import type { CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout
|
|
|
4
4
|
import type { CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods } from "../schemas/queries/index.js";
|
|
5
5
|
import type { Result } from "../schemas/result.js";
|
|
6
6
|
import type { NotFoundError } from "../schemas/index.js";
|
|
7
|
-
export declare abstract class CheckoutProvider extends BaseProvider {
|
|
7
|
+
export declare abstract class CheckoutProvider<TCheckout extends Checkout = Checkout, TShippingMethod extends ShippingMethod = ShippingMethod, TPaymentMethod extends PaymentMethod = PaymentMethod> extends BaseProvider {
|
|
8
8
|
/**
|
|
9
9
|
* This starts a new checkout session for the given cart. The checkout might duplicate the cart, or just reference it, depending on implementation, but changes to the cart,
|
|
10
10
|
* is not reflected in the checkout, and vice versa. The checkout is a snapshot of the cart at the time of initiation.
|
|
@@ -15,7 +15,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
|
|
|
15
15
|
* @param billingAddress the billing/shipping address to start with. This affects available shipping methods, and may be required by some payment providers.
|
|
16
16
|
* @param reqCtx
|
|
17
17
|
*/
|
|
18
|
-
abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Result<
|
|
18
|
+
abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Result<TCheckout>>;
|
|
19
19
|
/**
|
|
20
20
|
* Fetches an existing checkout by its identifier.
|
|
21
21
|
*
|
|
@@ -23,7 +23,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
|
|
|
23
23
|
* @param payload
|
|
24
24
|
* @param reqCtx
|
|
25
25
|
*/
|
|
26
|
-
abstract getById(payload: CheckoutQueryById): Promise<Result<
|
|
26
|
+
abstract getById(payload: CheckoutQueryById): Promise<Result<TCheckout, NotFoundError>>;
|
|
27
27
|
/**
|
|
28
28
|
* Updates the shipping address for the checkout and recalculates the shipping methods and totals.
|
|
29
29
|
*
|
|
@@ -32,7 +32,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
|
|
|
32
32
|
* NOTE: Unsure this is really needed.
|
|
33
33
|
* @param shippingAddress The updated shipping address. Note: This may also be the billing address, if your store does not differentiate.
|
|
34
34
|
*/
|
|
35
|
-
abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Result<
|
|
35
|
+
abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Result<TCheckout>>;
|
|
36
36
|
/**
|
|
37
37
|
* Returns all available shipping methods for the given checkout. This will typically depend on the shipping address, and possibly also the items in the checkout.
|
|
38
38
|
*
|
|
@@ -41,7 +41,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
|
|
|
41
41
|
* @param checkoutId The checkout you want to get shipping methods for.
|
|
42
42
|
* @param reqCtx
|
|
43
43
|
*/
|
|
44
|
-
abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<Result<
|
|
44
|
+
abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<Result<TShippingMethod[]>>;
|
|
45
45
|
/**
|
|
46
46
|
* Returns all available payment methods for the given checkout. This will typically depend mostly on the billing address and jurisdiction.
|
|
47
47
|
*
|
|
@@ -50,20 +50,20 @@ export declare abstract class CheckoutProvider extends BaseProvider {
|
|
|
50
50
|
* @param checkoutId The checkout you want to get payment methods for.
|
|
51
51
|
* @param reqCtx
|
|
52
52
|
*/
|
|
53
|
-
abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<Result<
|
|
53
|
+
abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<Result<TPaymentMethod[]>>;
|
|
54
54
|
/**
|
|
55
55
|
* Adds a payment instruction to the checkout. This will typically create a payment intent in the payment provider, and return whatever is needed to continue the payment process, e.g. a client secret for Stripe, or a redirect URL for PayPal.
|
|
56
56
|
*
|
|
57
57
|
* Usecase: User has chosen a payment method, and you need to start the payment process.
|
|
58
58
|
*/
|
|
59
|
-
abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Result<
|
|
59
|
+
abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Result<TCheckout>>;
|
|
60
60
|
/**
|
|
61
61
|
* Removes a payment instruction from the checkout. This will typically void the payment intent in the payment provider, and remove the payment instruction from the checkout.
|
|
62
62
|
*
|
|
63
63
|
* Usecase: User has decided to change payment method, or has cancelled the payment process.
|
|
64
64
|
* @param paymentInstructionId
|
|
65
65
|
*/
|
|
66
|
-
abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Result<
|
|
66
|
+
abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Result<TCheckout>>;
|
|
67
67
|
/**
|
|
68
68
|
* Sets the shipping method and optional pickup point for the checkout. The pickup point can be a physical store, a locker, or similar.
|
|
69
69
|
* If it is unset, it means home delivery to the shipping address.
|
|
@@ -74,7 +74,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
|
|
|
74
74
|
* @param shippingMethodId
|
|
75
75
|
* @param pickupPoint
|
|
76
76
|
*/
|
|
77
|
-
abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Result<
|
|
77
|
+
abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Result<TCheckout>>;
|
|
78
78
|
/**
|
|
79
79
|
* Finalizes the checkout process. This typically involves creating an order from the checkout and processing payment.
|
|
80
80
|
*
|
|
@@ -83,7 +83,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
|
|
|
83
83
|
* @param payload
|
|
84
84
|
* @param reqCtx
|
|
85
85
|
*/
|
|
86
|
-
abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Result<
|
|
86
|
+
abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Result<TCheckout>>;
|
|
87
87
|
getResourceName(): string;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
@@ -3,11 +3,11 @@ import type { IdentityMutationLogin, IdentityMutationLogout, IdentityMutationReg
|
|
|
3
3
|
import type { IdentityQuerySelf } from "../schemas/queries/identity.query.js";
|
|
4
4
|
import type { Result } from "../schemas/result.js";
|
|
5
5
|
import { BaseProvider } from "./base.provider.js";
|
|
6
|
-
export declare abstract class IdentityProvider extends BaseProvider {
|
|
7
|
-
abstract getSelf(payload: IdentityQuerySelf): Promise<Result<
|
|
8
|
-
abstract login(payload: IdentityMutationLogin): Promise<Result<
|
|
9
|
-
abstract logout(payload: IdentityMutationLogout): Promise<Result<
|
|
10
|
-
abstract register(payload: IdentityMutationRegister): Promise<Result<
|
|
6
|
+
export declare abstract class IdentityProvider<TIdentity extends Identity = Identity> extends BaseProvider {
|
|
7
|
+
abstract getSelf(payload: IdentityQuerySelf): Promise<Result<TIdentity>>;
|
|
8
|
+
abstract login(payload: IdentityMutationLogin): Promise<Result<TIdentity>>;
|
|
9
|
+
abstract logout(payload: IdentityMutationLogout): Promise<Result<TIdentity>>;
|
|
10
|
+
abstract register(payload: IdentityMutationRegister): Promise<Result<TIdentity>>;
|
|
11
11
|
protected getResourceName(): string;
|
|
12
|
-
protected updateIdentityContext(identity:
|
|
12
|
+
protected updateIdentityContext(identity: TIdentity): void;
|
|
13
13
|
}
|
|
@@ -4,8 +4,8 @@ import type { Inventory } from '../schemas/models/inventory.model.js';
|
|
|
4
4
|
import type { InventoryQueryBySKU } from '../schemas/queries/inventory.query.js';
|
|
5
5
|
import type { Result } from '../schemas/result.js';
|
|
6
6
|
import { BaseProvider } from './base.provider.js';
|
|
7
|
-
export declare abstract class InventoryProvider extends BaseProvider {
|
|
8
|
-
abstract getBySKU(payload: InventoryQueryBySKU): Promise<Result<
|
|
7
|
+
export declare abstract class InventoryProvider<TInventory extends Inventory = Inventory> extends BaseProvider {
|
|
8
|
+
abstract getBySKU(payload: InventoryQueryBySKU): Promise<Result<TInventory, NotFoundError>>;
|
|
9
9
|
protected getResourceName(): string;
|
|
10
|
-
protected createEmptyInventory(key: InventoryIdentifier):
|
|
10
|
+
protected createEmptyInventory(key: InventoryIdentifier): TInventory;
|
|
11
11
|
}
|
|
@@ -8,7 +8,7 @@ import { BaseProvider } from "./base.provider.js";
|
|
|
8
8
|
*
|
|
9
9
|
* Usecase: An e-commerce platform wants to provide customers with a way to search through their past orders using filters like date range, order status, or total amount spent.
|
|
10
10
|
*/
|
|
11
|
-
export declare abstract class OrderSearchProvider extends BaseProvider {
|
|
11
|
+
export declare abstract class OrderSearchProvider<TOrderSearchResult extends OrderSearchResult = OrderSearchResult> extends BaseProvider {
|
|
12
12
|
protected getResourceName(): string;
|
|
13
13
|
/**
|
|
14
14
|
* Queries orders based on the provided search criteria.
|
|
@@ -17,5 +17,5 @@ export declare abstract class OrderSearchProvider extends BaseProvider {
|
|
|
17
17
|
* Usecase: A widget on the frontpage after login, shows the last 5 orders placed by the customer.
|
|
18
18
|
* @param payload The search criteria for querying orders.
|
|
19
19
|
*/
|
|
20
|
-
abstract queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<
|
|
20
|
+
abstract queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<TOrderSearchResult>>;
|
|
21
21
|
}
|
|
@@ -3,7 +3,7 @@ import type { Order } from '../schemas/models/index.js';
|
|
|
3
3
|
import type { OrderQueryById } from '../schemas/queries/index.js';
|
|
4
4
|
import type { Result } from '../schemas/result.js';
|
|
5
5
|
import type { NotFoundError } from '../schemas/index.js';
|
|
6
|
-
export declare abstract class OrderProvider extends BaseProvider {
|
|
6
|
+
export declare abstract class OrderProvider<TOrder extends Order = Order> extends BaseProvider {
|
|
7
7
|
/**
|
|
8
8
|
* Get order by ID.
|
|
9
9
|
*
|
|
@@ -11,7 +11,7 @@ export declare abstract class OrderProvider extends BaseProvider {
|
|
|
11
11
|
* @param payload
|
|
12
12
|
* @param session
|
|
13
13
|
*/
|
|
14
|
-
abstract getById(payload: OrderQueryById): Promise<Result<
|
|
15
|
-
protected createEmptyOrder():
|
|
14
|
+
abstract getById(payload: OrderQueryById): Promise<Result<TOrder, NotFoundError>>;
|
|
15
|
+
protected createEmptyOrder(): TOrder;
|
|
16
16
|
protected getResourceName(): string;
|
|
17
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Price, Result } from '../schemas/index.js';
|
|
2
2
|
import type { CustomerPriceQuery, ListPriceQuery } from '../schemas/queries/price.query.js';
|
|
3
3
|
import { BaseProvider } from './base.provider.js';
|
|
4
|
-
export declare abstract class PriceProvider extends BaseProvider {
|
|
4
|
+
export declare abstract class PriceProvider<TPrice extends Price = Price> extends BaseProvider {
|
|
5
5
|
/**
|
|
6
6
|
* Get a list price price by SKU. This is the most general, undiscounted price and is typically
|
|
7
7
|
* used as the "before" price in most ecommerce setups.
|
|
@@ -10,7 +10,7 @@ export declare abstract class PriceProvider extends BaseProvider {
|
|
|
10
10
|
* @param payload The SKU to query
|
|
11
11
|
* @param session The session information
|
|
12
12
|
*/
|
|
13
|
-
abstract getListPrice(payload: ListPriceQuery): Promise<Result<
|
|
13
|
+
abstract getListPrice(payload: ListPriceQuery): Promise<Result<TPrice>>;
|
|
14
14
|
/**
|
|
15
15
|
* Get a customer-specific price by SKU.
|
|
16
16
|
*
|
|
@@ -20,7 +20,7 @@ export declare abstract class PriceProvider extends BaseProvider {
|
|
|
20
20
|
* @param payload The SKU to query
|
|
21
21
|
* @param session The session information
|
|
22
22
|
*/
|
|
23
|
-
abstract getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<
|
|
23
|
+
abstract getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<TPrice>>;
|
|
24
24
|
/**
|
|
25
25
|
* Utility function to create an empty price result, with a value of -1.
|
|
26
26
|
* This is used when no price is found for a given SKU + currency combination.
|
|
@@ -29,6 +29,6 @@ export declare abstract class PriceProvider extends BaseProvider {
|
|
|
29
29
|
* @param currency
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
protected createEmptyPriceResult(sku: string):
|
|
32
|
+
protected createEmptyPriceResult(sku: string): TPrice;
|
|
33
33
|
protected getResourceName(): string;
|
|
34
34
|
}
|
|
@@ -7,7 +7,7 @@ import type { ProductAssociation } from '../schemas/models/product-associations.
|
|
|
7
7
|
* accessories, spareparts, and replacements. These associations are typically used to provide recommendations to customers on the product detail page, but can also be used in other contexts such as the cart or post-purchase, but
|
|
8
8
|
* do not carry any personalization concept to them.
|
|
9
9
|
*/
|
|
10
|
-
export declare abstract class ProductAssociationsProvider extends BaseProvider {
|
|
10
|
+
export declare abstract class ProductAssociationsProvider<TProductAssociation extends ProductAssociation = ProductAssociation> extends BaseProvider {
|
|
11
11
|
/**
|
|
12
12
|
* Returns a list of product identifiers which are accessories to the given product.
|
|
13
13
|
* Accessories in are products in their own right, but are commonly purchased alongside or recommended as complementary to the main product. Examples of accessories include:
|
|
@@ -20,7 +20,7 @@ export declare abstract class ProductAssociationsProvider extends BaseProvider {
|
|
|
20
20
|
*
|
|
21
21
|
* TODO: This should be a PaginatedResult
|
|
22
22
|
*/
|
|
23
|
-
abstract getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<
|
|
23
|
+
abstract getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<TProductAssociation[]>>;
|
|
24
24
|
/**
|
|
25
25
|
* Returns a list of product identifiers which are spareparts to the given product.
|
|
26
26
|
* Spareparts are products which are necessary for the use of the main product, but are not typically purchased alongside it. Examples of spareparts include:
|
|
@@ -30,13 +30,13 @@ export declare abstract class ProductAssociationsProvider extends BaseProvider {
|
|
|
30
30
|
*
|
|
31
31
|
* TODO: This should be a PaginatedResult
|
|
32
32
|
*/
|
|
33
|
-
abstract getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<
|
|
33
|
+
abstract getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<TProductAssociation[]>>;
|
|
34
34
|
/**
|
|
35
35
|
* This product is replaced by these equivalent or newer products
|
|
36
36
|
*
|
|
37
37
|
* TODO: This should be a PaginatedResult
|
|
38
38
|
* @param query
|
|
39
39
|
*/
|
|
40
|
-
abstract getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<
|
|
40
|
+
abstract getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<TProductAssociation[]>>;
|
|
41
41
|
getResourceName(): string;
|
|
42
42
|
}
|
|
@@ -12,21 +12,21 @@ import { BaseProvider } from "./base.provider.js";
|
|
|
12
12
|
*
|
|
13
13
|
* Some systems might only support single entries of each type, but the general case is to support multiples.
|
|
14
14
|
*/
|
|
15
|
-
export declare abstract class ProductListProvider extends BaseProvider {
|
|
15
|
+
export declare abstract class ProductListProvider<TProductList extends ProductList = ProductList, TProductListItem extends ProductListItem = ProductListItem, TProductListPaginatedResult extends ProductListPaginatedResult = ProductListPaginatedResult, TProductListItemPaginatedResult extends ProductListItemPaginatedResult = ProductListItemPaginatedResult> extends BaseProvider {
|
|
16
16
|
protected getResourceName(): string;
|
|
17
17
|
/**
|
|
18
18
|
* Usecase: in the frontend you want to fetch a specific list, for example a specific wishlist, to show the details of the list, such as the name, description, image, etc.
|
|
19
19
|
* you might have stored the identifier from an earlier session or looked it up previously.
|
|
20
20
|
* @param payload
|
|
21
21
|
*/
|
|
22
|
-
abstract getById(payload: ProductListQueryById): Promise<Result<
|
|
22
|
+
abstract getById(payload: ProductListQueryById): Promise<Result<TProductList>>;
|
|
23
23
|
/**
|
|
24
24
|
* Usecase: in the frontend you want to see if the customer already has a favorite list or wishlist, to which the product can be added.
|
|
25
25
|
* In complex scenarios you might want to fetch a list of wishlists, and allow customer to pick which one to add the product-variant to.
|
|
26
26
|
*
|
|
27
27
|
* @param query
|
|
28
28
|
*/
|
|
29
|
-
abstract queryLists(query: ProductListQuery): Promise<Result<
|
|
29
|
+
abstract queryLists(query: ProductListQuery): Promise<Result<TProductListPaginatedResult>>;
|
|
30
30
|
/**
|
|
31
31
|
* Usecase: in the frontend, if customer has clicked the "add to favorites list", and you have used the queryLists to find out there is no
|
|
32
32
|
* preexistiing list, you can use this method to create a new favorite list.
|
|
@@ -35,13 +35,13 @@ export declare abstract class ProductListProvider extends BaseProvider {
|
|
|
35
35
|
* which the customer can then add the product to.
|
|
36
36
|
* @param mutation
|
|
37
37
|
*/
|
|
38
|
-
abstract addList(mutation: ProductListMutationCreate): Promise<Result<
|
|
38
|
+
abstract addList(mutation: ProductListMutationCreate): Promise<Result<TProductList>>;
|
|
39
39
|
/**
|
|
40
40
|
*
|
|
41
41
|
* Usecase: update name of list, or other metadata related to the list, such as "this is my summer wishlist", or "this is my favorite list for cameras".
|
|
42
42
|
* @param mutation
|
|
43
43
|
*/
|
|
44
|
-
abstract updateList(mutation: ProductListMutationUpdate): Promise<Result<
|
|
44
|
+
abstract updateList(mutation: ProductListMutationUpdate): Promise<Result<TProductList>>;
|
|
45
45
|
/**
|
|
46
46
|
* Usecase: customer wants to delete a list, such as "delete my summer wishlist", including all the product list items
|
|
47
47
|
* @param mutation
|
|
@@ -51,12 +51,12 @@ export declare abstract class ProductListProvider extends BaseProvider {
|
|
|
51
51
|
* Usecase: in the frontend you want to show a list of the products in the customers wishlist.
|
|
52
52
|
* @param query
|
|
53
53
|
*/
|
|
54
|
-
abstract queryListItems(query: ProductListItemsQuery): Promise<Result<
|
|
54
|
+
abstract queryListItems(query: ProductListItemsQuery): Promise<Result<TProductListItemPaginatedResult>>;
|
|
55
55
|
/**
|
|
56
56
|
* Usecase: Add a new product-variant to a list
|
|
57
57
|
* @param mutation
|
|
58
58
|
*/
|
|
59
|
-
abstract addItem(mutation: ProductListItemMutationCreate): Promise<Result<
|
|
59
|
+
abstract addItem(mutation: ProductListItemMutationCreate): Promise<Result<TProductListItem>>;
|
|
60
60
|
/**
|
|
61
61
|
* Usecase: Remove a product-variant from a list.
|
|
62
62
|
* @param mutation
|
|
@@ -66,5 +66,5 @@ export declare abstract class ProductListProvider extends BaseProvider {
|
|
|
66
66
|
* Usecase: Update the quantity of a product-variant in a list.
|
|
67
67
|
* @param mutation
|
|
68
68
|
*/
|
|
69
|
-
abstract updateItem(mutation: ProductListItemMutationUpdate): Promise<Result<
|
|
69
|
+
abstract updateItem(mutation: ProductListItemMutationUpdate): Promise<Result<TProductListItem>>;
|
|
70
70
|
}
|
|
@@ -8,28 +8,28 @@ import { type ProductRatingIdentifier } from '../schemas/models/identifiers.mode
|
|
|
8
8
|
* Reviews contain ratings along with textual feedback, author information, and verification status.
|
|
9
9
|
* This provider also handles aggregated rating summaries for products.
|
|
10
10
|
*/
|
|
11
|
-
export declare abstract class ProductReviewsProvider extends BaseProvider {
|
|
11
|
+
export declare abstract class ProductReviewsProvider<TProductRatingSummary extends ProductRatingSummary = ProductRatingSummary, TProductReviewPaginatedResult extends ProductReviewPaginatedResult = ProductReviewPaginatedResult, TProductReview extends ProductReview = ProductReview> extends BaseProvider {
|
|
12
12
|
/**
|
|
13
13
|
* Get the rating summary for a product, including average rating and distribution.
|
|
14
14
|
*
|
|
15
15
|
* Usecase: Display rating summary on product detail pages or product listing pages.
|
|
16
16
|
* @param query The product to get ratings for
|
|
17
17
|
*/
|
|
18
|
-
abstract getRatingSummary(query: ProductReviewsGetRatingSummaryQuery): Promise<Result<
|
|
18
|
+
abstract getRatingSummary(query: ProductReviewsGetRatingSummaryQuery): Promise<Result<TProductRatingSummary>>;
|
|
19
19
|
/**
|
|
20
20
|
* Get a paginated list of reviews for a product.
|
|
21
21
|
*
|
|
22
22
|
* Usecase: Display customer reviews on product detail pages with filtering and sorting options.
|
|
23
23
|
* @param query The query parameters including product, pagination, sorting, and filtering options
|
|
24
24
|
*/
|
|
25
|
-
abstract findReviews(query: ProductReviewsListQuery): Promise<Result<
|
|
25
|
+
abstract findReviews(query: ProductReviewsListQuery): Promise<Result<TProductReviewPaginatedResult>>;
|
|
26
26
|
/**
|
|
27
27
|
* Submit a review for a product.
|
|
28
28
|
*
|
|
29
29
|
* Usecase: Allow customers to submit detailed reviews with ratings for products they have purchased.
|
|
30
30
|
* @param mutation The review submission data including rating, title, and content
|
|
31
31
|
*/
|
|
32
|
-
abstract submitReview(mutation: ProductReviewMutationSubmit): Promise<Result<
|
|
32
|
+
abstract submitReview(mutation: ProductReviewMutationSubmit): Promise<Result<TProductReview>>;
|
|
33
33
|
protected createEmptyProductRatingSummary(key: ProductRatingIdentifier): ProductRatingSummary;
|
|
34
34
|
getResourceName(): string;
|
|
35
35
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ProductSearchResult
|
|
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
4
|
import { BaseProvider } from './base.provider.js';
|
|
5
|
-
export declare abstract class ProductSearchProvider extends BaseProvider {
|
|
5
|
+
export declare abstract class ProductSearchProvider<TProductSearchResult extends ProductSearchResult = ProductSearchResult> extends BaseProvider {
|
|
6
6
|
protected getResourceName(): string;
|
|
7
|
-
abstract queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<
|
|
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
|
}
|
|
@@ -3,7 +3,7 @@ import { BaseProvider } from './base.provider.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 ProductProvider<TProduct extends Product = Product> extends BaseProvider {
|
|
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<
|
|
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<
|
|
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<
|
|
36
|
-
protected createEmptyProduct(id: string):
|
|
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
|
|
@@ -4,14 +4,14 @@ import type { ProfileMutationAddShippingAddress, ProfileMutationMakeShippingAddr
|
|
|
4
4
|
import type { ProfileQuerySelf as ProfileQueryById } from '../schemas/queries/index.js';
|
|
5
5
|
import type { Result } from '../schemas/result.js';
|
|
6
6
|
import { BaseProvider } from './base.provider.js';
|
|
7
|
-
export declare abstract class ProfileProvider extends BaseProvider {
|
|
7
|
+
export declare abstract class ProfileProvider<TProfile extends Profile = Profile> extends BaseProvider {
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
69
|
+
abstract setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<TProfile, NotFoundError>>;
|
|
70
70
|
protected getResourceName(): string;
|
|
71
71
|
}
|
|
@@ -2,7 +2,7 @@ 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
4
|
import { BaseProvider } from './base.provider.js';
|
|
5
|
-
export declare abstract class StoreProvider extends BaseProvider {
|
|
6
|
-
abstract queryByProximity(payload: StoreQueryByProximity): Promise<Result<Array<
|
|
5
|
+
export declare abstract class StoreProvider<TStore extends Store = Store> extends BaseProvider {
|
|
6
|
+
abstract queryByProximity(payload: StoreQueryByProximity): Promise<Result<Array<TStore>>>;
|
|
7
7
|
protected getResourceName(): string;
|
|
8
8
|
}
|