@reactionary/core 0.0.42 → 0.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/cache/memory-cache.js +39 -0
  2. package/cache/noop-cache.js +3 -13
  3. package/cache/redis-cache.js +16 -32
  4. package/decorators/reactionary.decorator.js +57 -4
  5. package/index.js +2 -1
  6. package/initialization.js +43 -0
  7. package/package.json +4 -2
  8. package/providers/base.provider.js +29 -12
  9. package/providers/index.js +2 -0
  10. package/providers/profile.provider.js +9 -0
  11. package/providers/store.provider.js +9 -0
  12. package/schemas/capabilities.schema.js +2 -1
  13. package/schemas/models/identifiers.model.js +12 -6
  14. package/schemas/models/identity.model.js +15 -16
  15. package/schemas/models/index.js +1 -0
  16. package/schemas/models/profile.model.js +3 -2
  17. package/schemas/models/shipping-method.model.js +2 -2
  18. package/schemas/models/store.model.js +11 -0
  19. package/schemas/mutations/cart.mutation.js +2 -2
  20. package/schemas/mutations/identity.mutation.js +6 -1
  21. package/schemas/mutations/index.js +1 -0
  22. package/schemas/mutations/profile.mutation.js +9 -0
  23. package/schemas/queries/index.js +2 -0
  24. package/schemas/queries/inventory.query.js +3 -5
  25. package/schemas/queries/profile.query.js +5 -0
  26. package/schemas/queries/store.query.js +11 -0
  27. package/schemas/session.schema.js +22 -8
  28. package/src/cache/cache.interface.d.ts +13 -20
  29. package/src/cache/memory-cache.d.ts +18 -0
  30. package/src/cache/noop-cache.d.ts +5 -11
  31. package/src/cache/redis-cache.d.ts +5 -11
  32. package/src/client/client-builder.d.ts +2 -2
  33. package/src/client/client.d.ts +10 -10
  34. package/src/decorators/reactionary.decorator.d.ts +34 -1
  35. package/src/index.d.ts +2 -1
  36. package/src/initialization.d.ts +2 -0
  37. package/src/providers/analytics.provider.d.ts +1 -1
  38. package/src/providers/base.provider.d.ts +12 -9
  39. package/src/providers/cart-payment.provider.d.ts +7 -7
  40. package/src/providers/cart.provider.d.ts +17 -17
  41. package/src/providers/category.provider.d.ts +9 -9
  42. package/src/providers/identity.provider.d.ts +8 -7
  43. package/src/providers/index.d.ts +2 -0
  44. package/src/providers/inventory.provider.d.ts +4 -4
  45. package/src/providers/price.provider.d.ts +6 -6
  46. package/src/providers/product.provider.d.ts +5 -5
  47. package/src/providers/profile.provider.d.ts +10 -0
  48. package/src/providers/search.provider.d.ts +4 -4
  49. package/src/providers/store.provider.d.ts +8 -0
  50. package/src/schemas/capabilities.schema.d.ts +1 -0
  51. package/src/schemas/models/analytics.model.d.ts +1 -1
  52. package/src/schemas/models/cart.model.d.ts +14 -0
  53. package/src/schemas/models/identifiers.model.d.ts +10 -6
  54. package/src/schemas/models/identity.model.d.ts +72 -27
  55. package/src/schemas/models/index.d.ts +1 -0
  56. package/src/schemas/models/inventory.model.d.ts +1 -1
  57. package/src/schemas/models/profile.model.d.ts +35 -0
  58. package/src/schemas/models/store.model.d.ts +18 -0
  59. package/src/schemas/mutations/cart-payment.mutation.d.ts +1 -1
  60. package/src/schemas/mutations/cart.mutation.d.ts +14 -0
  61. package/src/schemas/mutations/identity.mutation.d.ts +5 -0
  62. package/src/schemas/mutations/index.d.ts +1 -0
  63. package/src/schemas/mutations/profile.mutation.d.ts +6 -0
  64. package/src/schemas/queries/cart.query.d.ts +1 -1
  65. package/src/schemas/queries/identity.query.d.ts +1 -1
  66. package/src/schemas/queries/index.d.ts +2 -0
  67. package/src/schemas/queries/inventory.query.d.ts +6 -15
  68. package/src/schemas/queries/price.query.d.ts +1 -1
  69. package/src/schemas/queries/profile.query.d.ts +3 -0
  70. package/src/schemas/queries/search.query.d.ts +1 -1
  71. package/src/schemas/queries/store.query.d.ts +8 -0
  72. package/src/schemas/session.schema.d.ts +53 -21
  73. package/cache/cache-evaluation.interface.js +0 -0
  74. package/src/cache/cache-evaluation.interface.d.ts +0 -17
@@ -4,16 +4,30 @@ import { WebStoreIdentifierSchema } from "./models/identifiers.model";
4
4
  import { CurrencySchema } from "./models/currency.model";
