@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
@@ -1,9 +1,12 @@
1
- export * from './cart.provider';
2
- export * from './category.provider';
3
- export * from './identity.provider';
4
- export * from './inventory.provider';
5
- export * from './price.provider';
6
- export * from './product.provider';
7
- export * from './profile.provider';
8
- export * from './search.provider';
9
- export * from './store.provider';
1
+ export * from './cart.provider.js';
2
+ export * from './category.provider.js';
3
+ export * from './identity.provider.js';
4
+ export * from './inventory.provider.js';
5
+ export * from './price.provider.js';
6
+ export * from './product.provider.js';
7
+ export * from './profile.provider.js';
8
+ export * from './search.provider.js';
9
+ export * from './store.provider.js';
10
+
11
+ export * from './order.provider.js';
12
+ export * from './checkout.provider.js';
@@ -6,12 +6,10 @@ import type {
6
6
  } from '@reactionary/core';
7
7
  import { InventoryProvider } from '@reactionary/core';
8
8
  import type z from 'zod';
9
- import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
10
- import { CommercetoolsClient } from '../core/client';
9
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
10
+ import { CommercetoolsClient } from '../core/client.js';
11
11
  import type {
12
12
  InventoryEntry,
13
- ProductVariant,
14
- ProductVariantAvailability,
15
13
  } from '@commercetools/platform-sdk';
16
14
  export class CommercetoolsInventoryProvider<
17
15
  T extends Inventory = Inventory
