@reactionary/source 0.0.48 → 0.0.52

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 (175) hide show
  1. package/core/package.json +4 -3
  2. package/core/src/cache/cache.interface.ts +1 -1
  3. package/core/src/cache/memory-cache.ts +2 -2
  4. package/core/src/cache/noop-cache.ts +1 -1
  5. package/core/src/cache/redis-cache.ts +1 -1
  6. package/core/src/client/client-builder.ts +4 -4
  7. package/core/src/client/client.ts +12 -12
  8. package/core/src/decorators/reactionary.decorator.ts +22 -2
  9. package/core/src/index.ts +14 -14
  10. package/core/src/initialization.ts +1 -1
  11. package/core/src/providers/analytics.provider.ts +2 -2
  12. package/core/src/providers/base.provider.ts +5 -5
  13. package/core/src/providers/cart.provider.ts +6 -6
  14. package/core/src/providers/category.provider.ts +4 -9
  15. package/core/src/providers/checkout.provider.ts +156 -0
  16. package/core/src/providers/identity.provider.ts +5 -5
  17. package/core/src/providers/index.ts +13 -12
  18. package/core/src/providers/inventory.provider.ts +4 -4
  19. package/core/src/providers/order.provider.ts +31 -0
  20. package/core/src/providers/price.provider.ts +5 -5
  21. package/core/src/providers/product.provider.ts +5 -5
  22. package/core/src/providers/profile.provider.ts +5 -5
  23. package/core/src/providers/search.provider.ts +4 -4
  24. package/core/src/providers/store.provider.ts +4 -4
  25. package/core/src/schemas/capabilities.schema.ts +2 -1
  26. package/core/src/schemas/models/analytics.model.ts +1 -1
  27. package/core/src/schemas/models/cart.model.ts +3 -28
  28. package/core/src/schemas/models/category.model.ts +2 -2
  29. package/core/src/schemas/models/checkout.model.ts +66 -0
  30. package/core/src/schemas/models/cost.model.ts +21 -0
  31. package/core/src/schemas/models/identifiers.model.ts +23 -2
  32. package/core/src/schemas/models/identity.model.ts +8 -5
  33. package/core/src/schemas/models/index.ts +19 -15
  34. package/core/src/schemas/models/inventory.model.ts +2 -2
  35. package/core/src/schemas/models/order.model.ts +46 -0
  36. package/core/src/schemas/models/payment.model.ts +5 -12
  37. package/core/src/schemas/models/price.model.ts +3 -3
  38. package/core/src/schemas/models/product.model.ts +6 -3
  39. package/core/src/schemas/models/profile.model.ts +2 -2
  40. package/core/src/schemas/models/search.model.ts +2 -3
  41. package/core/src/schemas/models/shipping-method.model.ts +34 -3
  42. package/core/src/schemas/models/store.model.ts +2 -2
  43. package/core/src/schemas/mutations/analytics.mutation.ts +2 -2
  44. package/core/src/schemas/mutations/cart.mutation.ts +5 -5
  45. package/core/src/schemas/mutations/checkout.mutation.ts +50 -0
  46. package/core/src/schemas/mutations/identity.mutation.ts +1 -1
  47. package/core/src/schemas/mutations/index.ts +10 -10
  48. package/core/src/schemas/mutations/profile.mutation.ts +1 -1
  49. package/core/src/schemas/queries/cart.query.ts +2 -2
  50. package/core/src/schemas/queries/category.query.ts +3 -3
  51. package/core/src/schemas/queries/checkout.query.ts +22 -0
  52. package/core/src/schemas/queries/identity.query.ts +1 -1
  53. package/core/src/schemas/queries/index.ts +13 -12
  54. package/core/src/schemas/queries/inventory.query.ts +2 -2
  55. package/core/src/schemas/queries/order.query.ts +9 -0
  56. package/core/src/schemas/queries/price.query.ts +2 -2
  57. package/core/src/schemas/queries/product.query.ts +9 -2
  58. package/core/src/schemas/queries/profile.query.ts +1 -1
  59. package/core/src/schemas/queries/search.query.ts +2 -2
  60. package/core/src/schemas/queries/store.query.ts +1 -1
  61. package/core/src/schemas/session.schema.ts +3 -3
  62. package/core/tsconfig.json +3 -2
  63. package/examples/next/next.config.js +17 -6
  64. package/examples/next/src/app/page.tsx +1 -2
  65. package/examples/node/package.json +2 -1
  66. package/examples/node/src/basic/basic-node-setup.spec.ts +1 -1
  67. package/examples/node/tsconfig.json +2 -1
  68. package/examples/node/tsconfig.spec.json +3 -2
  69. package/package.json +3 -1
  70. package/providers/algolia/package.json +2 -1
  71. package/providers/algolia/src/core/initialize.ts +5 -5
  72. package/providers/algolia/src/index.ts +5 -5
  73. package/providers/algolia/src/providers/product.provider.ts +8 -2
  74. package/providers/algolia/src/providers/search.provider.ts +1 -1
  75. package/providers/algolia/src/test/search.provider.spec.ts +1 -1
  76. package/providers/algolia/tsconfig.json +2 -1
  77. package/providers/algolia/tsconfig.spec.json +3 -2
  78. package/providers/commercetools/{jest.config.ts → jest.config.cjs} +1 -1
  79. package/providers/commercetools/package.json +3 -2
  80. package/providers/commercetools/src/core/client.ts +63 -32
  81. package/providers/commercetools/src/core/initialize.ts +20 -16
  82. package/providers/commercetools/src/index.ts +10 -10
  83. package/providers/commercetools/src/providers/cart.provider.ts +14 -19
  84. package/providers/commercetools/src/providers/category.provider.ts +3 -12
  85. package/providers/commercetools/src/providers/checkout.provider.ts +644 -0
  86. package/providers/commercetools/src/providers/identity.provider.ts +8 -8
  87. package/providers/commercetools/src/providers/index.ts +12 -9
  88. package/providers/commercetools/src/providers/inventory.provider.ts +2 -4
  89. package/providers/commercetools/src/providers/order.provider.ts +163 -0
  90. package/providers/commercetools/src/providers/price.provider.ts +3 -3
  91. package/providers/commercetools/src/providers/product.provider.ts +24 -6
  92. package/providers/commercetools/src/providers/profile.provider.ts +2 -2
  93. package/providers/commercetools/src/providers/search.provider.ts +3 -5
  94. package/providers/commercetools/src/providers/store.provider.ts +3 -3
  95. package/providers/commercetools/src/schema/capabilities.schema.ts +2 -1
  96. package/providers/commercetools/src/schema/commercetools.schema.ts +7 -5
  97. package/providers/commercetools/src/schema/configuration.schema.ts +2 -0
  98. package/providers/commercetools/src/test/cart.provider.spec.ts +24 -4
  99. package/providers/commercetools/src/test/category.provider.spec.ts +3 -3
  100. package/providers/commercetools/src/test/checkout.provider.spec.ts +312 -0
  101. package/providers/commercetools/src/test/identity.provider.spec.ts +3 -3
  102. package/providers/commercetools/src/test/inventory.provider.spec.ts +2 -2
  103. package/providers/commercetools/src/test/price.provider.spec.ts +4 -4
  104. package/providers/commercetools/src/test/product.provider.spec.ts +22 -5
  105. package/providers/commercetools/src/test/profile.provider.spec.ts +3 -3
  106. package/providers/commercetools/src/test/search.provider.spec.ts +2 -2
  107. package/providers/commercetools/src/test/store.provider.spec.ts +2 -2
  108. package/providers/commercetools/src/test/test-utils.ts +14 -0
  109. package/providers/commercetools/tsconfig.json +2 -1
  110. package/providers/commercetools/tsconfig.spec.json +4 -3
  111. package/providers/fake/{jest.config.ts → jest.config.cjs} +1 -1
  112. package/providers/fake/package.json +2 -2
  113. package/providers/fake/src/core/initialize.ts +6 -6
  114. package/providers/fake/src/index.ts +4 -4
  115. package/providers/fake/src/providers/analytics.provider.ts +1 -1
  116. package/providers/fake/src/providers/cart.provider.ts +2 -2
  117. package/providers/fake/src/providers/category.provider.ts +7 -3
  118. package/providers/fake/src/providers/identity.provider.ts +1 -1
  119. package/providers/fake/src/providers/index.ts +9 -9
  120. package/providers/fake/src/providers/inventory.provider.ts +1 -1
  121. package/providers/fake/src/providers/price.provider.ts +1 -1
  122. package/providers/fake/src/providers/product.provider.ts +10 -4
  123. package/providers/fake/src/providers/search.provider.ts +2 -5
  124. package/providers/fake/src/providers/store.provider.ts +2 -3
  125. package/providers/fake/src/test/cart.provider.spec.ts +3 -3
  126. package/providers/fake/src/test/category.provider.spec.ts +2 -2
  127. package/providers/fake/src/test/price.provider.spec.ts +2 -2
  128. package/providers/fake/src/test/product.provider.spec.ts +8 -8
  129. package/providers/fake/src/test/test-utils.ts +1 -1
  130. package/providers/fake/tsconfig.json +2 -1
  131. package/providers/fake/tsconfig.spec.json +1 -3
  132. package/providers/posthog/package.json +4 -4
  133. package/providers/posthog/project.json +2 -2
  134. package/providers/posthog/src/core/initialize.ts +2 -2
  135. package/providers/posthog/src/index.ts +3 -3
  136. package/providers/posthog/tsconfig.json +2 -1
  137. package/tsconfig.base.json +3 -4
  138. package/.claude/settings.local.json +0 -28
  139. package/core/src/providers/cart-payment.provider.ts +0 -57
  140. package/core/src/schemas/mutations/cart-payment.mutation.ts +0 -21
  141. package/core/src/schemas/queries/cart-payment.query.ts +0 -12
  142. package/otel/README.md +0 -227
  143. package/otel/eslint.config.mjs +0 -23
  144. package/otel/package.json +0 -11
  145. package/otel/pnpm-lock.yaml +0 -805
  146. package/otel/project.json +0 -33
  147. package/otel/src/index.ts +0 -22
  148. package/otel/src/metrics.ts +0 -76
  149. package/otel/src/provider-instrumentation.ts +0 -108
  150. package/otel/src/test/otel.spec.ts +0 -8
  151. package/otel/src/trace-decorator.ts +0 -226
  152. package/otel/src/tracer.ts +0 -83
  153. package/otel/src/trpc-middleware.ts +0 -128
  154. package/otel/tsconfig.json +0 -23
  155. package/otel/tsconfig.lib.json +0 -23
  156. package/otel/tsconfig.spec.json +0 -28
  157. package/otel/vite.config.ts +0 -24
  158. package/providers/commercetools/src/providers/cart-payment.provider.ts +0 -193
  159. package/providers/commercetools/src/test/cart-payment.provider.spec.ts +0 -145
  160. package/trpc/README.md +0 -7
  161. package/trpc/__mocks__/superjson.js +0 -25
  162. package/trpc/eslint.config.mjs +0 -19
  163. package/trpc/jest.config.ts +0 -14
  164. package/trpc/package.json +0 -14
  165. package/trpc/project.json +0 -31
  166. package/trpc/src/client.ts +0 -175
  167. package/trpc/src/index.ts +0 -44
  168. package/trpc/src/integration.spec.ts +0 -223
  169. package/trpc/src/server.ts +0 -125
  170. package/trpc/src/test-utils.ts +0 -31
  171. package/trpc/src/transparent-client.spec.ts +0 -162
  172. package/trpc/src/types.ts +0 -144
  173. package/trpc/tsconfig.json +0 -16
  174. package/trpc/tsconfig.lib.json +0 -10
  175. package/trpc/tsconfig.spec.json +0 -15
