@reactionary/core 0.0.42 → 0.0.51

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 (101) 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/checkout.provider.js +6 -0
  10. package/providers/index.js +4 -1
  11. package/providers/order.provider.js +15 -0
  12. package/providers/profile.provider.js +9 -0
  13. package/providers/store.provider.js +9 -0
  14. package/schemas/capabilities.schema.js +4 -2
  15. package/schemas/models/cart.model.js +3 -24
  16. package/schemas/models/checkout.model.js +44 -0
  17. package/schemas/models/cost.model.js +20 -0
  18. package/schemas/models/identifiers.model.js +24 -6
  19. package/schemas/models/identity.model.js +18 -16
  20. package/schemas/models/index.js +5 -0
  21. package/schemas/models/order.model.js +37 -0
  22. package/schemas/models/payment.model.js +1 -10
  23. package/schemas/models/product.model.js +5 -2
  24. package/schemas/models/profile.model.js +3 -2
  25. package/schemas/models/shipping-method.model.js +26 -4
  26. package/schemas/models/store.model.js +11 -0
  27. package/schemas/mutations/cart.mutation.js +2 -2
  28. package/schemas/mutations/checkout.mutation.js +36 -0
  29. package/schemas/mutations/identity.mutation.js +6 -1
  30. package/schemas/mutations/index.js +2 -1
  31. package/schemas/mutations/profile.mutation.js +9 -0
  32. package/schemas/queries/checkout.query.js +16 -0
  33. package/schemas/queries/index.js +4 -1
  34. package/schemas/queries/inventory.query.js +3 -5
  35. package/schemas/queries/order.query.js +8 -0
  36. package/schemas/queries/product.query.js +5 -0
  37. package/schemas/queries/profile.query.js +5 -0
  38. package/schemas/queries/store.query.js +11 -0
  39. package/schemas/session.schema.js +22 -8
  40. package/src/cache/cache.interface.d.ts +13 -20
  41. package/src/cache/memory-cache.d.ts +18 -0
  42. package/src/cache/noop-cache.d.ts +5 -11
  43. package/src/cache/redis-cache.d.ts +5 -11
  44. package/src/client/client-builder.d.ts +2 -2
  45. package/src/client/client.d.ts +11 -11
  46. package/src/decorators/reactionary.decorator.d.ts +34 -1
  47. package/src/index.d.ts +2 -1
  48. package/src/initialization.d.ts +2 -0
  49. package/src/providers/analytics.provider.d.ts +1 -1
  50. package/src/providers/base.provider.d.ts +12 -9
  51. package/src/providers/cart.provider.d.ts +17 -17
  52. package/src/providers/category.provider.d.ts +9 -9
  53. package/src/providers/checkout.provider.d.ts +135 -0
  54. package/src/providers/identity.provider.d.ts +8 -7
  55. package/src/providers/index.d.ts +4 -1
  56. package/src/providers/inventory.provider.d.ts +4 -4
  57. package/src/providers/order.provider.d.ts +16 -0
  58. package/src/providers/price.provider.d.ts +6 -6
  59. package/src/providers/product.provider.d.ts +6 -5
  60. package/src/providers/profile.provider.d.ts +10 -0
  61. package/src/providers/search.provider.d.ts +4 -4
  62. package/src/providers/store.provider.d.ts +8 -0
  63. package/src/schemas/capabilities.schema.d.ts +3 -1
  64. package/src/schemas/models/analytics.model.d.ts +1 -1
  65. package/src/schemas/models/cart.model.d.ts +0 -2092
  66. package/src/schemas/models/checkout.model.d.ts +2930 -0
  67. package/src/schemas/models/cost.model.d.ts +1867 -0
  68. package/src/schemas/models/identifiers.model.d.ts +22 -6
  69. package/src/schemas/models/identity.model.d.ts +78 -27
  70. package/src/schemas/models/index.d.ts +5 -0
  71. package/src/schemas/models/inventory.model.d.ts +1 -1
  72. package/src/schemas/models/order.model.d.ts +3144 -0
  73. package/src/schemas/models/payment.model.d.ts +1 -438
  74. package/src/schemas/models/product.model.d.ts +2 -2
  75. package/src/schemas/models/profile.model.d.ts +35 -0
  76. package/src/schemas/models/shipping-method.model.d.ts +50 -0
  77. package/src/schemas/models/store.model.d.ts +18 -0
  78. package/src/schemas/mutations/cart.mutation.d.ts +14 -0
  79. package/src/schemas/mutations/{cart-payment.mutation.d.ts → checkout.mutation.d.ts} +74 -6
  80. package/src/schemas/mutations/identity.mutation.d.ts +5 -0
  81. package/src/schemas/mutations/index.d.ts +2 -1
  82. package/src/schemas/mutations/profile.mutation.d.ts +6 -0
  83. package/src/schemas/queries/cart.query.d.ts +1 -1
  84. package/src/schemas/queries/checkout.query.d.ts +19 -0
  85. package/src/schemas/queries/identity.query.d.ts +1 -1
  86. package/src/schemas/queries/index.d.ts +4 -1
  87. package/src/schemas/queries/inventory.query.d.ts +6 -15
  88. package/src/schemas/queries/order.query.d.ts +7 -0
  89. package/src/schemas/queries/price.query.d.ts +1 -1
  90. package/src/schemas/queries/product.query.d.ts +6 -0
  91. package/src/schemas/queries/profile.query.d.ts +3 -0
  92. package/src/schemas/queries/search.query.d.ts +1 -1
  93. package/src/schemas/queries/store.query.d.ts +8 -0
  94. package/src/schemas/session.schema.d.ts +56 -21
  95. package/cache/cache-evaluation.interface.js +0 -0
  96. package/providers/cart-payment.provider.js +0 -9
  97. package/schemas/mutations/cart-payment.mutation.js +0 -15
  98. package/schemas/queries/cart-payment.query.js +0 -11
  99. package/src/cache/cache-evaluation.interface.d.ts +0 -17
  100. package/src/providers/cart-payment.provider.d.ts +0 -42
  101. package/src/schemas/queries/cart-payment.query.d.ts +0 -16
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ import { CartIdentifierSchema, CartItemIdentifierSchema, IdentityIdentifierSchema, SKUIdentifierSchema } from "../models/identifiers.model";
3
+ import { BaseModelSchema } from "./base.model";
4
+ import { AddressSchema } from "./profile.model";
5
+ import { ShippingMethodSchema } from "./shipping-method.model";
6
+ import { CostBreakDownSchema, ItemCostBreakdownSchema } from "./cost.model";
7
+ import { PaymentInstructionSchema } from "./payment.model";
8
+ const OrderStatusSchema = z.enum(["AwaitingPayment", "ReleasedToFulfillment", "Shipped", "Cancelled"]).default("AwaitingPayment").describe("The current status of the order.");
9
+ const OrderInventoryStatusSchema = z.enum(["NotAllocated", "Allocated", "Backordered", "Preordered"]).default("Allocated").describe("The inventory release status of the order.");
10
+ const OrderItemSchema = z.looseObject({
11
+ identifier: CartItemIdentifierSchema.default(() => CartItemIdentifierSchema.parse({})),
12
+ sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
13
+ quantity: z.number().default(0),
14
+ price: ItemCostBreakdownSchema.default(() => ItemCostBreakdownSchema.parse({})),
15
+ inventoryStatus: OrderInventoryStatusSchema.default("Allocated").describe("The inventory release status of the order item.")
16
+ });
17
+ const OrderSchema = BaseModelSchema.extend({
18
+ identifier: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({})),
19
+ userId: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
20
+ items: z.array(OrderItemSchema).default(() => []),
21
+ price: CostBreakDownSchema.default(() => CostBreakDownSchema.parse({})),
22
+ name: z.string().default(""),
23
+ description: z.string().default(""),
24
+ shippingAddress: AddressSchema.optional(),
25
+ billingAddress: AddressSchema.optional(),
26
+ shippingMethod: ShippingMethodSchema.optional(),
27
+ orderStatus: OrderStatusSchema.default("AwaitingPayment"),
28
+ inventoryStatus: OrderInventoryStatusSchema.default("Allocated"),
29
+ paymentInstructions: z.array(PaymentInstructionSchema).default(() => []),
30
+ cartReference: CartIdentifierSchema.optional().describe("Reference to the cart from which this order was created.")
31
+ });
32
+ export {
33
+ OrderInventoryStatusSchema,
34
+ OrderItemSchema,
35
+ OrderSchema,
36
+ OrderStatusSchema
37
+ };
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { BaseModelSchema, ImageSchema } from "./base.model";
3
- import { CartIdentifierSchema, PaymentInstructionIdentifierSchema, PaymentMethodIdentifierSchema } from "./identifiers.model";
3
+ import { PaymentInstructionIdentifierSchema, PaymentMethodIdentifierSchema } from "./identifiers.model";
4
4
  import { MonetaryAmountSchema } from "./price.model";