@@ -0,0 +1,163 @@
1
+ import type {
2
+ RequestContext,
3
+ Cache,
4
+ Order,
5
+ OrderQueryById,
6
+ Currency} from '@reactionary/core';
7
+ import { OrderItemSchema, OrderProvider } from '@reactionary/core';
8
+ import type z from 'zod';
9
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
10
+ import { CommercetoolsClient } from '../core/client.js';
11
+ import type { Order as CTOrder } from '@commercetools/platform-sdk';
12
+ import { CommercetoolsOrderIdentifierSchema } from '../schema/commercetools.schema.js';
13
+ export class CommercetoolsOrderProvider<
14
+ T extends Order = Order
15
+ > extends OrderProvider<T> {
16
+ protected config: CommercetoolsConfiguration;
17
+
18
+ constructor(
19
+ config: CommercetoolsConfiguration,
20
+ schema: z.ZodType<T>,
21
+ cache: Cache
22
+ ) {
23
+ super(schema, cache);
24
+
25
+ this.config = config;
26
+ }
27
+
28
+ protected async getClient(reqCtx: RequestContext) {
29
+
30
+ const client = await new CommercetoolsClient(this.config).getClient(
31
+ reqCtx
32
+ );
33
+ return client.withProjectKey({ projectKey: this.config.projectKey }).me().orders();
34
+ }
35
+
36
+
37
+ public override async getById(payload: OrderQueryById, reqCtx: RequestContext): Promise<T> {
38
+ const client = await new CommercetoolsClient(this.config).getClient(reqCtx);
39
+
40
+ try {
41
+ const remote = await client
42
+ .withProjectKey({ projectKey: this.config.projectKey })
43
+ .orders()
44
+ .withId({ ID: payload.order.key })
45
+ .get()
46
+ .execute();
47
+
48
+ return this.parseSingle(remote.body, reqCtx);
49
+ } catch (e) {
50
+ return this.createEmptyOrder();
51
+ }
52
+ }
53
+
54
+
55
+ protected override parseSingle(_body: unknown, reqCtx: RequestContext): T {
56
+ const remote = _body as CTOrder;
57
+ const result = this.newModel();
58
+
59
+ result.identifier = CommercetoolsOrderIdentifierSchema.parse({
60
+ key: remote.id,
61
+ version: remote.version || 0,
62
+ });
63
+
64
+
65
+
66
+ result.name = remote.custom?.fields['name'] || '';
67
+ result.description = remote.custom?.fields['description'] || '';
68
+
69
+ const grandTotal = remote.totalPrice.centAmount || 0;
70
+ const shippingTotal = remote.shippingInfo?.price.centAmount || 0;
71
+ const productTotal = grandTotal - shippingTotal;
72
+ const taxTotal = remote.taxedPrice?.totalTax?.centAmount || 0;
73
+ const discountTotal =
74
+ remote.discountOnTotalPrice?.discountedAmount.centAmount || 0;
75
+ const surchargeTotal = 0;
76
+ const currency = remote.totalPrice.currencyCode as Currency;
77
+
78
+ result.price = {
79
+ totalTax: {
80
+ value: taxTotal / 100,
81
+ currency,
82
+ },
83
+ totalDiscount: {
84
+ value: discountTotal / 100,
85
+ currency,
86
+ },
87
+ totalSurcharge: {
88
+ value: surchargeTotal / 100,
89
+ currency,
90
+ },
91
+ totalShipping: {
92
+ value: shippingTotal / 100,
93
+ currency: remote.shippingInfo?.price.currencyCode as Currency,
94
+ },
95
+ totalProductPrice: {
96
+ value: productTotal / 100,
97
+ currency,
98
+ },
99
+ grandTotal: {
100
+ value: grandTotal / 100,
101
+ currency,
102
+ },
103
+ };
104
+
105
+ if (remote.paymentState === 'Pending' && remote.orderState === 'Open') {
106
+ result.orderStatus = 'AwaitingPayment';
107
+ } else if (remote.paymentState === 'Paid' && remote.orderState === 'Confirmed') {
108
+ result.orderStatus = 'ReleasedToFulfillment';
109
+ }
110
+ if (remote.shipmentState === 'Ready' && remote.orderState === 'Confirmed') {
111
+ result.orderStatus = 'ReleasedToFulfillment';
112
+ }
113
+ if ( (remote.shipmentState === 'Shipped' || remote.shipmentState === 'Delivered') && remote.orderState === 'Completed') {
114
+ result.orderStatus = 'Shipped';
115
+ }
116
+
117
+ for (const remoteItem of remote.lineItems) {
118
+ const item = OrderItemSchema.parse({});
119
+
120
+ item.identifier.key = remoteItem.id;
121
+ item.sku.key = remoteItem.variant.sku || '';
122
+ item.quantity = remoteItem.quantity;
123
+
124
+ const unitPrice = remoteItem.price.value.centAmount;
125
+ const totalPrice = remoteItem.totalPrice.centAmount || 0;
126
+ const totalDiscount = remoteItem.price.discounted?.value.centAmount || 0;
127
+ const unitDiscount = totalDiscount / remoteItem.quantity;
128
+
129
+ item.price = {
130
+ unitPrice: {
131
+ value: unitPrice / 100,
132
+ currency,
133
+ },
134
+ unitDiscount: {
135
+ value: unitDiscount / 100,
136
+ currency,
137
+ },
138
+ totalPrice: {
139
+ value: (totalPrice || 0) / 100,
140
+ currency,
141
+ },
142
+ totalDiscount: {
143
+ value: totalDiscount / 100,
144
+ currency,
145
+ },
146
+ };
147
+
148
+ result.items.push(item);
149
+ }
150
+
151
+ result.meta = {
152
+ cache: {
153
+ hit: false,
154
+ key: this.generateCacheKeySingle(result.identifier, reqCtx),
155
+ },
156
+ placeholder: false,
157
+ };
158
+
159
+
160
+
161
+ return this.assert(result);
162
+ }
163
+ }
@@ -1,8 +1,8 @@
1
1
  import { PriceProvider, TieredPriceSchema } from '@reactionary/core';
2
2
  import type { PriceQueryBySku, RequestContext , Price, Cache, Currency, TieredPrice } from '@reactionary/core';
3
3
  import type z from 'zod';