@@ -0,0 +1,312 @@
1
+ import 'dotenv/config';
2
+ import type { Cart, Checkout, RequestContext } from '@reactionary/core';
3
+ import {
4
+ CartSchema,
5
+ CheckoutSchema,
6
+ IdentitySchema,
7
+ NoOpCache,
8
+ PaymentInstructionSchema,
9
+ ShippingInstructionSchema,
10
+ createInitialRequestContext,
11
+ } from '@reactionary/core';
12
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
13
+ import { CommercetoolsCartProvider } from '../providers/cart.provider.js';
14
+ import { CommercetoolsIdentityProvider } from '../providers/identity.provider.js';
15
+ import { CommercetoolsCheckoutProvider } from '../providers/checkout.provider.js';
16
+
17
+ const testData = {
18
+ skuWithoutTiers: 'SGB-01',
19
+ skuWithTiers: 'GMCT-01',
20
+ };
21
+
22
+ describe('Commercetools Checkout Provider', () => {
23
+ let provider: CommercetoolsCheckoutProvider;
24
+ let cartProvider: CommercetoolsCartProvider;
25
+ let identityProvider: CommercetoolsIdentityProvider;
26
+ let reqCtx: RequestContext;
27
+
28
+ beforeAll(() => {
29
+ provider = new CommercetoolsCheckoutProvider(
30
+ getCommercetoolsTestConfiguration(),
31
+ CheckoutSchema,
32
+ new NoOpCache()
33
+ );
34
+ cartProvider = new CommercetoolsCartProvider(
35
+ getCommercetoolsTestConfiguration(),
36
+ CartSchema,
37
+ new NoOpCache()
38
+ );
39
+ identityProvider = new CommercetoolsIdentityProvider(
40
+ getCommercetoolsTestConfiguration(),
41
+ IdentitySchema,
42
+ new NoOpCache()
43
+ );
44
+ });
45
+
46
+ beforeEach(() => {
47
+ reqCtx = createInitialRequestContext();
48
+ });
49
+
50
+ describe('anonymous sessions', () => {
51
+ let cart: Cart;
52
+
53
+ beforeEach(async () => {
54
+ cart = await cartProvider.add(
55
+ {
56
+ cart: { key: '', version: 0 },
57
+ sku: {
58
+ key: testData.skuWithoutTiers,
59
+ },
60
+ quantity: 1,
61
+ },
62
+ reqCtx
63
+ );
64
+ });
65
+
66
+ it('can create a checkout session from a cart', async () => {
67
+ // we have either an anonymous user, or an authenticated user.
68
+ // if it is anonymous, we assume you will have collected some basic info by now ?
69
+
70
+ const checkout = await provider.initiateCheckoutForCart(
71
+ {
72
+ cart: cart.identifier,
73
+ billingAddress: {
74
+ countryCode: 'US',
75
+ firstName: 'John',
76
+ lastName: 'Doe',
77
+ streetAddress: '123 Main St',
78
+ streetNumber: '1A',
79
+ postalCode: '12345',
80
+ city: 'Anytown',
81
+ region: '',
82
+ },
83
+ notificationEmail: 'sample@example.com',
84
+ notificationPhone: '+4512345678',
85
+ },
86
+ reqCtx
87
+ );
88
+
89
+ expect(checkout.identifier.key).toBeDefined();
90
+ expect(checkout.originalCartReference.key).toBe(cart.identifier.key);
91
+ expect(checkout.billingAddress?.firstName).toBe('John');
92
+ expect(checkout.items.length).toBe(1);
93
+ expect(checkout.items[0].sku.key).toBe(testData.skuWithoutTiers);
94
+ });
95
+
96
+ describe('checkout actions', () => {
97
+ let checkout: Checkout;
98
+ beforeEach(async () => {
99
+ checkout = await provider.initiateCheckoutForCart(
100
+ {
101
+ cart: cart.identifier,
102
+ billingAddress: {
103
+ countryCode: 'US',
104
+ firstName: 'John',
105
+ lastName: 'Doe',
106
+ streetAddress: '123 Main St',
107
+ streetNumber: '1A',
108
+ postalCode: '12345',
109
+ city: 'Anytown',
110
+ region: '',
111
+ },
112
+ notificationEmail: 'sample@example.com',
113
+ notificationPhone: '+4512345678',
114
+ },
115
+ reqCtx
116
+ );
117
+ });
118
+
119
+ it('can list payment methods', async () => {
120
+ const paymentMethods = await provider.getAvailablePaymentMethods(
121
+ {
122
+ checkout: checkout.identifier,
123
+ },
124
+ reqCtx
125
+ );
126
+ expect(paymentMethods.length).toBeGreaterThan(0);
127
+ expect(
128
+ paymentMethods.find((x) => x.identifier.method === 'stripe')
129
+ ).toBeDefined();
130
+ });
131
+
132
+ it('can list shipping methods', async () => {
133
+ const shippingMethods = await provider.getAvailableShippingMethods(
134
+ {
135
+ checkout: checkout.identifier,
136
+ },
137
+ reqCtx
138
+ );
139
+ expect(shippingMethods.length).toBeGreaterThan(0);
140
+ expect(
141
+ shippingMethods.find((x) => x.identifier.key === 'us-delivery')
142
+ ).toBeDefined();
143
+ });
144
+
145
+ it('can add a payment instruction', async () => {
146
+ const paymentMethods = await provider.getAvailablePaymentMethods(
147
+ {
148
+ checkout: checkout.identifier,
149
+ },
150
+ reqCtx
151
+ );
152
+ const pm = paymentMethods.find((x) => x.identifier.method === 'stripe');
153
+ expect(pm).toBeDefined();
154
+
155
+ const checkoutWithPi = await provider.addPaymentInstruction(
156
+ {
157
+ checkout: checkout.identifier,
158
+ paymentInstruction: PaymentInstructionSchema.parse({
159
+ paymentMethod: pm?.identifier,
160
+ amount: checkout.price.grandTotal,
161
+ protocolData: [{ key: 'test-key', value: 'test-value' }],
162
+ }),
163
+ },
164
+ reqCtx
165
+ );
166
+
167
+ expect(checkoutWithPi.paymentInstructions.length).toBe(1);
168
+ expect(checkoutWithPi.paymentInstructions[0].paymentMethod.method).toBe(
169
+ 'stripe'
170
+ );
171
+ expect(checkoutWithPi.paymentInstructions[0].protocolData.find(x => x.key === 'stripe_clientSecret')?.value).toBeDefined();
172
+
173
+ });
174
+
175
+ xit('can cancel an in-progress payment', async () => {
176
+ const paymentMethods = await provider.getAvailablePaymentMethods(
177
+ {
178
+ checkout: checkout.identifier,
179
+ },
180
+ reqCtx
181
+ );
182
+ const pm = paymentMethods.find((x) => x.identifier.method === 'stripe');
183
+ expect(pm).toBeDefined();
184
+
185
+ const checkoutWithPi = await provider.addPaymentInstruction(
186
+ {
187
+ checkout: checkout.identifier,
188
+ paymentInstruction: PaymentInstructionSchema.parse({
189
+ paymentMethod: pm?.identifier,
190
+ amount: checkout.price.grandTotal,
191
+ protocolData: [{ key: 'test-key', value: 'test-value' }],
192
+ }),
193
+ },
194
+ reqCtx
195
+ );
196
+
197
+ expect(checkoutWithPi.paymentInstructions.length).toBe(1);
198
+
199
+ const checkoutAfterCancel = await provider.removePaymentInstruction(
200
+ {
201
+ checkout: checkout.identifier,
202
+ paymentInstruction:
203
+ checkoutWithPi.paymentInstructions[0].identifier,
204
+ },
205
+ reqCtx
206
+ );
207
+
208
+ expect(checkoutAfterCancel.paymentInstructions.length).toBe(0);
209
+ });
210
+
211
+ it('can set shipping address', async () => {
212
+ const checkoutWithShipping = await provider.setShippingAddress(
213
+ {
214
+ checkout: checkout.identifier,
215
+ shippingAddress: {
216
+ countryCode: 'US',
217
+ firstName: 'Jane',
218
+ lastName: 'Doe',
219
+ streetAddress: '456 Other St',
220
+ streetNumber: '2B',
221
+ postalCode: '54321',
222
+ city: 'Othertown',
223
+ region: '',
224
+ },
225
+ },
226
+ reqCtx
227
+ );
228
+
229
+ expect(checkoutWithShipping.shippingAddress).toBeDefined();
230
+ expect(checkoutWithShipping.shippingAddress?.firstName).toBe('Jane');
231
+ });
232
+
233
+ it('can set shipping instructions', async () => {
234
+ const shippingMethods = await provider.getAvailableShippingMethods(
235
+ {
236
+ checkout: checkout.identifier,
237
+ },
238
+ reqCtx
239
+ );
240
+ const sm = shippingMethods.find((x) => x.identifier.key === 'us-delivery');
241
+ expect(sm).toBeDefined();
242
+
243
+ const shippingInstruction = ShippingInstructionSchema.parse({
244
+ shippingMethod: sm?.identifier || { key: '' },
245
+ amount: checkout.price.totalShipping,
246
+ instructions: 'Leave at front door if not home',
247
+ consentForUnattendedDelivery: true,
248
+ pickupPoint: '4190asx141', // this would be a real pickup point ID in a real scenario
249
+ });
250
+
251
+ const checkoutWithShipping = await provider.setShippingInstruction(
252
+ {
253
+ checkout: checkout.identifier,
254
+ shippingInstruction,
255
+ },
256
+ reqCtx
257
+ );
258
+
259
+ expect(checkout.price.totalShipping.value).toBe(0);
260
+ expect(checkoutWithShipping.price.totalShipping.value).toBeGreaterThan(0);
261
+ expect(checkoutWithShipping.shippingInstruction).toBeDefined();
262
+ expect(
263
+ checkoutWithShipping.shippingInstruction?.shippingMethod.key
264
+ ).toBe('us-delivery');
265
+ expect(checkoutWithShipping.shippingInstruction?.instructions).toBe(
266
+ 'Leave at front door if not home'
267
+ );
268
+ expect(checkoutWithShipping.shippingInstruction?.pickupPoint).toBe(
269
+ '4190asx141'
270
+ );
271
+ expect(
272
+ checkoutWithShipping.shippingInstruction?.consentForUnattendedDelivery
273
+ ).toBe(true);
274
+ });
275
+
276
+ xit('wont report it finalizable until everything is paid/authorized', async () => {
277
+ expect(checkout.readyForFinalization).toBe(false);
278
+ const pm = (
279
+ await provider.getAvailablePaymentMethods(
280
+ {
281
+ checkout: checkout.identifier,
282
+ },
283
+ reqCtx
284
+ )
285
+ ).find((x) => x.identifier.method === 'stripe');
286
+ expect(pm).toBeDefined();
287
+
288
+ const checkoutWithPi = await provider.addPaymentInstruction(
289
+ {
290
+ checkout: checkout.identifier,
291
+ paymentInstruction: PaymentInstructionSchema.parse({
292
+ paymentMethod: pm?.identifier,
293
+ amount: checkout.price.grandTotal,
294
+ protocolData: [{ key: 'test-key', value: 'test-value' }],
295
+ }),
296
+ },
297
+ reqCtx
298
+ );
299
+
300
+ // do something to simulate payment authorization ?
301
+ const checkoutReady = await provider.getById(
302
+ { identifier: checkoutWithPi.identifier },
303
+ reqCtx
304
+ );
305
+ if (!checkoutReady) {
306
+ fail('checkout not found');
307
+ }
308
+ expect(checkoutReady.readyForFinalization).toBe(true);
309
+ });
310
+ });
311
+ });
312
+ });
@@ -6,9 +6,9 @@ import {
6
6
  NoOpCache,
7
7
  createInitialRequestContext,
8
8
  } from '@reactionary/core';