5
5
  const PaymentStatusSchema = z.enum(["pending", "authorized", "canceled", "capture", "partial_capture", "refunded", "partial_refund"]);
6
6
  const PaymentProtocolDataSchema = z.looseObject({
@@ -20,16 +20,7 @@ const PaymentInstructionSchema = BaseModelSchema.extend({
20
20
  protocolData: z.array(PaymentProtocolDataSchema).default(() => []).describe("Additional protocol-specific data for processing the payment."),
21
21
  status: PaymentStatusSchema.default("pending")
22
22
  });
23
- const CartPaymentInstructionSchema = PaymentInstructionSchema.extend({
24
- cart: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({}))
25
- });
26
- const OrderPaymentInstructionSchema = PaymentInstructionSchema.extend({
27
- order: z.string().default("")
28
- // OrderIdentifierSchema
29
- });
30
23
  export {
31
- CartPaymentInstructionSchema,
32
- OrderPaymentInstructionSchema,
33
24
  PaymentInstructionSchema,
34
25
  PaymentMethodSchema,
35
26
  PaymentProtocolDataSchema,
@@ -1,8 +1,11 @@
1
1
  import { z } from "zod";
2
- import { ProductIdentifierSchema } from "./identifiers.model";
2
+ import { ProductIdentifierSchema, SKUIdentifierSchema } from "./identifiers.model";
3
3
  import { BaseModelSchema } from "./base.model";
4
4
  const SKUSchema = z.looseObject({
5
- identifier: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({}))
5
+ identifier: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({}))
6
+ /* name: z.string().default(''),
7
+ slug: z.string().default(''),
8
+ image: ImageSchema.default(() => ImageSchema.parse({})), */
6
9
  });