5
5
  const LanguageContextSchema = z.looseObject({
6
6
  locale: z.string().default("en-US"),
7
- currencyCode: CurrencySchema.default(() => CurrencySchema.parse({})),
8
- countryCode: z.string().default("US")
7
+ currencyCode: CurrencySchema.default(() => CurrencySchema.parse({}))
9
8
  });
10
- const SessionSchema = z.looseObject({
11
- id: z.string(),
12
- identity: IdentitySchema.default(() => IdentitySchema.parse({})),
13
- languageContext: LanguageContextSchema.default(() => LanguageContextSchema.parse({})),
14
- storeIdentifier: WebStoreIdentifierSchema.default(() => WebStoreIdentifierSchema.parse({}))
9
+ const SessionSchema = z.record(z.string(), z.any());
10
+ const TaxJurisdictionSchema = z.object({
11
+ countryCode: z.string().default("US"),
12
+ stateCode: z.string().default(""),
13
+ countyCode: z.string().default(""),
14
+ cityCode: z.string().default("")
15
+ });
16
+ const RequestContextSchema = z.looseObject({
17
+ identity: IdentitySchema.default(() => IdentitySchema.parse({})).describe("Read/Write. The identity of the current user. Caller is responsible for persisting any changes to the identity"),
18
+ session: SessionSchema.default(() => SessionSchema.parse({})).describe("Read/Write session storage. Caller is responsible for persisting any changes. Providers will prefix own values"),
19
+ languageContext: LanguageContextSchema.default(() => LanguageContextSchema.parse({})).describe("ReadOnly. The language and locale context for the current request."),
20
+ storeIdentifier: WebStoreIdentifierSchema.default(() => WebStoreIdentifierSchema.parse({})).describe("ReadOnly. The identifier of the current web store making the request."),
21
+ taxJurisdiction: TaxJurisdictionSchema.default(() => TaxJurisdictionSchema.parse({})).describe("ReadOnly. The tax jurisdiction for the current request, typically derived from the store location or carts billing address"),
22
+ correlationId: z.string().default("").describe("A unique identifier for the request, can be used for tracing and logging purposes."),
23
+ isBot: z.boolean().default(false).describe("Indicates if the request is made by a bot or crawler."),
24
+ clientIp: z.string().default("").describe("The IP address of the client making the request, if available. Mostly for logging purposes"),
25
+ userAgent: z.string().default("").describe("The user agent string of the client making the request, if available."),
26
+ referrer: z.string().default("").describe("The referrer URL, if available.")
15
27
  });
16
28
  export {
17
29
  LanguageContextSchema,
18
- SessionSchema
30
+ RequestContextSchema,
31
+ SessionSchema,
32
+ TaxJurisdictionSchema
19
33
  };
@@ -1,4 +1,9 @@
1
- import { z } from 'zod';
1
+ import type { z } from 'zod';
2
+ import type { BaseModel } from '../schemas/models';
3
+ export interface CacheEntryOptions {
4
+ ttlSeconds: number;
5
+ dependencyIds: Array<string>;
6
+ }
2
7
  /**
3
8
  * Generic cache interface that can be implemented by different cache backends
4
9
  * (Redis, memory, file-based, etc.)
@@ -7,30 +12,18 @@ export interface Cache {
7
12
  /**
8
13
  * Retrieves a value from cache and validates it against the provided schema
9
14
  */
10
- get<T>(key: string, schema: z.ZodType<T>): Promise<T | null>;
15
+ get<T extends BaseModel>(key: string, schema: z.ZodType<T>): Promise<T | null>;
11
16
  /**
12
17
  * Stores a value in cache with optional expiration time
13
18
  */
14
- put(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
15
- /**
16
- * Removes one or more keys from cache
17
- * Supports wildcard patterns (implementation dependent)
18
- */
19
- del(keys: string | string[]): Promise<void>;
20
- /**
21
- * Finds all keys matching a pattern (implementation dependent)
22
- */
23
- keys(pattern: string): Promise<string[]>;
19
+ put(key: string, value: unknown, options: CacheEntryOptions): Promise<void>;
24
20
  /**
25
- * Clears all cache entries or entries matching a pattern
21
+ * Removes entries from the cache based on a set of dependency
22
+ * ids
26
23
  */
27
- clear(pattern?: string): Promise<void>;
24
+ invalidate(dependencyIds: Array<string>): Promise<void>;
28
25
  /**
29
- * Gets basic cache statistics (implementation dependent)
26
+ * Removes all entries from cache, wiping it completely
30
27
  */
31
- getStats(): Promise<{
32
- hits: number;
33
- misses: number;
34
- size: number;
35
- }>;
28
+ clear(): Promise<void>;
36
29
  }
@@ -0,0 +1,18 @@
1
+ import type { BaseModel } from '../schemas/models';
2
+ import type { Cache, CacheEntryOptions } from './cache.interface';
3
+ import type z from 'zod';
4
+ /**
5
+ * Memory version of the cache. Primarily useful for local development.
6
+ * This is NOT suited for production use.
7
+ */
8
+ export declare class MemoryCache implements Cache {
9
+ protected entries: {
10
+ key: string;
11
+ value: unknown;
12
+ options: CacheEntryOptions;
13
+ }[];
14
+ get<T extends BaseModel>(key: string, schema: z.ZodType<T>): Promise<T | null>;
15
+ put(key: string, value: unknown, options: CacheEntryOptions): Promise<void>;
16
+ invalidate(dependencyIds: Array<string>): Promise<void>;
17
+ clear(): Promise<void>;
18
+ }
@@ -1,18 +1,12 @@
1
- import { Cache } from './cache.interface';
2
- import z from 'zod';
1
+ import type { Cache, CacheEntryOptions } from './cache.interface';
2
+ import type z from 'zod';
3
3
  /**
4
4
  * No-op cache implementation that never stores or returns data.
5
5
  * Useful for testing or when caching should be disabled.
6
6
  */
7
7
  export declare class NoOpCache implements Cache {
8
8
  get<T>(_key: string, _schema: z.ZodType<T>): Promise<T | null>;
9
- put(_key: string, _value: unknown, _ttlSeconds?: number): Promise<void>;
10
- del(_keys: string | string[]): Promise<void>;
11
- keys(_pattern: string): Promise<string[]>;
12
- clear(_pattern?: string): Promise<void>;
13
- getStats(): Promise<{
14
- hits: number;
15
- misses: number;
16
- size: number;
17
- }>;
9
+ put(_key: string, _value: unknown, options: CacheEntryOptions): Promise<void>;
10
+ invalidate(dependencyIds: Array<string>): Promise<void>;
11
+ clear(): Promise<void>;
18
12
  }
@@ -1,17 +1,11 @@
1
1
  import { Redis } from '@upstash/redis';
2
- import { Cache } from './cache.interface';
3
- import z from 'zod';
2
+ import type { Cache, CacheEntryOptions } from './cache.interface';
3
+ import type z from 'zod';
4
4
  export declare class RedisCache implements Cache {
5
5
  protected redis: Redis;
6
6
  constructor();
7
7
  get<T>(key: string, schema: z.ZodType<T>): Promise<T | null>;
8
- put(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
9
- del(keys: string | string[]): Promise<void>;
10
- keys(pattern: string): Promise<string[]>;
11
- clear(pattern?: string): Promise<void>;
12
- getStats(): Promise<{
13
- hits: number;
14
- misses: number;
15
- size: number;
16
- }>;
8
+ put(key: string, value: unknown, options: CacheEntryOptions): Promise<void>;
9
+ invalidate(dependencyIds: Array<string>): Promise<void>;
10
+ clear(): Promise<void>;
17
11
  }
@@ -1,5 +1,5 @@
1
- import { Cache } from "../cache/cache.interface";
2
- import { Client } from "./client";
1
+ import type { Cache } from "../cache/cache.interface";
2
+ import type { Client } from "./client";
3
3
  type CapabilityFactory<T> = (cache: Cache) => T;
4
4
  type MergeCapabilities<Acc, New> = Omit<Acc, keyof New> & New;
5
5
  export declare class ClientBuilder<TClient = object> {
@@ -1,13 +1,13 @@
1
- import { AnalyticsProvider } from "../providers/analytics.provider";
2
- import { ProductProvider } from "../providers/product.provider";
3
- import { SearchProvider } from "../providers/search.provider";
4
- import { IdentityProvider } from '../providers/identity.provider';
5
- import { CartProvider } from "../providers/cart.provider";
6
- import { PriceProvider } from "../providers/price.provider";
7
- import { InventoryProvider } from "../providers/inventory.provider";
8
- import { Cache } from "../cache/cache.interface";
9
- import { CategoryProvider } from "../providers/category.provider";
10
- import { CartPaymentProvider } from "../providers";
1
+ import type { AnalyticsProvider } from "../providers/analytics.provider";
2
+ import type { ProductProvider } from "../providers/product.provider";
3
+ import type { SearchProvider } from "../providers/search.provider";
4
+ import type { IdentityProvider } from '../providers/identity.provider';
5
+ import type { CartProvider } from "../providers/cart.provider";
6
+ import type { PriceProvider } from "../providers/price.provider";
7
+ import type { InventoryProvider } from "../providers/inventory.provider";
8
+ import type { Cache } from "../cache/cache.interface";
9
+ import type { CategoryProvider } from "../providers/category.provider";
10
+ import type { CartPaymentProvider } from "../providers";
11
11
  export interface Client {
12
12
  product: ProductProvider;
13
13
  search: SearchProvider;
@@ -1 +1,34 @@
1
- export declare function Reactionary(options: unknown): MethodDecorator;
1
+ import type { BaseProvider } from '../providers';
2
+ /**
3
+ * The options associated with annotating a provider function and marking
4
+ * it as a reactionary entrypoint to be called
5
+ */
6
+ export declare class ReactionaryDecoratorOptions {
7
+ /**
8
+ * Whether or not the query is eligible for caching. Queries that depend
9
+ * heavily on personalization, for example, are likely to be a poor fit
10
+ * for caching.
11
+ */
12
+ cache: boolean;
13
+ /**
14
+ * Whether or not the cache entry should be variable based on the locale
15
+ * of the context in which it is querried.
16
+ */
17
+ localeDependentCaching: boolean;
18
+ /**
19
+ * Whether or not the cache entry should be variable based on the currency
20
+ * of the context in which it is querried.
21
+ */
22
+ currencyDependentCaching: boolean;
23
+ /**
24
+ * The number of seconds which a cache entry should be considered valid for the
25
+ * given query.
26
+ */
27
+ cacheTimeToLiveInSeconds: number;
28
+ }
29
+ /**
30
+ * Decorator for provider functions to provide functionality such as caching, tracing and type-checked
31
+ * assertion through Zod. It should only be used with publically accessible queries or mutations on
32
+ * providers.
33
+ */
34
+ export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseProvider, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
package/src/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './cache/cache.interface';
2
- export * from './cache/cache-evaluation.interface';
3
2
  export * from './cache/redis-cache';
3
+ export * from './cache/memory-cache';
4
4
  export * from './cache/noop-cache';
5
5
  export * from './client/client';
6
6
  export * from './client/client-builder';
@@ -11,3 +11,4 @@ export * from './schemas/session.schema';
11
11
  export * from './schemas/models/';
12
12
  export * from './schemas/mutations/';
13
13
  export * from './schemas/queries';
14
+ export * from './initialization';
@@ -0,0 +1,2 @@
1
+ import type { RequestContext } from "./schemas/session.schema";
2
+ export declare function createInitialRequestContext(): RequestContext;
@@ -1,4 +1,4 @@
1
- import { AnalyticsEvent } from '../schemas/models/analytics.model';
1
+ import type { AnalyticsEvent } from '../schemas/models/analytics.model';
2
2
  import { BaseProvider } from './base.provider';
3
3
  export declare abstract class AnalyticsProvider<T extends AnalyticsEvent = AnalyticsEvent> extends BaseProvider<T> {
4
4
  protected getResourceName(): string;
@@ -1,8 +1,9 @@
1
- import { z } from 'zod';
2
- import { BaseModel, createPaginatedResponseSchema } from '../schemas/models/base.model';
3
- import { Cache } from '../cache/cache.interface';
4
- import { Session } from '../schemas/session.schema';
5
- import { IdentifierType } from '../schemas/models/identifiers.model';
1
+ import type { z } from 'zod';
2
+ import type { BaseModel } from '../schemas/models/base.model';
3
+ import { createPaginatedResponseSchema } from '../schemas/models/base.model';
4
+ import type { Cache } from '../cache/cache.interface';
5
+ import type { RequestContext } from '../schemas/session.schema';
6
+ import type { IdentifierType } from '../schemas/models/identifiers.model';
6
7
  /**
7
8
  * Base capability provider, responsible for mutations (changes) and queries (fetches)
8
9
  * for a given business object domain.
@@ -24,10 +25,12 @@ export declare abstract class BaseProvider<T extends BaseModel = BaseModel> {
24
25
  * Handler for parsing a response from a remote provider and converting it
25
26
  * into the typed domain model.
26
27
  */
27
- protected parseSingle(_body: unknown, session: Session): T;
28
- protected parsePaginatedResult(_body: unknown, session: Session): z.infer<ReturnType<typeof createPaginatedResponseSchema<typeof this.schema>>>;
29
- protected generateCacheKeyPaginatedResult(resultSetName: string, res: ReturnType<typeof this.parsePaginatedResult>, session: Session): string;
30
- protected generateCacheKeySingle(identifier: IdentifierType, session: Session): string;
28
+ protected parseSingle(_body: unknown, reqCtx: RequestContext): T;
29
+ protected parsePaginatedResult(_body: unknown, reqCtx: RequestContext): z.infer<ReturnType<typeof createPaginatedResponseSchema<typeof this.schema>>>;
30
+ generateDependencyIdsForModel(model: unknown): Array<string>;
31
+ protected generateCacheKeyForQuery(scope: string, query: object): string;
32
+ protected generateCacheKeyPaginatedResult(resultSetName: string, res: ReturnType<typeof this.parsePaginatedResult>, reqCtx: RequestContext): string;
33
+ protected generateCacheKeySingle(identifier: IdentifierType, reqCtx: RequestContext): string;
31
34
  /**
32
35
  * Returns the abstract resource name provided by the remote system.
33
36
  */
@@ -1,7 +1,7 @@
1
- import { CartPaymentInstruction } from '../schemas/models/payment.model';
2
- import { CartPaymentMutationAddPayment, CartPaymentMutationCancelPayment } from '../schemas/mutations/cart-payment.mutation';
3
- import { CartPaymentQueryByCart } from '../schemas/queries/cart-payment.query';
4
- import { Session } from '../schemas/session.schema';
1
+ import type { CartPaymentInstruction } from '../schemas/models/payment.model';
2
+ import type { CartPaymentMutationAddPayment, CartPaymentMutationCancelPayment } from '../schemas/mutations/cart-payment.mutation';
3
+ import type { CartPaymentQueryByCart } from '../schemas/queries/cart-payment.query';
4
+ import type { RequestContext } from '../schemas/session.schema';
5
5
  import { BaseProvider } from './base.provider';
6
6
  export declare abstract class CartPaymentProvider<T extends CartPaymentInstruction = CartPaymentInstruction> extends BaseProvider<T> {
7
7
  /**
@@ -14,7 +14,7 @@ export declare abstract class CartPaymentProvider<T extends CartPaymentInstructi
14
14
  * @param cartIdentifier
15
15
  * @param session
16
16
  */
17
- abstract getByCartIdentifier(payload: CartPaymentQueryByCart, session: Session): Promise<T[]>;
17
+ abstract getByCartIdentifier(payload: CartPaymentQueryByCart, reqCtx: RequestContext): Promise<T[]>;
18
18
  /**
19
19
  * Calls payment provider to set up a new payment intent. Returns whatever is needed to continue the payment process, e.g. a client secret for Stripe, or a redirect URL for PayPal.
20
20
  *
@@ -25,7 +25,7 @@ export declare abstract class CartPaymentProvider<T extends CartPaymentInstructi
25
25
  * @param payload
26
26
  * @param session
27
27
  */
28
- abstract initiatePaymentForCart(payload: CartPaymentMutationAddPayment, session: Session): Promise<T>;
28
+ abstract initiatePaymentForCart(payload: CartPaymentMutationAddPayment, reqCtx: RequestContext): Promise<T>;
29
29
  /**
30
30
  * Cancel a payment instruction. This will typically void the payment intent in the payment provider, and set the status of the payment instruction to 'canceled'.
31
31
  *
@@ -37,6 +37,6 @@ export declare abstract class CartPaymentProvider<T extends CartPaymentInstructi
37
37
  * @param session
38
38
  * @returns
39
39
  */
40
- abstract cancelPaymentInstruction(payload: CartPaymentMutationCancelPayment, session: Session): Promise<T>;
40
+ abstract cancelPaymentInstruction(payload: CartPaymentMutationCancelPayment, reqCtx: RequestContext): Promise<T>;
41
41
  protected getResourceName(): string;
42
42
  }
@@ -1,9 +1,9 @@
1
1
  import { BaseProvider } from "./base.provider";
2
- import { Cart } from "../schemas/models/cart.model";
3
- import { CartQueryById } from "../schemas/queries/cart.query";
4
- import { Session } from "../schemas/session.schema";
5
- import { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationSetBillingAddress, CartMutationSetShippingInfo } from "../schemas/mutations/cart.mutation";
6
- import { CartIdentifier, OrderIdentifier } from "../schemas/models/identifiers.model";
2
+ import type { Cart } from "../schemas/models/cart.model";
3
+ import type { CartQueryById } from "../schemas/queries/cart.query";
4
+ import type { RequestContext } from "../schemas/session.schema";
5
+ import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationSetBillingAddress, CartMutationSetShippingInfo } from "../schemas/mutations/cart.mutation";
6
+ import type { CartIdentifier, OrderIdentifier } from "../schemas/models/identifiers.model";
7
7
  export declare abstract class CartProvider<T extends Cart = Cart> extends BaseProvider<T> {
8
8
  /**
9
9
  * Get cart by ID.
@@ -12,14 +12,14 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
12
12
  * @param payload
13
13
  * @param session
14
14
  */
15
- abstract getById(payload: CartQueryById, session: Session): Promise<T>;
15
+ abstract getById(payload: CartQueryById, reqCtx: RequestContext): Promise<T>;
16
16
  /**
17
17
  * Get the active cart id for the user.
18
18
  *
19
19
  * 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.
20
20
  * @param session
21
21
  */
22
- abstract getActiveCartId(session: Session): Promise<CartIdentifier>;
22
+ abstract getActiveCartId(reqCtx: RequestContext): Promise<CartIdentifier>;
23
23
  /**
24
24
  * Add item to cart. If no cart exists, create a new one. Returns the updated and recalculated cart.
25
25
  * Does not automatically consolidate items, so if you want to have second add of same item to increase quantity,
@@ -29,7 +29,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
29
29
  * @param payload
30
30
  * @param session
31
31
  */
32
- abstract add(payload: CartMutationItemAdd, session: Session): Promise<T>;
32
+ abstract add(payload: CartMutationItemAdd, reqCtx: RequestContext): Promise<T>;
33
33
  /**
34
34
  * Remove item from cart. If the cart is empty after removal, delete the cart. Returns the updated and recalculated cart.
35
35
  *
@@ -37,7 +37,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
37
37
  * @param payload
38
38
  * @param session
39
39
  */
40
- abstract remove(payload: CartMutationItemRemove, session: Session): Promise<T>;
40
+ abstract remove(payload: CartMutationItemRemove, reqCtx: RequestContext): Promise<T>;
41
41
  /**
42
42
  * Change quantity of item in cart. If the cart is empty after change, delete the cart. Returns the updated and recalculated cart.
43
43
  * Changing quantity to 0 is not allowed. Use the remove call instead. This is done to avoid accidental removal of item.
@@ -47,7 +47,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
47
47
  * @param payload
48
48
  * @param session
49
49
  */
50
- abstract changeQuantity(payload: CartMutationItemQuantityChange, session: Session): Promise<T>;
50
+ abstract changeQuantity(payload: CartMutationItemQuantityChange, reqCtx: RequestContext): Promise<T>;
51
51
  /**
52
52
  * Deletes the entire cart.
53
53
  *
@@ -55,7 +55,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
55
55
  * @param payload
56
56
  * @param session
57
57
  */
58
- abstract deleteCart(payload: CartMutationDeleteCart, session: Session): Promise<T>;
58
+ abstract deleteCart(payload: CartMutationDeleteCart, reqCtx: RequestContext): Promise<T>;
59
59
  /**
60
60
  * Sets shipping method and address on the cart. Returns the updated and recalculated cart.
61
61
  *
@@ -63,7 +63,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
63
63
  * @param payload
64
64
  * @param session
65
65
  */
66
- abstract setShippingInfo(payload: CartMutationSetShippingInfo, session: Session): Promise<T>;
66
+ abstract setShippingInfo(payload: CartMutationSetShippingInfo, reqCtx: RequestContext): Promise<T>;
67
67
  /**
68
68
  * Sets billing address on the cart. Returns the updated and recalculated cart.
69
69
  *
@@ -72,7 +72,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
72
72
  * @param payload
73
73
  * @param session
74
74
  */
75
- abstract setBillingAddress(payload: CartMutationSetBillingAddress, session: Session): Promise<T>;
75
+ abstract setBillingAddress(payload: CartMutationSetBillingAddress, reqCtx: RequestContext): Promise<T>;
76
76
  /**
77
77
  * Applies a coupon code to the cart. Returns the updated and recalculated cart.
78
78
  *
@@ -80,7 +80,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
80
80
  * @param payload
81
81
  * @param session
82
82
  */
83
- abstract applyCouponCode(payload: CartMutationApplyCoupon, session: Session): Promise<T>;
83
+ abstract applyCouponCode(payload: CartMutationApplyCoupon, reqCtx: RequestContext): Promise<T>;
84
84
  /**
85
85
  * Removes a coupon code from the cart. Returns the updated and recalculated cart.
86
86
  *
@@ -88,7 +88,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
88
88
  * @param payload
89
89
  * @param session
90
90
  */
91
- abstract removeCouponCode(payload: CartMutationRemoveCoupon, session: Session): Promise<T>;
91
+ abstract removeCouponCode(payload: CartMutationRemoveCoupon, reqCtx: RequestContext): Promise<T>;
92
92
  /**
93
93
  * Checks out the cart. Returns the order identifier of the newly created order.
94
94
  *
@@ -97,7 +97,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
97
97
  * @param payload
98
98
  * @param session
99
99
  */
100
- abstract checkout(payload: CartMutationCheckout, session: Session): Promise<OrderIdentifier>;
100
+ abstract checkout(payload: CartMutationCheckout, reqCtx: RequestContext): Promise<OrderIdentifier>;
101
101
  /**
102
102
  * Changes the currency of the cart.
103
103
  *
@@ -105,7 +105,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
105
105
  * @param newCurrency
106
106
  * @param session
107
107
  */
108
- abstract changeCurrency(payload: CartMutationChangeCurrency, session: Session): Promise<T>;
108
+ abstract changeCurrency(payload: CartMutationChangeCurrency, reqCtx: RequestContext): Promise<T>;
109
109
  protected createEmptyCart(): T;
110
110
  protected getResourceName(): string;
111
111
  }
@@ -1,6 +1,6 @@
1
- import { Category } from "../schemas/models/category.model";
2
- import { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories } from "../schemas/queries/category.query";
3
- import { Session } from "../schemas/session.schema";
1
+ import type { Category } from "../schemas/models/category.model";
2
+ import type { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories } from "../schemas/queries/category.query";
3
+ import type { RequestContext } from "../schemas/session.schema";
4
4
  import { BaseProvider } from "./base.provider";
5
5
  /**
6
6
  * CategoryProvider
@@ -22,11 +22,11 @@ export declare abstract class CategoryProvider<T extends Category = Category> ex
22
22
  * For now, the result will be en empty category, but we should probably throw an error instead.
23
23
  *
24
24
  * Use case: You have received a list of category ids from a recommendation engine, and you need to show a tile of this.
25
- * Future optimization: getByIds(ids: CategoryIdentifier[], session: Session): Promise<T[]>
25
+ * Future optimization: getByIds(ids: CategoryIdentifier[], reqCtx: RequestContext): Promise<T[]>
26
26
  * @param id
27
27
  * @param session
28
28
  */
29
- abstract getById(payload: CategoryQueryById, session: Session): Promise<T>;
29
+ abstract getById(payload: CategoryQueryById, reqCtx: RequestContext): Promise<T>;
30
30
  /**
31
31
  * Gets a single category by its seo slug
32
32
  *
@@ -34,7 +34,7 @@ export declare abstract class CategoryProvider<T extends Category = Category> ex
34
34
  * @param slug the slug
35
35
  * @param session
36
36
  */
37
- abstract getBySlug(payload: CategoryQueryBySlug, session: Session): Promise<T | null>;
37
+ abstract getBySlug(payload: CategoryQueryBySlug, reqCtx: RequestContext): Promise<T | null>;
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<T extends Category = Category> ex
43
43
  * @param id
44
44
  * @param session
45
45
  */
46
- abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, session: Session): Promise<T[]>;
46
+ abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, reqCtx: RequestContext): Promise<T[]>;
47
47
  /**
48
48
  * Finds all child categories of a given category.
49
49
  *
@@ -54,7 +54,7 @@ export declare abstract class CategoryProvider<T extends Category = Category> ex
54
54
  * @param id The ID of the parent category.
55
55
  * @param session The session information.
56
56
  */
57
- abstract findChildCategories(payload: CategoryQueryForChildCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>>;
57
+ abstract findChildCategories(payload: CategoryQueryForChildCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>>;
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<T extends Category = Category> ex
62
62
  * @param paginationOptions
63
63
  * @param session
64
64
  */
65
- abstract findTopCategories(payload: CategoryQueryForTopCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>>;
65
+ abstract findTopCategories(payload: CategoryQueryForTopCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>>;
66
66
  protected getResourceName(): string;
67
67
  }
@@ -1,11 +1,12 @@
1
- import { Identity } from "../schemas/models/identity.model";
2
- import { IdentityMutationLogin, IdentityMutationLogout } from "../schemas/mutations/identity.mutation";
3
- import { IdentityQuerySelf } from "../schemas/queries/identity.query";
4
- import { Session } from "../schemas/session.schema";
1
+ import type { Identity } from "../schemas/models/identity.model";
2
+ import type { IdentityMutationLogin, IdentityMutationLogout, IdentityMutationRegister } from "../schemas/mutations/identity.mutation";
3
+ import type { IdentityQuerySelf } from "../schemas/queries/identity.query";
4
+ import type { RequestContext } from "../schemas/session.schema";
5
5
  import { BaseProvider } from "./base.provider";
6
6
  export declare abstract class IdentityProvider<T extends Identity = Identity> extends BaseProvider<T> {
7
- abstract getSelf(payload: IdentityQuerySelf, session: Session): Promise<T>;
8
- abstract login(payload: IdentityMutationLogin, session: Session): Promise<T>;
9
- abstract logout(payload: IdentityMutationLogout, session: Session): Promise<T>;
7
+ abstract getSelf(payload: IdentityQuerySelf, reqCtx: RequestContext): Promise<T>;
8
+ abstract login(payload: IdentityMutationLogin, reqCtx: RequestContext): Promise<T>;
9
+ abstract logout(payload: IdentityMutationLogout, reqCtx: RequestContext): Promise<T>;
10
+ abstract register(payload: IdentityMutationRegister, reqCtx: RequestContext): Promise<T>;
10
11
  protected getResourceName(): string;
11
12
  }
@@ -7,4 +7,6 @@ export * from './identity.provider';
7
7
  export * from './inventory.provider';
8
8
  export * from './price.provider';
9
9
  export * from './product.provider';
10
+ export * from './profile.provider';
10
11
  export * from './search.provider';
12
+ export * from './store.provider';
@@ -1,8 +1,8 @@
1
- import { Inventory } from '../schemas/models/inventory.model';
2
- import { InventoryQuery } from '../schemas/queries/inventory.query';
3
- import { Session } from '../schemas/session.schema';
1
+ import type { Inventory } from '../schemas/models/inventory.model';
2
+ import type { InventoryQueryBySKU } from '../schemas/queries/inventory.query';
3
+ import type { RequestContext } from '../schemas/session.schema';
4
4
  import { BaseProvider } from './base.provider';
5
5
  export declare abstract class InventoryProvider<T extends Inventory = Inventory> extends BaseProvider<T> {
6
- abstract getBySKU(payload: InventoryQuery, session: Session): Promise<T>;
6
+ abstract getBySKU(payload: InventoryQueryBySKU, reqCtx: RequestContext): Promise<T>;
7
7
  protected getResourceName(): string;
8
8
  }
@@ -1,7 +1,7 @@
1
- import { Currency } from '../schemas/models/currency.model';
2
- import { Price } from '../schemas/models/price.model';
3
- import { PriceQueryBySku } from '../schemas/queries/price.query';
4
- import { Session } from '../schemas/session.schema';
1
+ import type { Currency } from '../schemas/models/currency.model';
2
+ import type { Price } from '../schemas/models/price.model';
3
+ import type { PriceQueryBySku } from '../schemas/queries/price.query';
4
+ import type { RequestContext } from '../schemas/session.schema';
5
5
  import { BaseProvider } from './base.provider';
6
6
  export declare abstract class PriceProvider<T extends Price = Price> extends BaseProvider<T> {
7
7
  /**
@@ -14,7 +14,7 @@ export declare abstract class PriceProvider<T extends Price = Price> extends Bas
14
14
  * @param payload The SKU to query
15
15
  * @param session The session information
16
16
  */
17
- abstract getBySKU(payload: PriceQueryBySku, session: Session): Promise<T>;
17
+ abstract getBySKU(payload: PriceQueryBySku, reqCtx: RequestContext): Promise<T>;
18
18
  /**
19
19
  * Fetch prices for multiple SKUs in one go.
20
20
  *
@@ -22,7 +22,7 @@ export declare abstract class PriceProvider<T extends Price = Price> extends Bas
22
22
  * @param payload The SKUs to query
23
23
  * @param session The session information
24
24
  */
25
- abstract getBySKUs(payload: PriceQueryBySku[], session: Session): Promise<T[]>;
25
+ abstract getBySKUs(payload: PriceQueryBySku[], reqCtx: RequestContext): Promise<T[]>;
26
26
  /**
27
27
  * Utility function to create an empty price result, with a value of -1.
28
28
  * This is used when no price is found for a given SKU + currency combination.
@@ -1,10 +1,10 @@
1
- import { Product } from '../schemas/models/product.model';
1
+ import type { Product } from '../schemas/models/product.model';
2
2
  import { BaseProvider } from './base.provider';
3
- import { Session } from '../schemas/session.schema';
4
- import { ProductQueryById, ProductQueryBySlug } from '../schemas/queries/product.query';
3
+ import type { RequestContext } from '../schemas/session.schema';
4
+ import type { ProductQueryById, ProductQueryBySlug } from '../schemas/queries/product.query';
5
5
  export declare abstract class ProductProvider<T extends Product = Product> extends BaseProvider<T> {
6
- abstract getById(payload: ProductQueryById, session: Session): Promise<T>;
7
- abstract getBySlug(payload: ProductQueryBySlug, session: Session): Promise<T | null>;
6
+ abstract getById(payload: ProductQueryById, reqCtx: RequestContext): Promise<T>;
7
+ abstract getBySlug(payload: ProductQueryBySlug, reqCtx: RequestContext): Promise<T | null>;
8
8
  protected createEmptyProduct(id: string): T;
9
9
  /**
10
10
  * The resource name, used for caching and logging.
@@ -0,0 +1,10 @@
1
+ import type { Profile } from '../schemas/models';
2
+ import type { ProfileMutationUpdate } from '../schemas/mutations';
3
+ import type { ProfileQuerySelf } from '../schemas/queries';
4
+ import type { RequestContext } from '../schemas/session.schema';
5
+ import { BaseProvider } from './base.provider';
6
+ export declare abstract class ProfileProvider<T extends Profile = Profile> extends BaseProvider<T> {
7
+ abstract getSelf(payload: ProfileQuerySelf, reqCtx: RequestContext): Promise<T>;
8
+ abstract update(payload: ProfileMutationUpdate, reqCtx: RequestContext): Promise<T>;
9
+ protected getResourceName(): string;
10
+ }
@@ -1,8 +1,8 @@
1
- import { SearchResult } from '../schemas/models/search.model';
2
- import { SearchQueryByTerm } from '../schemas/queries/search.query';
3
- import { Session } from '../schemas/session.schema';
1
+ import type { SearchResult } from '../schemas/models/search.model';
2
+ import type { SearchQueryByTerm } from '../schemas/queries/search.query';
3
+ import type { RequestContext } from '../schemas/session.schema';
4
4
  import { BaseProvider } from './base.provider';
5
5
  export declare abstract class SearchProvider<T extends SearchResult = SearchResult> extends BaseProvider<T> {
6
- abstract queryByTerm(payload: SearchQueryByTerm, session: Session): Promise<SearchResult>;
6
+ abstract queryByTerm(payload: SearchQueryByTerm, reqCtx: RequestContext): Promise<SearchResult>;
7
7
  protected getResourceName(): string;
8
8
  }