9
- import { getCommercetoolsTestConfiguration } from './test-utils';
10
- import { CommercetoolsIdentityProvider } from '../providers/identity.provider';
11
- import { CommercetoolsCartProvider } from '../providers/cart.provider';
9
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
10
+ import { CommercetoolsIdentityProvider } from '../providers/identity.provider.js';
11
+ import { CommercetoolsCartProvider } from '../providers/cart.provider.js';
12
12
 
13
13
  describe('Commercetools Identity Provider', () => {
14
14
  let provider: CommercetoolsIdentityProvider;
@@ -5,8 +5,8 @@ import {
5
5
  NoOpCache,
6
6
  createInitialRequestContext,
7
7
  } from '@reactionary/core';
8
- import { getCommercetoolsTestConfiguration } from './test-utils';
9
- import { CommercetoolsInventoryProvider } from '../providers/inventory.provider';
8
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
9
+ import { CommercetoolsInventoryProvider } from '../providers/inventory.provider.js';
10
10
 
11
11
  describe('Commercetools Inventory Provider', () => {
12
12
  let provider: CommercetoolsInventoryProvider;
@@ -2,10 +2,10 @@ import 'dotenv/config';
2
2
 
3
3
 
4
4
  import type { RequestContext} from '@reactionary/core';
5
- import { NoOpCache, PriceSchema, Session, createInitialRequestContext,} from '@reactionary/core';
6
- import { getCommercetoolsTestConfiguration } from './test-utils';
5
+ import { NoOpCache, PriceSchema, createInitialRequestContext,} from '@reactionary/core';
6
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
7
7
 
8
- import { CommercetoolsPriceProvider } from '../providers/price.provider';
8
+ import { CommercetoolsPriceProvider } from '../providers/price.provider.js';
9
9
 
10
10
  const testData = {
11
11
  skuWithoutTiers: 'SGB-01',
@@ -39,7 +39,7 @@ describe('Commercetools Price Provider', () => {
39
39
  }
40
40
  });
41
41
 
42
- it('should be able to get prices for a product with tiers', async () => {
42
+ xit('should be able to get prices for a product with tiers', async () => {
43
43
  const result = await provider.getBySKU({ sku: { key: testData.skuWithTiers }}, reqCtx);
44
44
 
45
45
  expect(result).toBeTruthy();
@@ -1,15 +1,18 @@
1
1
  import 'dotenv/config';
2
2
  import type { RequestContext} from '@reactionary/core';
3
- import { NoOpCache, ProductSchema, Session, createInitialRequestContext } from '@reactionary/core';
4
- import { CommercetoolsProductProvider } from '../providers/product.provider';
5
- import { getCommercetoolsTestConfiguration } from './test-utils';
3
+ import { NoOpCache, ProductSchema, createInitialRequestContext } from '@reactionary/core';
4
+ import { CommercetoolsProductProvider } from '../providers/product.provider.js';
5
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
6
6
 
7
7
  const testData = {
8
8
  product : {
9
9
  id: '4d28f98d-c446-446e-b59a-d9f718e5b98a',
10
10
  name: 'Sunnai Glass Bowl',
11
- image: 'https://storage.googleapis.com/merchant-center-europe/sample-data/goodstore/Sunnai_Glass_Bowl-1.1.jpeg'
12
- }
11
+ image: 'https://storage.googleapis.com/merchant-center-europe/sample-data/goodstore/Sunnai_Glass_Bowl-1.1.jpeg',
12
+ sku: 'SGB-01',
13
+
14
+ },
15
+
13
16
  }
14
17
 
15
18
  describe('Commercetools Product Provider', () => {
@@ -48,12 +51,26 @@ describe('Commercetools Product Provider', () => {
48
51
  }
49
52
  });
50
53
 
54
+ it('should be able to get a product by sku', async () => {
55
+ const result = await provider.getBySKU( { sku: { key: testData.product.sku } }, reqCtx);
56
+
57
+ expect(result).toBeTruthy();
58
+ if (result) {
59
+ expect(result.meta.placeholder).toBe(false);
60
+ expect(result.identifier.key).toBe(testData.product.id);
61
+ expect(result.name).toBe(testData.product.name);
62
+ expect(result.image).toBe(testData.product.image);
63
+ }
64
+ });
65
+
51
66
  it('should return null for unknown slug', async () => {
52
67
  const result = await provider.getBySlug( { slug: 'unknown-slug' }, reqCtx);
53
68
 
54
69
  expect(result).toBeNull();
55
70
  });
56
71
 
72
+
73
+
57
74
  it('should return a placeholder product for unknown id', async () => {
58
75
  const result = await provider.getById( { id: 'unknown-id' }, reqCtx);
59
76
 
@@ -6,9 +6,9 @@ import {
6
6
  ProfileSchema,
7
7
  createInitialRequestContext,
8
8
  } from '@reactionary/core';
9
- import { getCommercetoolsTestConfiguration } from './test-utils';
10
- import { CommercetoolsProfileProvider } from '../providers/profile.provider';
11
- import { CommercetoolsIdentityProvider } from '../providers/identity.provider';
9
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
10
+ import { CommercetoolsProfileProvider } from '../providers/profile.provider.js';
11
+ import { CommercetoolsIdentityProvider } from '../providers/identity.provider.js';
12
12
 
13
13
  describe('Commercetools Profile Provider', () => {
14
14
  let provider: CommercetoolsProfileProvider;
@@ -1,8 +1,8 @@
1
1
  import 'dotenv/config';
2
2
  import type { RequestContext} from '@reactionary/core';
3
3
  import { NoOpCache, SearchResultSchema, createInitialRequestContext } from '@reactionary/core';
4
- import { CommercetoolsSearchProvider } from '../providers/search.provider';
5
- import { getCommercetoolsTestConfiguration } from './test-utils';
4
+ import { CommercetoolsSearchProvider } from '../providers/search.provider.js';
5
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
6
6
 
7
7
  const testData = {
8
8
  searchTerm: 'bowl'
@@ -5,8 +5,8 @@ import {
5
5
  StoreSchema,
6
6
  createInitialRequestContext,
7
7
  } from '@reactionary/core';
8
- import { getCommercetoolsTestConfiguration } from './test-utils';
9
- import { CommercetoolsStoreProvider } from '../providers/store.provider';
8
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
9
+ import { CommercetoolsStoreProvider } from '../providers/store.provider.js';
10
10
 
11
11
  describe('Commercetools Store Provider', () => {
12
12
  let provider: CommercetoolsStoreProvider;
@@ -1,3 +1,6 @@
1
+ import { PaymentMethodSchema } from '@reactionary/core';
2
+ import { PaymentMethodIdentifierSchema } from '@reactionary/core';
3
+
1
4
  export function getCommercetoolsTestConfiguration() {
2
5
  return {
3
6
  apiUrl: process.env['CTP_API_URL'] || '',
@@ -6,6 +9,17 @@ export function getCommercetoolsTestConfiguration() {
6
9
  clientSecret: process.env['CTP_CLIENT_SECRET'] || '',
7
10
  projectKey: process.env['CTP_PROJECT_KEY'] || '',
8
11
  scopes: (process.env['CTP_SCOPES'] || '').split(',').map(x => x.trim()).filter(x => x && x.length > 0),
12
+
13
+ paymentMethods: [
14
+ PaymentMethodSchema.parse({
15
+ identifier: PaymentMethodIdentifierSchema.parse({
16
+ paymentProvider: 'stripe',
17
+ method: 'stripe',
18
+ name: 'Stripe',
19
+ }),
20
+ description: 'Stripe payment gateway'
21
+ })
22
+ ]
9
23
  }
10
24
  }
11
25
 
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "module": "commonjs",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
5
6
  "forceConsistentCasingInFileNames": true,
6
7
  "strict": true,
7
8
  "importHelpers": true,
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
4
  "module": "commonjs",
6
- "moduleResolution": "node10",
5
+ "moduleResolution": "node",
6
+ "verbatimModuleSyntax": false,
7
+ "outDir": "../../dist/out-tsc",
7
8
  "types": ["jest", "node"]
8
9
  },
9
10
  "include": [
10
- "jest.config.ts",
11
+ "jest.config.cjs",
11
12
  "src/**/*.test.ts",
12
13
  "src/**/*.spec.ts",
13
14
  "src/**/*.d.ts"
@@ -1,4 +1,4 @@
1
- export default {
1
+ module.exports = {
2
2
  displayName: 'provider-faker',
3
3
  preset: '../../jest.preset.js',
4
4
  testEnvironment: 'node',
@@ -5,8 +5,8 @@
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
7
  "@reactionary/core": "0.0.1",
8
- "@reactionary/otel": "0.0.1",
9
8
  "zod": "4.1.9",
10
9
  "@faker-js/faker": "^9.8.0"
11
- }
10
+ },
11
+ "type": "module"
12
12
  }
@@ -18,17 +18,17 @@ import {
18
18
  StoreSchema,
19
19
  PriceSchema,
20
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';
21
+ import { FakeProductProvider } from '../providers/product.provider.js';
22
+ import { FakeSearchProvider } from '../providers/search.provider.js';
23
+ import type { FakeConfiguration } from '../schema/configuration.schema.js';
24
+ import type { FakeCapabilities } from '../schema/capabilities.schema.js';
25
+ import { FakeCategoryProvider } from '../providers/category.provider.js';
26
26
  import {
27
27
  FakeCartProvider,
28
28
  FakeInventoryProvider,
29
29
  FakePriceProvider,
30
30
  FakeStoreProvider,
31
- } from '../providers';
31
+ } from '../providers/index.js';
32
32
 
33
33
  type FakeClient<T extends FakeCapabilities> = (T['cart'] extends true
34
34
  ? { cart: CartProvider }
@@ -1,5 +1,5 @@
1
- export * from './core/initialize';
1
+ export * from './core/initialize.js';
2
2
 
3
- export * from './providers/'
4
- export * from './schema/capabilities.schema';
5
- export * from './schema/configuration.schema';
3
+ export * from './providers/index.js'
4
+ export * from './schema/capabilities.schema.js';
5
+ export * from './schema/configuration.schema.js';
@@ -5,7 +5,7 @@ import {
5
5
  AnalyticsProvider
6
6
  } from '@reactionary/core';
7
7
  import type z from 'zod';
8
- import type { FakeConfiguration } from '../schema/configuration.schema';
8
+ import type { FakeConfiguration } from '../schema/configuration.schema.js';
9
9
 
10
10
  export class FakeAnalyticsProvider<
11
11
  T extends BaseModel = BaseModel
@@ -4,7 +4,7 @@ import type {
4
4
  CartMutationItemAdd,
5
5
  CartMutationItemRemove,
6
6
  CartMutationItemQuantityChange,
7
- Session, RequestContext,
7
+ RequestContext,
8
8
  Cache,
9
9
  CartIdentifier,
10
10
  CartMutationApplyCoupon,
@@ -19,7 +19,7 @@ import {
19
19
  CartProvider
20
20
  } from '@reactionary/core';
21
21
  import type z from 'zod';
22
- import type { FakeConfiguration } from '../schema/configuration.schema';
22
+ import type { FakeConfiguration } from '../schema/configuration.schema.js';
23
23
  import { Faker, en, base } from '@faker-js/faker';
24
24
 
25
25
  export class FakeCartProvider<
@@ -1,6 +1,6 @@
1
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";
2
+ import { CategoryProvider, Reactionary } from "@reactionary/core";
3
+ import type { FakeConfiguration } from "../schema/configuration.schema.js";
4
4
  import type { Cache as ReactionaryCache } from "@reactionary/core";
5
5
  import type z from "zod";
6
6
  import { Faker, en, base } from '@faker-js/faker';
@@ -71,9 +71,10 @@ export class FakeCategoryProvider<
71
71
  });
72
72
  }
73
73
 
74
+ @Reactionary({})
74
75
  public override async getById(payload: CategoryQueryById, reqCtx: RequestContext): Promise<T> {
75
76
  const category = this.allCategories.get(payload.id.key);
76
-
77
+
77
78
  if(!category) {
78
79
  const dummyCategory = this.newModel();
79
80
  dummyCategory.meta.placeholder = true;
@@ -82,6 +83,8 @@ export class FakeCategoryProvider<
82
83
  }
83
84
  return category;
84
85
  }
86
+
87
+ @Reactionary({})
85
88
  public override getBySlug(payload: CategoryQueryBySlug, reqCtx: RequestContext): Promise<T | null> {
86
89
  for(const p of this.allCategories.values()) {
87
90
  if(p.slug === payload.slug) {
@@ -91,6 +94,7 @@ export class FakeCategoryProvider<
91
94
  return Promise.resolve(null);
92
95
  }
93
96
 
97
+ @Reactionary({})
94
98
  public override getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, reqCtx: RequestContext): Promise<T[]> {
95
99
  const path = new Array<T>();
96
100
  let category = this.allCategories.get(payload.id.key);
@@ -9,7 +9,7 @@ import {
9
9
  type IdentityMutationRegister,
10
10
  } from '@reactionary/core';
11
11
  import type z from 'zod';
12
- import type { FakeConfiguration } from '../schema/configuration.schema';
12
+ import type { FakeConfiguration } from '../schema/configuration.schema.js';
13
13
  import { base, en, Faker } from '@faker-js/faker';
14
14
 
15
15
  export class FakeIdentityProvider<
@@ -1,9 +1,9 @@
1
- export * from './analytics.provider';
2
- export * from './cart.provider';
3
- export * from './category.provider';
4
- export * from './identity.provider';
5
- export * from './inventory.provider';
6
- export * from './price.provider';
7
- export * from './product.provider';
8
- export * from './search.provider';
9
- export * from './store.provider';
1
+ export * from './analytics.provider.js';
2
+ export * from './cart.provider.js';
3
+ export * from './category.provider.js';
4
+ export * from './identity.provider.js';
5
+ export * from './inventory.provider.js';
6
+ export * from './price.provider.js';
7
+ export * from './product.provider.js';
8
+ export * from './search.provider.js';
9
+ export * from './store.provider.js';
@@ -8,7 +8,7 @@ import {
8
8
  InventoryProvider
9
9
  } from '@reactionary/core';
10
10
  import type z from 'zod';
11
- import type { FakeConfiguration } from '../schema/configuration.schema';
11
+ import type { FakeConfiguration } from '../schema/configuration.schema.js';
12
12
  import { base, en, Faker } from '@faker-js/faker';
13
13
 
14
14
  export class FakeInventoryProvider<