@reactionary/source 0.0.41 → 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 (125) hide show
  1. package/.claude/settings.local.json +28 -0
  2. package/.env-template +8 -5
  3. package/.vscode/settings.json +5 -0
  4. package/README.md +41 -0
  5. package/core/package.json +3 -1
  6. package/core/src/cache/cache.interface.ts +14 -18
  7. package/core/src/cache/memory-cache.ts +56 -0
  8. package/core/src/cache/noop-cache.ts +5 -23
  9. package/core/src/cache/redis-cache.ts +28 -38
  10. package/core/src/client/client-builder.ts +3 -3
  11. package/core/src/client/client.ts +11 -9
  12. package/core/src/decorators/reactionary.decorator.ts +80 -8
  13. package/core/src/index.ts +5 -29
  14. package/core/src/initialization.ts +43 -0
  15. package/core/src/providers/analytics.provider.ts +1 -1
  16. package/core/src/providers/base.provider.ts +61 -25
  17. package/core/src/providers/cart-payment.provider.ts +57 -0
  18. package/core/src/providers/cart.provider.ts +131 -8
  19. package/core/src/providers/category.provider.ts +9 -9
  20. package/core/src/providers/identity.provider.ts +8 -7
  21. package/core/src/providers/index.ts +12 -0
  22. package/core/src/providers/inventory.provider.ts +4 -4
  23. package/core/src/providers/price.provider.ts +7 -7
  24. package/core/src/providers/product.provider.ts +17 -5
  25. package/core/src/providers/profile.provider.ts +22 -0
  26. package/core/src/providers/search.provider.ts +4 -4
  27. package/core/src/providers/store.provider.ts +14 -0
  28. package/core/src/schemas/capabilities.schema.ts +3 -1
  29. package/core/src/schemas/models/analytics.model.ts +1 -1
  30. package/core/src/schemas/models/cart.model.ts +16 -3
  31. package/core/src/schemas/models/identifiers.model.ts +90 -22
  32. package/core/src/schemas/models/identity.model.ts +23 -7
  33. package/core/src/schemas/models/index.ts +15 -0
  34. package/core/src/schemas/models/payment.model.ts +41 -0
  35. package/core/src/schemas/models/profile.model.ts +35 -0
  36. package/core/src/schemas/models/shipping-method.model.ts +14 -0
  37. package/core/src/schemas/models/store.model.ts +11 -0
  38. package/core/src/schemas/mutations/cart-payment.mutation.ts +21 -0
  39. package/core/src/schemas/mutations/cart.mutation.ts +62 -3
  40. package/core/src/schemas/mutations/identity.mutation.ts +8 -1
  41. package/core/src/schemas/mutations/index.ts +10 -0
  42. package/core/src/schemas/mutations/profile.mutation.ts +9 -0
  43. package/core/src/schemas/queries/cart-payment.query.ts +12 -0
  44. package/core/src/schemas/queries/cart.query.ts +1 -1
  45. package/core/src/schemas/queries/identity.query.ts +1 -1
  46. package/core/src/schemas/queries/index.ts +3 -0
  47. package/core/src/schemas/queries/inventory.query.ts +4 -12
  48. package/core/src/schemas/queries/price.query.ts +1 -1
  49. package/core/src/schemas/queries/profile.query.ts +7 -0
  50. package/core/src/schemas/queries/search.query.ts +1 -1
  51. package/core/src/schemas/queries/store.query.ts +11 -0
  52. package/core/src/schemas/session.schema.ts +31 -6
  53. package/eslint.config.mjs +7 -0
  54. package/examples/next/src/app/page.tsx +4 -12
  55. package/examples/node/package.json +1 -3
  56. package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +9 -8
  57. package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +4 -3
  58. package/examples/node/src/basic/basic-node-setup.spec.ts +4 -5
  59. package/nx.json +1 -0
  60. package/otel/src/metrics.ts +2 -1
  61. package/otel/src/provider-instrumentation.ts +2 -1
  62. package/otel/src/tracer.ts +7 -6
  63. package/otel/src/trpc-middleware.ts +3 -2
  64. package/package.json +2 -1
  65. package/providers/algolia/src/core/initialize.ts +4 -3
  66. package/providers/algolia/src/providers/product.provider.ts +15 -13
  67. package/providers/algolia/src/providers/search.provider.ts +9 -9
  68. package/providers/algolia/src/schema/capabilities.schema.ts +1 -1
  69. package/providers/algolia/src/test/search.provider.spec.ts +10 -10
  70. package/providers/algolia/src/test/test-utils.ts +9 -4
  71. package/providers/commercetools/README.md +27 -0
  72. package/providers/commercetools/src/core/client.ts +164 -117
  73. package/providers/commercetools/src/core/initialize.ts +24 -14
  74. package/providers/commercetools/src/providers/cart-payment.provider.ts +193 -0
  75. package/providers/commercetools/src/providers/cart.provider.ts +402 -125
  76. package/providers/commercetools/src/providers/category.provider.ts +35 -35
  77. package/providers/commercetools/src/providers/identity.provider.ts +23 -75
  78. package/providers/commercetools/src/providers/index.ts +2 -0
  79. package/providers/commercetools/src/providers/inventory.provider.ts +69 -40
  80. package/providers/commercetools/src/providers/price.provider.ts +79 -47
  81. package/providers/commercetools/src/providers/product.provider.ts +36 -30
  82. package/providers/commercetools/src/providers/profile.provider.ts +61 -0
  83. package/providers/commercetools/src/providers/search.provider.ts +16 -12
  84. package/providers/commercetools/src/providers/store.provider.ts +78 -0
  85. package/providers/commercetools/src/schema/capabilities.schema.ts +3 -1
  86. package/providers/commercetools/src/schema/commercetools.schema.ts +18 -0
  87. package/providers/commercetools/src/schema/configuration.schema.ts +2 -1
  88. package/providers/commercetools/src/test/cart-payment.provider.spec.ts +145 -0
  89. package/providers/commercetools/src/test/cart.provider.spec.ts +82 -22
  90. package/providers/commercetools/src/test/category.provider.spec.ts +18 -17
  91. package/providers/commercetools/src/test/identity.provider.spec.ts +88 -0
  92. package/providers/commercetools/src/test/inventory.provider.spec.ts +41 -0
  93. package/providers/commercetools/src/test/price.provider.spec.ts +9 -8
  94. package/providers/commercetools/src/test/product.provider.spec.ts +33 -5
  95. package/providers/commercetools/src/test/profile.provider.spec.ts +49 -0
  96. package/providers/commercetools/src/test/search.provider.spec.ts +8 -7
  97. package/providers/commercetools/src/test/store.provider.spec.ts +37 -0
  98. package/providers/commercetools/src/test/test-utils.ts +7 -31
  99. package/providers/fake/src/core/initialize.ts +96 -38
  100. package/providers/fake/src/providers/analytics.provider.ts +6 -5
  101. package/providers/fake/src/providers/cart.provider.ts +66 -19
  102. package/providers/fake/src/providers/category.provider.ts +12 -12
  103. package/providers/fake/src/providers/identity.provider.ts +22 -14
  104. package/providers/fake/src/providers/index.ts +1 -0
  105. package/providers/fake/src/providers/inventory.provider.ts +13 -13
  106. package/providers/fake/src/providers/price.provider.ts +13 -13
  107. package/providers/fake/src/providers/product.provider.ts +13 -10
  108. package/providers/fake/src/providers/search.provider.ts +7 -5
  109. package/providers/fake/src/providers/store.provider.ts +47 -0
  110. package/providers/fake/src/schema/capabilities.schema.ts +4 -1
  111. package/providers/fake/src/test/cart.provider.spec.ts +18 -18
  112. package/providers/fake/src/test/category.provider.spec.ts +55 -37
  113. package/providers/fake/src/test/price.provider.spec.ts +9 -14
  114. package/providers/fake/src/test/product.provider.spec.ts +27 -0
  115. package/providers/fake/src/test/test-utils.ts +2 -28
  116. package/providers/posthog/src/core/initialize.ts +3 -3
  117. package/providers/posthog/src/schema/capabilities.schema.ts +1 -1
  118. package/trpc/src/client.ts +42 -41
  119. package/trpc/src/index.ts +4 -3
  120. package/trpc/src/integration.spec.ts +11 -11
  121. package/trpc/src/server.ts +26 -24
  122. package/trpc/src/test-utils.ts +9 -4
  123. package/trpc/src/types.ts +24 -22
  124. package/core/src/cache/cache-evaluation.interface.ts +0 -19
  125. package/examples/node/src/test-utils.ts +0 -26