4
- import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
5
- import { CommercetoolsClient } from '../core/client';
4
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
5
+ import { CommercetoolsClient } from '../core/client.js';
6
6
  import type { Price as CTPrice, ProductVariant as CTProductVariant } from '@commercetools/platform-sdk';
7
7
  export class CommercetoolsPriceProvider<
8
8
  T extends Price = Price
@@ -38,7 +38,7 @@ export class CommercetoolsPriceProvider<
38
38
  const response = await client.get({
39
39
  queryArgs: {
40
40
  staged: false,
41
- priceCountry: 'US',
41
+ priceCountry: reqCtx.taxJurisdiction.countryCode,
42
42
  priceCustomerGroup: undefined,
43
43
  priceChannel: channels.offerChannelGUID,
44
44
  priceCurrency: reqCtx.languageContext.currencyCode,
@@ -1,12 +1,11 @@
1
1
  import {
2
2
  ProductProvider
3
3
  } from '@reactionary/core';
4
- import { CommercetoolsClient } from '../core/client';
4
+ import { CommercetoolsClient } from '../core/client.js';
5
5
  import type { z } from 'zod';
6
- import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
6
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
7
7
  import type { ProductProjection } from '@commercetools/platform-sdk';
8
- import { traced } from '@reactionary/otel';
9
- import type { Product, ProductQueryById, ProductQueryBySlug, RequestContext } from '@reactionary/core';
8
+ import type { Product, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext } from '@reactionary/core';
10
9
  import type { Cache } from '@reactionary/core';
11
10
 
12
11
  export class CommercetoolsProductProvider<
@@ -26,7 +25,6 @@ export class CommercetoolsProductProvider<
26
25
  return client.withProjectKey({ projectKey: this.config.projectKey }).productProjections();
27
26
  }
28
27
 
29
- @traced()
30
28
  public override async getById(
31
29
  payload: ProductQueryById,
32
30
  reqCtx: RequestContext
@@ -45,7 +43,6 @@ export class CommercetoolsProductProvider<
45
43
  }
46
44
  }
47
45
 
48
- @traced()
49
46
  public override async getBySlug(
50
47
  payload: ProductQueryBySlug,
51
48
  reqCtx: RequestContext
@@ -67,6 +64,27 @@ export class CommercetoolsProductProvider<
67
64
  return this.parseSingle(remote.body.results[0], reqCtx);
68
65
  }
69
66
 
67
+ public override async getBySKU(
68
+ payload: ProductQueryBySKU,
69
+ reqCtx: RequestContext
70
+ ): Promise<T> {
71
+ const client = await this.getClient(reqCtx);
72
+
73
+ const remote = await client
74
+ .get({
75
+ queryArgs: {
76
+ staged: false,
77
+ limit: 1,
78
+ where: 'variants(sku in (:skus)) OR (masterVariant(sku in (:skus))) ',
79
+ 'var.skus': [payload].map(p => p.sku.key),
80
+ }
81
+ })
82
+ .execute();
83
+
84
+ return this.parseSingle(remote.body.results[0], reqCtx);
85
+ }
86
+
87
+
70
88
  protected override parseSingle(dataIn: unknown, reqCtx: RequestContext): T {
71
89
  const data = dataIn as ProductProjection;
72
90
  const base = this.newModel();
@@ -6,8 +6,8 @@ import type {
6
6
  } from '@reactionary/core';
7
7
  import { ProfileProvider } from '@reactionary/core';
8
8
  import type z from 'zod';
9
- import { CommercetoolsClient } from '../core/client';
10
- import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
9
+ import { CommercetoolsClient } from '../core/client.js';
10
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
11
11
  import type { Cache } from '@reactionary/core';
12
12
  import type { Customer } from '@commercetools/platform-sdk';
13
13
 
@@ -4,13 +4,12 @@ import type {
4
4
  SearchResultProduct,
5
5
  Cache,
6
6
  SearchQueryByTerm,
7
- Session, RequestContext,
7
+ RequestContext,
8
8
  } from '@reactionary/core';
9
9
 
10
- import { CommercetoolsClient } from '../core/client';
10
+ import { CommercetoolsClient } from '../core/client.js';
11
11
  import type z from 'zod';
12
- import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
13
- import { traced } from '@reactionary/otel';
12
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
14
13
 
15
14
  export class CommercetoolsSearchProvider<
16
15
  T extends SearchResult = SearchResult
@@ -27,7 +26,6 @@ export class CommercetoolsSearchProvider<
27
26
  this.config = config;
28
27
  }
29
28
 
30
- @traced()
31
29
  protected async getClient(reqCtx: RequestContext) {
32
30
  const client = await new CommercetoolsClient(this.config).getClient(reqCtx);
33
31
  return client.withProjectKey({ projectKey: this.config.projectKey }).productProjections();
@@ -5,9 +5,9 @@ import type {
5
5
  } from '@reactionary/core';
6
6
  import { StoreProvider } from '@reactionary/core';
7
7
  import type z from 'zod';
8
- import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
9
- import { CommercetoolsClient } from '../core/client';
10
- import type { Channel, InventoryEntry } from '@commercetools/platform-sdk';
8
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
9
+ import { CommercetoolsClient } from '../core/client.js';
10
+ import type { Channel } from '@commercetools/platform-sdk';
11
11
  import type { Store } from '@reactionary/core';
12
12
 
13
13
  export class CommercetoolsStoreProvider<
@@ -6,7 +6,8 @@ export const CommercetoolsCapabilitiesSchema = CapabilitiesSchema.pick({
6
6
  search: true,
7
7
  identity: true,
8
8
  cart: true,
9
- cartPayment: true,
9
+ checkout: true,
10
+ order: true,
10
11
  inventory: true,
11
12
  price: true,
12
13
  category: true,
@@ -1,18 +1,20 @@
1
- import { CartIdentifierSchema, OrderIdentifierSchema, PaymentInstructionIdentifierSchema } from "@reactionary/core";
1
+ import { CartIdentifierSchema, CheckoutIdentifierSchema, OrderIdentifierSchema } from "@reactionary/core";
2
2
  import z from "zod";
3
3
 
4
4
  export const CommercetoolsCartIdentifierSchema = CartIdentifierSchema.extend({
5
5
  version: z.number().default(0)
6
6
  });
7
7
 
8
- export const CommercetoolsCartPaymentInstructionIdentifierSchema = PaymentInstructionIdentifierSchema.extend({
9
- version: z.number().default(0),
10
- });
11
8
 
12
9
  export const CommercetoolsOrderIdentifierSchema = OrderIdentifierSchema.extend({
13
10
  version: z.number().default(0)
14
11
  });
15
12
 
13
+ export const CommercetoolsCheckoutIdentifierSchema = CheckoutIdentifierSchema.extend({
14
+ version: z.number().default(0)
15
+ });
16
+
17
+ export type CommercetoolsCheckoutIdentifier = z.infer<typeof CommercetoolsCheckoutIdentifierSchema>;
18
+
16
19
  export type CommercetoolsCartIdentifier = z.infer<typeof CommercetoolsCartIdentifierSchema>;
17
- export type CommercetoolsCartPaymentInstructionIdentifier = z.infer<typeof CommercetoolsCartPaymentInstructionIdentifierSchema>;
18
20
  export type CommercetoolsOrderIdentifier = z.infer<typeof CommercetoolsOrderIdentifierSchema>;
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { PaymentMethodSchema } from '@reactionary/core';
2
3
 
3
4
  export const CommercetoolsConfigurationSchema = z.looseObject({
4
5
  projectKey: z.string(),
@@ -7,6 +8,7 @@ export const CommercetoolsConfigurationSchema = z.looseObject({
7
8
  clientId: z.string(),
8
9
  clientSecret: z.string(),
9
10
  scopes: z.array(z.string()).default(() => []),
11
+ paymentMethods: PaymentMethodSchema.array().optional().default(() => []),
10
12
  });
11
13
 
12
14
  export type CommercetoolsConfiguration = z.infer<typeof CommercetoolsConfigurationSchema>;
@@ -1,9 +1,10 @@
1
1
  import 'dotenv/config';
2
2
  import type { RequestContext} from '@reactionary/core';
3
- import { CartSchema, IdentitySchema, NoOpCache, createInitialRequestContext } from '@reactionary/core';
4
- import { getCommercetoolsTestConfiguration } from './test-utils';
5
- import { CommercetoolsCartProvider } from '../providers/cart.provider';
6
- import { CommercetoolsIdentityProvider } from '../providers/identity.provider';
3
+ import { CartSchema, IdentitySchema, NoOpCache, ProductSchema, createInitialRequestContext } from '@reactionary/core';
4
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
5
+ import { CommercetoolsCartProvider } from '../providers/cart.provider.js';
6
+ import { CommercetoolsIdentityProvider } from '../providers/identity.provider.js';
7
+ import { CommercetoolsProductProvider } from '../providers/product.provider.js';
7
8
 
8
9
 
9
10
  const testData = {
@@ -13,12 +14,14 @@ const testData = {
13
14
 
14
15
  describe('Commercetools Cart Provider', () => {
15
16
  let provider: CommercetoolsCartProvider;
17
+ let productProvider: CommercetoolsProductProvider;
16
18
  let identityProvider: CommercetoolsIdentityProvider;
17
19
  let reqCtx: RequestContext;
18
20
 
19
21
  beforeAll( () => {
20
22
  provider = new CommercetoolsCartProvider(getCommercetoolsTestConfiguration(), CartSchema, new NoOpCache());
21
23
  identityProvider = new CommercetoolsIdentityProvider(getCommercetoolsTestConfiguration(), IdentitySchema, new NoOpCache());
24
+ productProvider = new CommercetoolsProductProvider(getCommercetoolsTestConfiguration(), ProductSchema, new NoOpCache());
22
25
  });
23
26
 
24
27
  beforeEach( () => {
@@ -162,6 +165,23 @@ describe('Commercetools Cart Provider', () => {
162
165
  expect(originalCart.items.length).toBe(0);
163
166
  });
164
167
 
168
+ it('can load the product information for cart items', async () => {
169
+
170
+ const cart = await provider.add({
171
+ cart: { key: '' },
172
+ sku: {
173
+ key: testData.skuWithoutTiers,
174
+ },
175
+ quantity: 1
176
+ }, reqCtx);
177
+ expect(cart.items[0].sku).toBeDefined();
178
+
179
+ const product = await productProvider.getBySKU( { sku: cart.items[0].sku }, reqCtx);
180
+ expect(product).toBeTruthy();
181
+ if (product) {
182
+ expect(product.skus.some(s => s.identifier.key === cart.items[0].sku.key)).toBe(true);
183
+ }
184
+ });
165
185
  /**
166
186
  it('should be able to create a cart for an anonymous user, then login and merge the cart', async () => {
167
187
  });
@@ -1,8 +1,8 @@
1
1
  import 'dotenv/config'
2
2
  import type { RequestContext} from '@reactionary/core';
3
- import { CategorySchema, NoOpCache, Session , createInitialRequestContext} from '@reactionary/core';
4
- import { CommercetoolsCategoryProvider } from '../providers/category.provider';
5
- import { getCommercetoolsTestConfiguration } from './test-utils';
3
+ import { CategorySchema, NoOpCache , createInitialRequestContext} from '@reactionary/core';
4
+ import { CommercetoolsCategoryProvider } from '../providers/category.provider.js';
5
+ import { getCommercetoolsTestConfiguration } from './test-utils.js';
6
6
 
7
7
  const testData = {
8
8
  topCategories: [