7
10
  const ProductAttributeSchema = z.looseObject({
8
11
  id: z.string(),
@@ -1,6 +1,7 @@
1
1
  import z from "zod";
2
2
  import { AddressIdentifierSchema, IdentityIdentifierSchema } from "./identifiers.model";
3
- const AddressSchema = z.looseObject({
3
+ import { BaseModelSchema } from "./base.model";
4
+ const AddressSchema = BaseModelSchema.extend({
4
5
  identifier: AddressIdentifierSchema.default(() => AddressIdentifierSchema.parse({})),
5
6
  firstName: z.string().default(""),
6
7
  lastName: z.string().default(""),
@@ -11,7 +12,7 @@ const AddressSchema = z.looseObject({
11
12
  postalCode: z.string().default(""),
12
13
  countryCode: z.string().default("US")
13
14
  });
14
- const ProfileSchema = z.looseObject({
15
+ const ProfileSchema = BaseModelSchema.extend({
15
16
  identifier: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
16
17
  email: z.string().email().default(""),
17
18
  phone: z.string().default(""),
@@ -1,15 +1,37 @@
1
1
  import z from "zod";
2
- import { ShippingMethodIdentifier } from "./identifiers.model";
2
+ import { ShippingMethodIdentifierSchema } from "./identifiers.model";
3
3
  import { MonetaryAmountSchema } from "./price.model";
4
- import { ImageSchema } from "./base.model";
4
+ import { BaseModelSchema, ImageSchema } from "./base.model";
5
+ import { AddressSchema } from "./profile.model";
6
+ const PickupPointSchema = z.looseObject({
7
+ identifier: z.object({
8
+ key: z.string().default("").nonoptional()
9
+ }).default(() => ({ key: "" })),
10
+ name: z.string().default(""),
11
+ description: z.string().default(""),
12
+ address: AddressSchema.default(() => AddressSchema.parse({})),
13
+ openingHours: z.string().default("").optional().describe('The opening hours of the pickup point, if applicable. This could be a string like "Mon-Fri 9am-5pm".'),
14
+ contactPhone: z.string().default("").optional().describe("The contact phone number for the pickup point, if applicable."),
15
+ contactEmail: z.string().default("").optional().describe("The contact email for the pickup point, if applicable."),
16
+ instructions: z.string().default("").optional().describe("Any special instructions for picking up from this point.")
17
+ });
5
18
  const ShippingMethodSchema = z.looseObject({
6
- identifier: ShippingMethodIdentifier.default(() => ShippingMethodIdentifier.parse({})),
19
+ identifier: ShippingMethodIdentifierSchema.default(() => ShippingMethodIdentifierSchema.parse({})),
7
20
  name: z.string().default(""),
8
21
  description: z.string().default(""),
9
22
  logo: ImageSchema.optional(),
10
23
  price: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})),
11
- deliveryTime: z.string().default("")
24
+ deliveryTime: z.string().default(""),
25
+ carrier: z.string().default("").optional()
26
+ });
27
+ const ShippingInstructionSchema = BaseModelSchema.extend({
28
+ shippingMethod: ShippingMethodIdentifierSchema.default(() => ShippingMethodIdentifierSchema.parse({})),
29
+ pickupPoint: z.string().default("").describe("An optional pickup point for the shipping method. This could be a physical store, a locker, or similar. If not set, it means home delivery to the shipping address."),
30
+ instructions: z.string().default("").describe("Optional instructions for the shipping. This could be delivery instructions, or similar."),
31
+ consentForUnattendedDelivery: z.boolean().default(false).describe("Indicates if the customer has given consent for unattended delivery, if applicable.")
12
32
  });
13
33
  export {
34
+ PickupPointSchema,
35
+ ShippingInstructionSchema,
14
36
  ShippingMethodSchema
15
37
  };
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import { BaseModelSchema } from "./base.model";
3
+ import { FulfillmentCenterIdentifierSchema, StoreIdentifierSchema } from "./identifiers.model";
4
+ const StoreSchema = BaseModelSchema.extend({
5
+ identifier: StoreIdentifierSchema.default(() => StoreIdentifierSchema.parse({})),
6
+ name: z.string().default(""),
7
+ fulfillmentCenter: FulfillmentCenterIdentifierSchema.default(() => FulfillmentCenterIdentifierSchema.parse({}))
8
+ });
9
+ export {
10
+ StoreSchema
11
+ };
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { BaseMutationSchema } from "./base.mutation";
3
- import { CartIdentifierSchema, CartItemIdentifierSchema, PaymentMethodIdentifierSchema, ShippingMethodIdentifier, SKUIdentifierSchema } from "../models/identifiers.model";
3
+ import { CartIdentifierSchema, CartItemIdentifierSchema, PaymentMethodIdentifierSchema, ShippingMethodIdentifierSchema, SKUIdentifierSchema } from "../models/identifiers.model";
4
4
  import { AddressSchema } from "../models/profile.model";
5
5
  import { CurrencySchema } from "../models/currency.model";
6
6
  import { MonetaryAmountSchema } from "../models/price.model";
@@ -23,7 +23,7 @@ const CartMutationDeleteCartSchema = BaseMutationSchema.extend({
23
23
  });
24
24
  const CartMutationSetShippingInfoSchema = BaseMutationSchema.extend({
25
25
  cart: CartIdentifierSchema.required(),
26
- shippingMethod: ShippingMethodIdentifier.optional(),
26
+ shippingMethod: ShippingMethodIdentifierSchema.optional(),
27
27
  shippingAddress: AddressSchema.optional()
28
28
  });
29
29
  const CartMutationSetBillingAddressSchema = BaseMutationSchema.extend({
@@ -0,0 +1,36 @@
1
+ import z from "zod";
2
+ import { CartIdentifierSchema, AddressSchema, PaymentInstructionIdentifierSchema, PaymentInstructionSchema, ShippingInstructionSchema } from "../models";
3
+ import { BaseMutationSchema } from "./base.mutation";
4
+ const CheckoutMutationInitiateCheckoutSchema = BaseMutationSchema.extend({
5
+ cart: CartIdentifierSchema.required(),
6
+ billingAddress: AddressSchema.omit({ identifier: true }).optional(),
7
+ notificationEmail: z.string().optional(),
8
+ notificationPhone: z.string().optional()
9
+ });
10
+ const CheckoutMutationSetShippingAddressSchema = BaseMutationSchema.extend({
11
+ checkout: CartIdentifierSchema.required(),
12
+ shippingAddress: AddressSchema.omit({ identifier: true }).required()
13
+ });
14
+ const CheckoutMutationFinalizeCheckoutSchema = BaseMutationSchema.extend({
15
+ checkout: CartIdentifierSchema.required()
16
+ });
17
+ const CheckoutMutationAddPaymentInstruction = BaseMutationSchema.extend({
18
+ paymentInstruction: PaymentInstructionSchema.omit({ meta: true, status: true, identifier: true }).required(),
19
+ checkout: CartIdentifierSchema.required()
20
+ });
21
+ const CheckoutMutationRemovePaymentInstruction = BaseMutationSchema.extend({
22
+ paymentInstruction: PaymentInstructionIdentifierSchema.required(),
23
+ checkout: CartIdentifierSchema.required()
24
+ });
25
+ const CheckoutMutationSetShippingInstruction = BaseMutationSchema.extend({
26
+ shippingInstruction: ShippingInstructionSchema.omit({ meta: true, status: true, identifier: true }).required(),
27
+ checkout: CartIdentifierSchema.required()
28
+ });
29
+ export {
30
+ CheckoutMutationAddPaymentInstruction,
31
+ CheckoutMutationFinalizeCheckoutSchema,
32
+ CheckoutMutationInitiateCheckoutSchema,
33
+ CheckoutMutationRemovePaymentInstruction,
34
+ CheckoutMutationSetShippingAddressSchema,
35
+ CheckoutMutationSetShippingInstruction
36
+ };
@@ -5,7 +5,12 @@ const IdentityMutationLoginSchema = BaseMutationSchema.extend({
5
5
  password: z.string()
6
6
  });
7
7
  const IdentityMutationLogoutSchema = BaseMutationSchema.extend({});
8
+ const IdentityMutationRegisterSchema = BaseMutationSchema.extend({
9
+ username: z.string(),
10
+ password: z.string()
11
+ });
8
12
  export {
9
13
  IdentityMutationLoginSchema,
10
- IdentityMutationLogoutSchema
14
+ IdentityMutationLogoutSchema,
15
+ IdentityMutationRegisterSchema
11
16
  };
@@ -1,9 +1,10 @@
1
1
  export * from "./analytics.mutation";
2
2
  export * from "./base.mutation";
3
- export * from "./cart-payment.mutation";
4
3
  export * from "./cart.mutation";
5
4
  export * from "./identity.mutation";
6
5
  export * from "./inventory.mutation";
7
6
  export * from "./price.mutation";
8
7
  export * from "./product.mutation";
8
+ export * from "./profile.mutation";
9
9
  export * from "./search.mutation";
10
+ export * from "./checkout.mutation";
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ import { BaseMutationSchema } from "./base.mutation";
3
+ const ProfileMutationUpdateSchema = BaseMutationSchema.extend({
4
+ email: z.email().default("base@example.com"),
5
+ phone: z.string().default("")
6
+ });
7
+ export {
8
+ ProfileMutationUpdateSchema
9
+ };
@@ -0,0 +1,16 @@
1
+ import { BaseQuerySchema } from "./base.query";
2
+ import { CheckoutIdentifierSchema } from "../models/identifiers.model";
3
+ const CheckoutQueryByIdSchema = BaseQuerySchema.extend({
4
+ identifier: CheckoutIdentifierSchema.required()
5
+ });
6
+ const CheckoutQueryForAvailableShippingMethodsSchema = BaseQuerySchema.extend({
7
+ checkout: CheckoutIdentifierSchema.required()
8
+ });
9
+ const CheckoutQueryForAvailablePaymentMethodsSchema = BaseQuerySchema.extend({
10
+ checkout: CheckoutIdentifierSchema.required()
11
+ });
12
+ export {
13
+ CheckoutQueryByIdSchema,
14
+ CheckoutQueryForAvailablePaymentMethodsSchema,
15
+ CheckoutQueryForAvailableShippingMethodsSchema
16
+ };
@@ -1,10 +1,13 @@
1
1
  export * from "./analytics.query";
2
2
  export * from "./base.query";
3
- export * from "./cart-payment.query";
4
3
  export * from "./cart.query";
5
4
  export * from "./category.query";
6
5
  export * from "./identity.query";
7
6
  export * from "./inventory.query";
8
7
  export * from "./price.query";
9
8
  export * from "./product.query";
9
+ export * from "./profile.query";
10
10
  export * from "./search.query";
11
+ export * from "./store.query";
12
+ export * from "./order.query";
13
+ export * from "./checkout.query";
@@ -1,11 +1,9 @@
1
- import { z } from "zod";
2
1
  import { BaseQuerySchema } from "./base.query";
3
- import { ProductIdentifierSchema } from "../models/identifiers.model";
2
+ import { FulfillmentCenterIdentifierSchema, ProductIdentifierSchema } from "../models/identifiers.model";
4
3
  const InventoryQueryBySKUSchema = BaseQuerySchema.extend({
5
- query: z.literal("sku"),
6
- sku: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({}))
4
+ sku: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})).nonoptional(),
5
+ fulfilmentCenter: FulfillmentCenterIdentifierSchema.default(() => FulfillmentCenterIdentifierSchema.parse({})).nonoptional()
7
6
  });
8
- ;
9
7
  export {
10
8
  InventoryQueryBySKUSchema
11
9
  };
@@ -0,0 +1,8 @@
1
+ import { BaseQuerySchema } from "./base.query";
2
+ import { OrderIdentifierSchema } from "../models/identifiers.model";
3
+ const OrderQueryByIdSchema = BaseQuerySchema.extend({
4
+ order: OrderIdentifierSchema.required()
5
+ });
6
+ export {
7
+ OrderQueryByIdSchema
8
+ };
@@ -1,12 +1,17 @@
1
1
  import { z } from "zod";
2
2
  import { BaseQuerySchema } from "./base.query";
3
+ import { SKUIdentifierSchema } from "../models";
3
4
  const ProductQueryBySlugSchema = BaseQuerySchema.extend({
4
5
  slug: z.string()
5
6
  });
6
7
  const ProductQueryByIdSchema = BaseQuerySchema.extend({
7
8
  id: z.string()
8
9
  });
10
+ const ProductQueryBySKUSchema = BaseQuerySchema.extend({
11
+ sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({}))
12
+ });
9
13
  export {
10
14
  ProductQueryByIdSchema,
15
+ ProductQueryBySKUSchema,
11
16
  ProductQueryBySlugSchema
12
17
  };
@@ -0,0 +1,5 @@
1
+ import { BaseQuerySchema } from "./base.query";
2
+ const ProfileQuerySelfSchema = BaseQuerySchema.extend({});
3
+ export {
4
+ ProfileQuerySelfSchema
5
+ };
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import { BaseQuerySchema } from "./base.query";
3
+ const StoreQueryByProximitySchema = BaseQuerySchema.extend({
4
+ longitude: z.number().default(0),
5
+ latitude: z.number().default(0),
6
+ distance: z.number().default(0),
7
+ limit: z.number().default(10)
8
+ });
9
+ export {
10
+ StoreQueryByProximitySchema
11
+ };
@@ -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,20 +1,20 @@
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 { CheckoutProvider } from "../providers";
11
11
  export interface Client {
12
12
  product: ProductProvider;
13
13
  search: SearchProvider;
14
14
  identity: IdentityProvider;
15
15
  cache: Cache;
16
16
  cart: CartProvider;
17
- cartPayment: CartPaymentProvider;
17
+ checkout: CheckoutProvider;
18
18
  analytics: Array<AnalyticsProvider>;
19
19
  price: PriceProvider;
20
20
  inventory: InventoryProvider;
@@ -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;