@@ -0,0 +1,37 @@
1
+ import 'dotenv/config';
2
+ import type { RequestContext } from '@reactionary/core';
3
+ import {
4
+ NoOpCache,
5
+ StoreSchema,
6
+ createInitialRequestContext,
7
+ } from '@reactionary/core';
8
+ import { getCommercetoolsTestConfiguration } from './test-utils';
9
+ import { CommercetoolsStoreProvider } from '../providers/store.provider';
10
+
11
+ describe('Commercetools Store Provider', () => {
12
+ let provider: CommercetoolsStoreProvider;
13
+ let reqCtx: RequestContext;
14
+
15
+ beforeAll(() => {
16
+ provider = new CommercetoolsStoreProvider(
17
+ getCommercetoolsTestConfiguration(),
18
+ StoreSchema,
19
+ new NoOpCache()
20
+ );
21
+ });
22
+
23
+ beforeEach(() => {
24
+ reqCtx = createInitialRequestContext();
25
+ });
26
+
27
+ it('should be able to query stores by longitude and latitude', async () => {
28
+ const stores = await provider.queryByProximity({
29
+ distance: 1000,
30
+ latitude: 15,
31
+ longitude: 15,
32
+ limit: 10
33
+ }, reqCtx);
34
+
35
+ expect(stores.length).toBe(2);
36
+ });
37
+ });
@@ -1,35 +1,11 @@
1
- import { Session } from "@reactionary/core";
2
-
3
1
  export function getCommercetoolsTestConfiguration() {
4
2
  return {
5
- apiUrl: process.env['COMMERCETOOLS_API_URL'] || '',
6
- authUrl: process.env['COMMERCETOOLS_AUTH_URL'] || '',
7
- clientId: process.env['COMMERCETOOLS_CLIENT_ID'] || '',
8
- clientSecret: process.env['COMMERCETOOLS_CLIENT_SECRET'] || '',
9
- projectKey: process.env['COMMERCETOOLS_PROJECT_KEY'] || ''
3
+ apiUrl: process.env['CTP_API_URL'] || '',
4
+ authUrl: process.env['CTP_AUTH_URL'] || '',
5
+ clientId: process.env['CTP_CLIENT_ID'] || '',
6
+ clientSecret: process.env['CTP_CLIENT_SECRET'] || '',
7
+ projectKey: process.env['CTP_PROJECT_KEY'] || '',
8
+ scopes: (process.env['CTP_SCOPES'] || '').split(',').map(x => x.trim()).filter(x => x && x.length > 0),
10
9
  }
11
10
  }
12
- export function createAnonymousTestSession(): Session {
13
- return {
14
- id: 'test-session-id',
15
- identity: {
16
- type: 'Anonymous',
17
- meta: {
18
- cache: { hit: false, key: '' },
19
- placeholder: false,
20
- },
21
- id: '',
22
- token: undefined,
23
- issued: new Date(),
24
- expiry: new Date(new Date().getTime() + 3600 * 1000), // 1 hour from now
25
- },
26
- languageContext: {
27
- locale: 'en-US',
28
- currencyCode: 'USD',
29
- countryCode: 'US',
30
- },
31
- storeIdentifier: {
32
- key: 'the-good-store',
33
- },
34
- };
35
- }
11
+
@@ -1,39 +1,97 @@
1
- import { ProductSchema, SearchResultSchema, Cache as ReactinaryCache, ProductProvider, SearchProvider, IdentityProvider, CategorySchema, CategoryProvider, CartSchema, CartProvider } from "@reactionary/core";
2
- import { FakeProductProvider } from "../providers/product.provider";
3
- import { FakeSearchProvider } from "../providers/search.provider";
4
- import { FakeConfiguration } from "../schema/configuration.schema";
5
- import { FakeCapabilities } from "../schema/capabilities.schema";
6
- import { FakeCategoryProvider } from "../providers/category.provider";
7
- import { FakeCartProvider } from "../providers";
8
-
9
- type FakeClient<T extends FakeCapabilities> =
10
- (T['cart'] extends true ? { cart: CartProvider } : object) &
11
- (T['product'] extends true ? { product: ProductProvider } : object) &
12
- (T['search'] extends true ? { search: SearchProvider } : object) &
13
- (T['identity'] extends true ? { identity: IdentityProvider } : object) &
14
- (T['category'] extends true ? { category: CategoryProvider } : object);
15
-
16
- export function withFakeCapabilities<T extends FakeCapabilities>(configuration: FakeConfiguration, capabilities: T) {
17
- return (cache: ReactinaryCache): FakeClient<T> => {
18
- const client: any = {};
19
-
20
- if (capabilities.product) {
21
- client.product = new FakeProductProvider(configuration, ProductSchema, cache);
22
- }
23
-
24
- if (capabilities.search) {
25
- client.search = new FakeSearchProvider(configuration, SearchResultSchema, cache);
26
- }
27
-
28
- if (capabilities.category) {
29
- client.category = new FakeCategoryProvider(configuration, CategorySchema, cache);
30
- }
31
-
32
- if (capabilities.cart) {
33
- client.cart = new FakeCartProvider(configuration, CartSchema, cache);
34
- }
35
-
36
-
37
- return client;
38
- };
1
+ import type {
2
+ Cache as ReactinaryCache,
3
+ ProductProvider,
4
+ SearchProvider,
5
+ IdentityProvider,
6
+ CategoryProvider,
7
+ CartProvider,
8
+ InventoryProvider,
9
+ StoreProvider,
10
+ PriceProvider,
11
+ } from '@reactionary/core';
12
+ import {
13
+ ProductSchema,
14
+ SearchResultSchema,
15
+ CategorySchema,
16
+ CartSchema,
17
+ InventorySchema,
18
+ StoreSchema,
19
+ PriceSchema,
20
+ } from '@reactionary/core';
21
+ import { FakeProductProvider } from '../providers/product.provider';
22
+ import { FakeSearchProvider } from '../providers/search.provider';
23
+ import type { FakeConfiguration } from '../schema/configuration.schema';
24
+ import type { FakeCapabilities } from '../schema/capabilities.schema';
25
+ import { FakeCategoryProvider } from '../providers/category.provider';
26
+ import {
27
+ FakeCartProvider,
28
+ FakeInventoryProvider,
29
+ FakePriceProvider,
30
+ FakeStoreProvider,
31
+ } from '../providers';
32
+
33
+ type FakeClient<T extends FakeCapabilities> = (T['cart'] extends true
34
+ ? { cart: CartProvider }
35
+ : object) &
36
+ (T['product'] extends true ? { product: ProductProvider } : object) &
37
+ (T['search'] extends true ? { search: SearchProvider } : object) &
38
+ (T['identity'] extends true ? { identity: IdentityProvider } : object) &
39
+ (T['category'] extends true ? { category: CategoryProvider } : object) &
40
+ (T['inventory'] extends true ? { inventory: InventoryProvider } : object) &
41
+ (T['store'] extends true ? { store: StoreProvider } : object) &
42
+ (T['price'] extends true ? { price: PriceProvider } : object);
43
+
44
+ export function withFakeCapabilities<T extends FakeCapabilities>(
45
+ configuration: FakeConfiguration,
46
+ capabilities: T
47
+ ) {
48
+ return (cache: ReactinaryCache): FakeClient<T> => {
49
+ const client: any = {};
50
+
51
+ if (capabilities.product) {
52
+ client.product = new FakeProductProvider(
53
+ configuration,
54
+ ProductSchema,
55
+ cache
56
+ );
57
+ }
58
+
59
+ if (capabilities.search) {
60
+ client.search = new FakeSearchProvider(
61
+ configuration,
62
+ SearchResultSchema,
63
+ cache
64
+ );
65
+ }
66
+
67
+ if (capabilities.category) {
68
+ client.category = new FakeCategoryProvider(
69
+ configuration,
70
+ CategorySchema,
71
+ cache
72
+ );
73
+ }
74
+
75
+ if (capabilities.cart) {
76
+ client.cart = new FakeCartProvider(configuration, CartSchema, cache);
77
+ }
78
+
79
+ if (capabilities.inventory) {
80
+ client.inventory = new FakeInventoryProvider(
81
+ configuration,
82
+ InventorySchema,
83
+ cache
84
+ );
85
+ }
86
+
87
+ if (capabilities.store) {
88
+ client.store = new FakeStoreProvider(configuration, StoreSchema, cache);
89
+ }
90
+
91
+ if (capabilities.price) {
92
+ client.price = new FakePriceProvider(configuration, PriceSchema, cache);
93
+ }
94
+
95
+ return client;
96
+ };
39
97
  }
@@ -1,10 +1,11 @@
1
- import {
2
- AnalyticsProvider,
1
+ import type {
3
2
  BaseModel,
4
- Cache,
3
+ Cache} from '@reactionary/core';
4
+ import {
5
+ AnalyticsProvider
5
6
  } from '@reactionary/core';
6
- import z from 'zod';
7
- import { FakeConfiguration } from '../schema/configuration.schema';
7
+ import type z from 'zod';
8
+ import type { FakeConfiguration } from '../schema/configuration.schema';
8
9
 
9
10
  export class FakeAnalyticsProvider<
10
11
  T extends BaseModel = BaseModel
@@ -1,15 +1,25 @@
1
- import {
1
+ import type {
2
2
  Cart,
3
- CartProvider,
4
3
  CartQueryById,
5
4
  CartMutationItemAdd,
6
5
  CartMutationItemRemove,
7
6
  CartMutationItemQuantityChange,
8
- Session,
7
+ Session, RequestContext,
9
8
  Cache,
9
+ CartIdentifier,
10
+ CartMutationApplyCoupon,
11
+ CartMutationChangeCurrency,
12
+ CartMutationCheckout,
13
+ CartMutationDeleteCart,
14
+ CartMutationRemoveCoupon,
15
+ CartMutationSetBillingAddress,
16
+ CartMutationSetShippingInfo,
17
+ OrderIdentifier} from '@reactionary/core';
18
+ import {
19
+ CartProvider
10
20
  } from '@reactionary/core';
11
- import z from 'zod';
12
- import { FakeConfiguration } from '../schema/configuration.schema';
21
+ import type z from 'zod';
22
+ import type { FakeConfiguration } from '../schema/configuration.schema';
13
23
  import { Faker, en, base } from '@faker-js/faker';
14
24
 
15
25
  export class FakeCartProvider<
@@ -31,7 +41,7 @@ export class FakeCartProvider<
31
41
 
32
42
  public override async getById(
33
43
  payload: CartQueryById,
34
- _session: Session
44
+ _reqCtx: RequestContext
35
45
  ): Promise<T> {
36
46
  const cartId = payload.cart.key;
37
47
 
@@ -69,14 +79,14 @@ export class FakeCartProvider<
69
79
 
70
80
  public override async add(
71
81
  payload: CartMutationItemAdd,
72
- session: Session
82
+ reqCtx: RequestContext
73
83
  ): Promise<T> {
74
84
 
75
85
  const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
76
- const cart = await this.getById({ cart: { key: cartId } }, session);
86
+ const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
77
87
 
78
88
  const existingItemIndex = cart.items.findIndex(
79
- item => item.product.key === payload.product.key
89
+ item => item.sku.key === payload.sku.key
80
90
  );
81
91
 
82
92
  if (existingItemIndex >= 0) {
@@ -86,26 +96,31 @@ export class FakeCartProvider<
86
96
 
87
97
  cart.items.push({
88
98
  identifier: { key: `item-${Date.now()}` },
89
- product: payload.product,
99
+ sku: payload.sku,
90
100
  quantity: payload.quantity,
91
101
  price: {
92
102
  unitPrice: {
93
103
  value: price,
94
- currency: session.languageContext.currencyCode,
104
+ currency: reqCtx.languageContext.currencyCode,
95
105
  },
96
106
  totalPrice: {
97
107
  value: 0, // Will be calculated below
98
- currency: session.languageContext.currencyCode,
108
+ currency: reqCtx.languageContext.currencyCode,
99
109
  },
100
110
  totalDiscount: {
101
111
  value: 0,
102
- currency: session.languageContext.currencyCode,
112
+ currency: reqCtx.languageContext.currencyCode,
103
113
  },
104
114
  unitDiscount: {
105
115
  value: 0,
106
- currency: session.languageContext.currencyCode,
116
+ currency: reqCtx.languageContext.currencyCode,
107
117
  },
108
118
  },
119
+ product: {
120
+ key: `product-for-${payload.sku.key}`,
121
+ },
122
+
123
+
109
124
  });
110
125
  }
111
126
 
@@ -116,10 +131,10 @@ export class FakeCartProvider<
116
131
 
117
132
  public override async remove(
118
133
  payload: CartMutationItemRemove,
119
- session: Session
134
+ reqCtx: RequestContext
120
135
  ): Promise<T> {
121
136
  const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
122
- const cart = await this.getById({ cart: { key: cartId } }, session);
137
+ const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
123
138
 
124
139
  cart.items = cart.items.filter(
125
140
  item => item.identifier.key !== payload.item.key
@@ -130,15 +145,17 @@ export class FakeCartProvider<
130
145
 
131
146
  public override async changeQuantity(
132
147
  payload: CartMutationItemQuantityChange,
133
- session: Session
148
+ reqCtx: RequestContext
134
149
  ): Promise<T> {
135
150
  const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
136
- const cart = await this.getById({ cart: { key: cartId } }, session);
151
+ const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
137
152
 
138
153
  const item = cart.items.find(
139
154
  item => item.identifier.key === payload.item.key
140
155
  );
141
-
156
+ if (payload.quantity < 1) {
157
+ return cart;
158
+ }
142
159
  if (item) {
143
160
  item.quantity = payload.quantity;
144
161
  }
@@ -147,6 +164,33 @@ export class FakeCartProvider<
147
164
  }
148
165
 
149
166
 
167
+ public override getActiveCartId(reqCtx: RequestContext): Promise<CartIdentifier> {
168
+ throw new Error('Method not implemented.');
169
+ }
170
+ public override deleteCart(payload: CartMutationDeleteCart, reqCtx: RequestContext): Promise<T> {
171
+ throw new Error('Method not implemented.');
172
+ }
173
+ public override setShippingInfo(payload: CartMutationSetShippingInfo, reqCtx: RequestContext): Promise<T> {
174
+ throw new Error('Method not implemented.');
175
+ }
176
+ public override setBillingAddress(payload: CartMutationSetBillingAddress, reqCtx: RequestContext): Promise<T> {
177
+ throw new Error('Method not implemented.');
178
+ }
179
+ public override applyCouponCode(payload: CartMutationApplyCoupon, reqCtx: RequestContext): Promise<T> {
180
+ throw new Error('Method not implemented.');
181
+ }
182
+ public override removeCouponCode(payload: CartMutationRemoveCoupon, reqCtx: RequestContext): Promise<T> {
183
+ throw new Error('Method not implemented.');
184
+ }
185
+ public override checkout(payload: CartMutationCheckout, reqCtx: RequestContext): Promise<OrderIdentifier> {
186
+ throw new Error('Method not implemented.');
187
+ }
188
+ public override changeCurrency(payload: CartMutationChangeCurrency, reqCtx: RequestContext): Promise<T> {
189
+ throw new Error('Method not implemented.');
190
+ }
191
+
192
+
193
+
150
194
 
151
195
  protected recalculateCart(cart: T) {
152
196
  cart.items.forEach(item => {
@@ -163,4 +207,7 @@ export class FakeCartProvider<
163
207
  currency: cart.items[0]?.price.unitPrice.currency || 'USD',
164
208
  };
165
209
  }
210
+
211
+
212
+
166
213
  }
@@ -1,7 +1,8 @@
1
- import { Category, CategoryProvider, CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories, Session } from "@reactionary/core";
2
- import { FakeConfiguration } from "../schema/configuration.schema";
3
- import { Cache as ReactionaryCache } from "@reactionary/core";
4
- import z from "zod";
1
+ import type { Category, CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories, RequestContext} from "@reactionary/core";
2
+ import { CategoryProvider, Session } from "@reactionary/core";
3
+ import type { FakeConfiguration } from "../schema/configuration.schema";
4
+ import type { Cache as ReactionaryCache } from "@reactionary/core";
5
+ import type z from "zod";
5
6
  import { Faker, en, base } from '@faker-js/faker';
6
7
  export class FakeCategoryProvider<
7
8
  T extends Category = Category
@@ -70,19 +71,18 @@ export class FakeCategoryProvider<
70
71
  });
71
72
  }
72
73
 
73
-
74
-
75
- public override async getById(payload: CategoryQueryById, session: Session): Promise<T> {
74
+ public override async getById(payload: CategoryQueryById, reqCtx: RequestContext): Promise<T> {
76
75
  const category = this.allCategories.get(payload.id.key);
76
+
77
77
  if(!category) {
78
78
  const dummyCategory = this.newModel();
79
79
  dummyCategory.meta.placeholder = true;
80
80
  dummyCategory.identifier = { key: payload.id.key };
81
81
  return dummyCategory;
82
82
  }
83
- return category;
83
+ return category;
84
84
  }
85
- public override getBySlug(payload: CategoryQueryBySlug, session: Session): Promise<T | null> {
85
+ public override getBySlug(payload: CategoryQueryBySlug, reqCtx: RequestContext): Promise<T | null> {
86
86
  for(const p of this.allCategories.values()) {
87
87
  if(p.slug === payload.slug) {
88
88
  return Promise.resolve(p as T);
@@ -91,7 +91,7 @@ export class FakeCategoryProvider<
91
91
  return Promise.resolve(null);
92
92
  }
93
93
 
94
- public override getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, session: Session): Promise<T[]> {
94
+ public override getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, reqCtx: RequestContext): Promise<T[]> {
95
95
  const path = new Array<T>();
96
96
  let category = this.allCategories.get(payload.id.key);
97
97
  path.push(category as T);
@@ -104,7 +104,7 @@ export class FakeCategoryProvider<
104
104
  return Promise.resolve(path);
105
105
  }
106
106
 
107
- public override async findChildCategories(payload: CategoryQueryForChildCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>> {
107
+ public override async findChildCategories(payload: CategoryQueryForChildCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>> {
108
108
  const children = this.childCategories.get(payload.parentId.key);
109
109
  const page = children?.slice((payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize, payload.paginationOptions.pageNumber * payload.paginationOptions.pageSize);
110
110
 
@@ -126,7 +126,7 @@ export class FakeCategoryProvider<
126
126
 
127
127
  return Promise.resolve(res);
128
128
  }
129
- public override findTopCategories(payload: CategoryQueryForTopCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>> {
129
+ public override findTopCategories(payload: CategoryQueryForTopCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>> {
130
130
  const children = this.topCategories;
131
131
  const page = children?.slice((payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize, payload.paginationOptions.pageNumber * payload.paginationOptions.pageSize);
132
132
 
@@ -1,14 +1,15 @@
1
1
  import {
2
- Identity,
2
+ type Identity,
3
+ type IdentityQuerySelf,
4
+ type IdentityMutationLogin,
5
+ type IdentityMutationLogout,
6
+ type RequestContext,
7
+ type Cache,
3
8
  IdentityProvider,
4
- IdentityQuerySelf,
5
- IdentityMutationLogin,
6
- IdentityMutationLogout,
7
- Session,
8
- Cache,
9
+ type IdentityMutationRegister,
9
10
  } from '@reactionary/core';
10
- import z from 'zod';
11
- import { FakeConfiguration } from '../schema/configuration.schema';
11
+ import type z from 'zod';
12
+ import type { FakeConfiguration } from '../schema/configuration.schema';
12
13
  import { base, en, Faker } from '@faker-js/faker';
13
14
 
14
15
  export class FakeIdentityProvider<
@@ -25,7 +26,7 @@ export class FakeIdentityProvider<
25
26
 
26
27
  public override async getSelf(
27
28
  _payload: IdentityQuerySelf,
28
- _session: Session
29
+ _reqCtx: RequestContext
29
30
  ): Promise<T> {
30
31
  if (!this.currentIdentity) {
31
32
  const model = this.newModel();
@@ -50,7 +51,7 @@ export class FakeIdentityProvider<
50
51
 
51
52
  public override async login(
52
53
  payload: IdentityMutationLogin,
53
- _session: Session
54
+ _reqCtx: RequestContext
54
55
  ): Promise<T> {
55
56
  const generator = new Faker({
56
57
  seed: 42,
@@ -72,14 +73,14 @@ export class FakeIdentityProvider<
72
73
  placeholder: false,
73
74
  },
74
75
  });
75
-
76
+
76
77
  this.currentIdentity = this.assert(model);
77
78
  return this.currentIdentity;
78
79
  }
79
80
 
80
81
  public override async logout(
81
82
  _payload: IdentityMutationLogout,
82
- _session: Session
83
+ _reqCtx: RequestContext
83
84
  ): Promise<T> {
84
85
  const model = this.newModel();
85
86
  Object.assign(model, {
@@ -95,8 +96,15 @@ export class FakeIdentityProvider<
95
96
  placeholder: false,
96
97
  },
97
98
  });
98
-
99
+
99
100
  this.currentIdentity = this.assert(model);
100
101
  return this.currentIdentity;
101
102
  }
102
- }
103
+
104
+ public override register(
105
+ payload: IdentityMutationRegister,
106
+ reqCtx: RequestContext
107
+ ): Promise<T> {
108
+ throw new Error('Method not implemented.');
109
+ }
110
+ }
@@ -6,3 +6,4 @@ export * from './inventory.provider';
6
6
  export * from './price.provider';
7
7
  export * from './product.provider';
8
8
  export * from './search.provider';
9
+ export * from './store.provider';
@@ -1,12 +1,14 @@
1
- import {
1
+ import type {
2
2
  Inventory,
3
- InventoryProvider,
4
- InventoryQuery,
5
- Session,
3
+ RequestContext,
6
4
  Cache,
5
+ InventoryQueryBySKU
6
+ } from '@reactionary/core';
7
+ import {
8
+ InventoryProvider
7
9
  } from '@reactionary/core';
8
- import z from 'zod';
9
- import { FakeConfiguration } from '../schema/configuration.schema';
10
+ import type z from 'zod';
11
+ import type { FakeConfiguration } from '../schema/configuration.schema';
10
12
  import { base, en, Faker } from '@faker-js/faker';
11
13
 
12
14
  export class FakeInventoryProvider<
@@ -21,8 +23,8 @@ export class FakeInventoryProvider<
21
23
  }
22
24
 
23
25
  public override async getBySKU(
24
- payload: InventoryQuery,
25
- _session: Session
26
+ payload: InventoryQueryBySKU,
27
+ _reqCtx: RequestContext
26
28
  ): Promise<T> {
27
29
  // Generate a simple hash from the SKU string for seeding
28
30
  let hash = 0;
@@ -40,10 +42,8 @@ export class FakeInventoryProvider<
40
42
  const model = this.newModel();
41
43
 
42
44
  model.identifier = {
43
- sku: { key: skuString},
44
- channelId: {
45
- key: 'online'
46
- },
45
+ sku: payload.sku,
46
+ fulfillmentCenter: payload.fulfilmentCenter
47
47
  };
48
48
  model.sku = skuString;
49
49
 
@@ -58,7 +58,7 @@ export class FakeInventoryProvider<
58
58
  model.meta = {
59
59
  cache: {
60
60
  hit: false,
61
- key: this.generateCacheKeySingle(model.identifier, _session)
61
+ key: this.generateCacheKeySingle(model.identifier, _reqCtx)
62
62
  },
63
63
  placeholder: false,
64
64
  };
@@ -1,12 +1,12 @@
1
1
  import {
2
- Price,
2
+ type Price,
3
+ type PriceQueryBySku,
4
+ type RequestContext,
5
+ type Cache,
3
6
  PriceProvider,
4
- PriceQueryBySku,
5
- Session,
6
- Cache,
7
7
  } from '@reactionary/core';
8
- import z from 'zod';
9
- import { FakeConfiguration } from '../schema/configuration.schema';
8
+ import type z from 'zod';
9
+ import type { FakeConfiguration } from '../schema/configuration.schema';
10
10
  import { base, en, Faker } from '@faker-js/faker';
11
11
 
12
12
  export class FakePriceProvider<
@@ -20,20 +20,20 @@ export class FakePriceProvider<
20
20
  this.config = config;
21
21
  }
22
22
 
23
- public override async getBySKUs(payload: PriceQueryBySku[], session: Session): Promise<T[]> {
23
+ public override async getBySKUs(payload: PriceQueryBySku[], reqCtx: RequestContext): Promise<T[]> {
24
24
 
25
- const promises = payload.map(p => this.getBySKU(p, session));
25
+ const promises = payload.map(p => this.getBySKU(p, reqCtx));
26
26
  const result = await Promise.all(promises);
27
27
  return result;
28
28
  }
29
29
 
30
30
  public override async getBySKU(
31
31
  payload: PriceQueryBySku,
32
- _session: Session
32
+ _reqCtx: RequestContext
33
33
  ): Promise<T> {
34
34
 
35
35
  if (payload.sku.key === 'unknown-sku') {
36
- return this.getEmptyPriceResult(payload.sku.key, _session.languageContext.currencyCode);
36
+ return this.createEmptyPriceResult(payload.sku.key, _reqCtx.languageContext.currencyCode);
37
37
  }
38
38
 
39
39
  // Generate a simple hash from the SKU key string for seeding
@@ -57,7 +57,7 @@ export class FakePriceProvider<
57
57
  },
58
58
  unitPrice: {
59
59
  value: generator.number.int({ min: 300, max: 100000 }) / 100,
60
- currency: _session.languageContext.currencyCode,
60
+ currency: _reqCtx.languageContext.currencyCode,
61
61
  },
62
62
  meta: {
63
63
  cache: {
@@ -78,14 +78,14 @@ export class FakePriceProvider<
78
78
  minimumQuantity: generator.number.int({ min: 2, max: 5 }),
79
79
  price: {
80
80
  value: tier1Price,
81
- currency: _session.languageContext.currencyCode,
81
+ currency: _reqCtx.languageContext.currencyCode,
82
82
  }
83
83
  },
84
84
  {
85
85
  minimumQuantity: generator.number.int({ min: 6, max: 10 }),
86
86
  price: {
87
87
  value: tier2Price,
88
- currency: _session.languageContext.currencyCode,
88
+ currency: _reqCtx.languageContext.currencyCode,
89
89
  }
90
90
  }
91
91
  ];