@reactionary/source 0.0.48 → 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/core/src/client/client.ts +2 -2
  2. package/core/src/providers/checkout.provider.ts +156 -0
  3. package/core/src/providers/index.ts +3 -2
  4. package/core/src/providers/order.provider.ts +31 -0
  5. package/core/src/providers/product.provider.ts +2 -2
  6. package/core/src/schemas/capabilities.schema.ts +2 -1
  7. package/core/src/schemas/models/cart.model.ts +1 -20
  8. package/core/src/schemas/models/checkout.model.ts +68 -0
  9. package/core/src/schemas/models/cost.model.ts +21 -0
  10. package/core/src/schemas/models/identifiers.model.ts +23 -2
  11. package/core/src/schemas/models/identity.model.ts +6 -3
  12. package/core/src/schemas/models/index.ts +5 -1
  13. package/core/src/schemas/models/order.model.ts +47 -0
  14. package/core/src/schemas/models/payment.model.ts +3 -10
  15. package/core/src/schemas/models/product.model.ts +6 -3
  16. package/core/src/schemas/models/shipping-method.model.ts +32 -1
  17. package/core/src/schemas/mutations/checkout.mutation.ts +50 -0
  18. package/core/src/schemas/mutations/index.ts +1 -1
  19. package/core/src/schemas/queries/checkout.query.ts +22 -0
  20. package/core/src/schemas/queries/index.ts +3 -2
  21. package/core/src/schemas/queries/order.query.ts +9 -0
  22. package/core/src/schemas/queries/product.query.ts +8 -1
  23. package/otel/src/trace-decorator.ts +8 -8
  24. package/package.json +3 -1
  25. package/providers/algolia/src/providers/product.provider.ts +7 -1
  26. package/providers/commercetools/package.json +1 -0
  27. package/providers/commercetools/src/core/client.ts +62 -31
  28. package/providers/commercetools/src/core/initialize.ts +11 -7
  29. package/providers/commercetools/src/providers/cart.provider.ts +10 -1
  30. package/providers/commercetools/src/providers/checkout.provider.ts +644 -0
  31. package/providers/commercetools/src/providers/identity.provider.ts +6 -6
  32. package/providers/commercetools/src/providers/index.ts +4 -1
  33. package/providers/commercetools/src/providers/order.provider.ts +165 -0
  34. package/providers/commercetools/src/providers/price.provider.ts +1 -1
  35. package/providers/commercetools/src/providers/product.provider.ts +24 -1
  36. package/providers/commercetools/src/schema/capabilities.schema.ts +2 -1
  37. package/providers/commercetools/src/schema/commercetools.schema.ts +7 -5
  38. package/providers/commercetools/src/schema/configuration.schema.ts +2 -0
  39. package/providers/commercetools/src/test/cart.provider.spec.ts +21 -1
  40. package/providers/commercetools/src/test/checkout.provider.spec.ts +312 -0
  41. package/providers/commercetools/src/test/price.provider.spec.ts +1 -1
  42. package/providers/commercetools/src/test/product.provider.spec.ts +19 -2
  43. package/providers/commercetools/src/test/test-utils.ts +14 -0
  44. package/providers/fake/src/providers/category.provider.ts +6 -2
  45. package/providers/fake/src/providers/product.provider.ts +9 -3
  46. package/providers/fake/src/test/product.provider.spec.ts +7 -7
  47. package/trpc/src/server.ts +1 -1
  48. package/trpc/src/transparent-client.spec.ts +4 -5
  49. package/.claude/settings.local.json +0 -28
  50. package/core/src/providers/cart-payment.provider.ts +0 -57
  51. package/core/src/schemas/mutations/cart-payment.mutation.ts +0 -21
  52. package/core/src/schemas/queries/cart-payment.query.ts +0 -12
  53. package/providers/commercetools/src/providers/cart-payment.provider.ts +0 -193
  54. package/providers/commercetools/src/test/cart-payment.provider.spec.ts +0 -145
  55. package/trpc/src/test-utils.ts +0 -31
@@ -0,0 +1,50 @@
1
+ import z from "zod";
2
+ import { CartIdentifierSchema, AddressSchema, PaymentInstructionIdentifierSchema, PaymentInstructionSchema, ShippingInstructionSchema } from "../models";
3
+ import { BaseMutationSchema } from "./base.mutation";
4
+
5
+
6
+ export const CheckoutMutationInitiateCheckoutSchema = BaseMutationSchema.extend({
7
+ cart: CartIdentifierSchema.required(),
8
+ billingAddress: AddressSchema.omit({identifier: true}).optional(),
9
+ notificationEmail: z.string().optional(),
10
+ notificationPhone: z.string().optional(),
11
+ });
12
+
13
+ export const CheckoutMutationSetShippingAddressSchema = BaseMutationSchema.extend({
14
+ checkout: CartIdentifierSchema.required(),
15
+ shippingAddress: AddressSchema.omit({identifier: true}).required(),
16
+ });
17
+
18
+
19
+ export const CheckoutMutationFinalizeCheckoutSchema = BaseMutationSchema.extend({
20
+ checkout: CartIdentifierSchema.required(),
21
+ });
22
+
23
+
24
+ export const CheckoutMutationAddPaymentInstruction = BaseMutationSchema.extend({
25
+ paymentInstruction: PaymentInstructionSchema.omit({ meta: true, status: true, identifier: true }).required(),
26
+ checkout: CartIdentifierSchema.required()
27
+ });
28
+
29
+ export const CheckoutMutationRemovePaymentInstruction = BaseMutationSchema.extend({
30
+ paymentInstruction: PaymentInstructionIdentifierSchema.required(),
31
+ checkout: CartIdentifierSchema.required()
32
+ });
33
+
34
+
35
+
36
+ export const CheckoutMutationSetShippingInstruction = BaseMutationSchema.extend({
37
+ shippingInstruction: ShippingInstructionSchema.omit({ meta: true, status: true, identifier: true }).required(),
38
+ checkout: CartIdentifierSchema.required()
39
+ });
40
+
41
+
42
+
43
+
44
+
45
+ export type CheckoutMutationInitiateCheckout = z.infer<typeof CheckoutMutationInitiateCheckoutSchema>;
46
+ export type CheckoutMutationSetShippingAddress = z.infer<typeof CheckoutMutationSetShippingAddressSchema>;
47
+ export type CheckoutMutationFinalizeCheckout = z.infer<typeof CheckoutMutationFinalizeCheckoutSchema>;
48
+ export type CheckoutMutationAddPaymentInstruction = z.infer<typeof CheckoutMutationAddPaymentInstruction>;
49
+ export type CheckoutMutationRemovePaymentInstruction = z.infer<typeof CheckoutMutationRemovePaymentInstruction>;
50
+ export type CheckoutMutationSetShippingInstruction = z.infer<typeof CheckoutMutationSetShippingInstruction>;
@@ -1,6 +1,5 @@
1
1
  export * from './analytics.mutation';
2
2
  export * from './base.mutation';
3
- export * from './cart-payment.mutation';
4
3
  export * from './cart.mutation';
5
4
  export * from './identity.mutation';
6
5
  export * from './inventory.mutation';
@@ -8,3 +7,4 @@ export * from './price.mutation';
8
7
  export * from './product.mutation';
9
8
  export * from './profile.mutation';
10
9
  export * from './search.mutation';
10
+ export * from './checkout.mutation';
@@ -0,0 +1,22 @@
1
+ import type { z } from 'zod';
2
+ import { BaseQuerySchema } from './base.query';
3
+ import { CartIdentifierSchema, CheckoutIdentifierSchema } from '../models/identifiers.model';
4
+
5
+ export const CheckoutQueryByIdSchema = BaseQuerySchema.extend({
6
+ identifier: CheckoutIdentifierSchema.required()
7
+ });
8
+
9
+
10
+ export const CheckoutQueryForAvailableShippingMethodsSchema = BaseQuerySchema.extend({
11
+ checkout: CheckoutIdentifierSchema.required()
12
+ });
13
+
14
+ export const CheckoutQueryForAvailablePaymentMethodsSchema = BaseQuerySchema.extend({
15
+ checkout: CheckoutIdentifierSchema.required()
16
+ });
17
+
18
+
19
+
20
+ export type CheckoutQueryForAvailableShippingMethods = z.infer<typeof CheckoutQueryForAvailableShippingMethodsSchema>;
21
+ export type CheckoutQueryForAvailablePaymentMethods = z.infer<typeof CheckoutQueryForAvailablePaymentMethodsSchema>;
22
+ export type CheckoutQueryById = z.infer<typeof CheckoutQueryByIdSchema>;
@@ -1,6 +1,5 @@
1
1
  export * from './analytics.query';
2
2
  export * from './base.query';
3
- export * from './cart-payment.query';
4
3
  export * from './cart.query';
5
4
  export * from './category.query';
6
5
  export * from './identity.query';
@@ -9,4 +8,6 @@ export * from './price.query';
9
8
  export * from './product.query';
10
9
  export * from './profile.query';
11
10
  export * from './search.query';
12
- export * from './store.query';
11
+ export * from './store.query';
12
+ export * from './order.query';
13
+ export * from './checkout.query';
@@ -0,0 +1,9 @@
1
+ import type { z } from 'zod';
2
+ import { BaseQuerySchema } from './base.query';
3
+ import { OrderIdentifierSchema } from '../models/identifiers.model';
4
+
5
+ export const OrderQueryByIdSchema = BaseQuerySchema.extend({
6
+ order: OrderIdentifierSchema.required()
7
+ });
8
+
9
+ export type OrderQueryById = z.infer<typeof OrderQueryByIdSchema>;
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { BaseQuerySchema } from './base.query';
3
+ import { SKUIdentifierSchema } from '../models';
3
4
 
4
5
  export const ProductQueryBySlugSchema = BaseQuerySchema.extend({
5
6
  slug: z.string()
@@ -9,5 +10,11 @@ export const ProductQueryByIdSchema = BaseQuerySchema.extend({
9
10
  id: z.string()
10
11
  });
11
12
 
13
+ export const ProductQueryBySKUSchema = BaseQuerySchema.extend({
14
+ sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
15
+ });
16
+
17
+
12
18
  export type ProductQueryBySlug = z.infer<typeof ProductQueryBySlugSchema>;
13
- export type ProductQueryById = z.infer<typeof ProductQueryByIdSchema>;
19
+ export type ProductQueryById = z.infer<typeof ProductQueryByIdSchema>;
20
+ export type ProductQueryBySKU = z.infer<typeof ProductQueryBySKUSchema>;
@@ -85,7 +85,7 @@ function safeSerialize(value: unknown, maxDepth = 3, currentDepth = 0): string {
85
85
  * TypeScript decorator for tracing function execution
86
86
  * Automatically creates OpenTelemetry spans for decorated methods
87
87
  * Uses Stage 2 (legacy) decorator syntax
88
- *
88
+ *
89
89
  * @example
90
90
  * ```typescript
91
91
  * class MyService {
@@ -116,14 +116,14 @@ export function traced(options: TracedOptions = {}): MethodDecorator {
116
116
  ): PropertyDescriptor {
117
117
  const originalMethod = descriptor.value;
118
118
  const methodName = String(propertyKey);
119
-
119
+
120
120
  descriptor.value = createTracedMethod(originalMethod, methodName, {
121
121
  captureArgs,
122
122
  captureResult,
123
123
  spanName,
124
124
  spanKind
125
125
  });
126
-
126
+
127
127
  return descriptor;
128
128
  };
129
129
  }
@@ -139,7 +139,7 @@ function createTracedMethod(
139
139
  }
140
140
  ): any {
141
141
  const { captureArgs, captureResult, spanName, spanKind } = options;
142
-
142
+
143
143
  function tracedMethod(this: any, ...args: any[]): any {
144
144
  const tracer = getTracer();
145
145
  const className = this?.constructor?.name || 'Unknown';
@@ -174,7 +174,7 @@ function createTracedMethod(
174
174
  span.setAttribute('function.result', '[Serialization error]');
175
175
  }
176
176
  }
177
-
177
+
178
178
  if (isError) {
179
179
  span.setStatus({
180
180
  code: SpanStatusCode.ERROR,
@@ -186,13 +186,13 @@ function createTracedMethod(
186
186
  } else {
187
187
  span.setStatus({ code: SpanStatusCode.OK });
188
188
  }
189
-
189
+
190
190
  span.end();
191
191
  };
192
192
 
193
193
  try {
194
194
  const result = originalMethod.apply(this, args);
195
-
195
+
196
196
  // Handle async functions - await them to keep span open
197
197
  if (result instanceof Promise) {
198
198
  try {
@@ -205,7 +205,7 @@ function createTracedMethod(
205
205
  throw error;
206
206
  }
207
207
  }
208
-
208
+
209
209
  // Handle sync functions
210
210
  setSpanResult(result);
211
211
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/source",
3
- "version": "0.0.48",
3
+ "version": "0.0.51",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -34,6 +34,7 @@
34
34
  "algoliasearch": "^5.23.4",
35
35
  "connect-redis": "^8.1.0",
36
36
  "cors": "^2.8.5",
37
+ "debug": "^4.4.3",
37
38
  "dotenv": "^17.2.2",
38
39
  "express": "^5.1.0",
39
40
  "express-session": "^1.18.1",
@@ -82,6 +83,7 @@
82
83
  "@swc/cli": "~0.6.0",
83
84
  "@swc/core": "~1.5.7",
84
85
  "@swc/helpers": "~0.5.11",
86
+ "@types/debug": "^4.1.12",
85
87
  "@types/jest": "^29.5.12",
86
88
  "@types/node": "18.16.9",
87
89
  "@types/react": "19.0.0",
@@ -3,7 +3,8 @@ import type {
3
3
  ProductQueryById,
4
4
  ProductQueryBySlug,
5
5
  RequestContext,
6
- Cache
6
+ Cache,
7
+ ProductQueryBySKU
7
8
  } from '@reactionary/core';
8
9
  import {
9
10
  ProductProvider
@@ -57,4 +58,9 @@ export class AlgoliaProductProvider<
57
58
 
58
59
  return this.assert(result);
59
60
  }
61
+
62
+ public override getBySKU(payload: ProductQueryBySKU, reqCtx: RequestContext): Promise<T> {
63
+ throw new Error('Method not implemented.');
64
+ }
65
+
60
66
  }
@@ -6,6 +6,7 @@
6
6
  "dependencies": {
7
7
  "@reactionary/core": "0.0.1",
8
8
  "@reactionary/otel": "0.0.1",
9
+ "debug": "^4.4.3",
9
10
  "zod": "4.1.9",
10
11
  "@commercetools/ts-client": "^4.2.1",
11
12
  "@commercetools/platform-sdk": "^8.8.0"
@@ -7,8 +7,18 @@ import {
7
7
  import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk';
8
8
  import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
9
9
  import { randomUUID } from 'crypto';
10
- import { GuestIdentitySchema, IdentitySchema, type RequestContext } from '@reactionary/core';
10
+ import {
11
+ AnonymousIdentitySchema,
12
+ GuestIdentitySchema,
13
+ RegisteredIdentitySchema,
14
+ type RequestContext,
15
+ } from '@reactionary/core';
11
16
  import * as crypto from 'crypto';
17
+ import createDebug from 'debug'
18
+ const debug = createDebug('commercetools:debug')
19
+
20
+
21
+
12
22
 
13
23
  export class RequestContextTokenCache implements TokenCache {
14
24
  constructor(protected context: RequestContext) {}
@@ -18,15 +28,11 @@ export class RequestContextTokenCache implements TokenCache {
18
28
  ): Promise<TokenStore | undefined> {
19
29
  const identity = this.context.identity;
20
30
 
21
- if (identity.type !== 'Anonymous') {
22
- return {
23
- refreshToken: identity.refresh_token,
24
- token: identity.token || '',
25
- expirationTime: identity.expiry.getTime(),
26
- };
27
- }
28
-
29
- return undefined;
31
+ return {
32
+ refreshToken: identity.refresh_token,
33
+ token: identity.token || '',
34
+ expirationTime: identity.expiry.getTime(),
35
+ };
30
36
  }
31
37
 
32
38
  public async set(
@@ -41,6 +47,8 @@ export class RequestContextTokenCache implements TokenCache {
41
47
  }
42
48
  }
43
49
 
50
+
51
+
44
52
  export class CommercetoolsClient {
45
53
  protected config: CommercetoolsConfiguration;
46
54
 
@@ -57,8 +65,6 @@ export class CommercetoolsClient {
57
65
  password: string,
58
66
  reqCtx: RequestContext
59
67
  ) {
60
- const cache = new RequestContextTokenCache(reqCtx);
61
-
62
68
  const registrationBuilder =
63
69
  this.createBaseClientBuilder().withAnonymousSessionFlow({
64
70
  host: this.config.authUrl,
@@ -68,12 +74,12 @@ export class CommercetoolsClient {
68
74
  clientSecret: this.config.clientSecret,
69
75
  },
70
76
  scopes: this.config.scopes,
71
- tokenCache: cache,
72
77
  });
73
78
 
74
79
  const registrationClient = createApiBuilderFromCtpClient(
75
80
  registrationBuilder.build()
76
81
  );
82
+
77
83
  const registration = await registrationClient
78
84
  .withProjectKey({ projectKey: this.config.projectKey })
79
85
  .me()
@@ -87,6 +93,8 @@ export class CommercetoolsClient {
87
93
  .execute();
88
94
 
89
95
  const login = await this.login(username, password, reqCtx);
96
+
97
+ return login;
90
98
  }
91
99
 
92
100
  public async login(
@@ -95,7 +103,6 @@ export class CommercetoolsClient {
95
103
  reqCtx: RequestContext
96
104
  ) {
97
105
  const cache = new RequestContextTokenCache(reqCtx);
98
- const identity = reqCtx.identity;
99
106
 
100
107
  const loginBuilder = this.createBaseClientBuilder().withPasswordFlow({
101
108
  host: this.config.authUrl,
@@ -114,39 +121,52 @@ export class CommercetoolsClient {
114
121
  const login = await loginClient
115
122
  .withProjectKey({ projectKey: this.config.projectKey })
116
123
  .me()
117
- .get()
124
+ .login()
125
+ .post({
126
+ body: {
127
+ email: username,
128
+ password: password,
129
+ },
130
+ })
118
131
  .execute();
119
132
 
120
- identity.type = 'Registered';
121
- identity.logonId = username;
122
- identity.id = {
123
- userId: login.body.id
124
- };
133
+ reqCtx.identity = RegisteredIdentitySchema.parse({
134
+ ...reqCtx.identity,
135
+ type: 'Registered',
136
+ logonId: username,
137
+ id: {
138
+ userId: login.body.customer.id,
139
+ },
140
+ });
141
+
142
+ return reqCtx.identity;
125
143
  }
126
144
 
127
145
  public async logout(reqCtx: RequestContext) {
128
146
  const cache = new RequestContextTokenCache(reqCtx);
129
147
  await cache.set({ token: '', refreshToken: '', expirationTime: 0 });
130
148
 
131
- reqCtx.identity = IdentitySchema.parse({});
149
+ reqCtx.identity = AnonymousIdentitySchema.parse({});
132
150
 
133
151
  // TODO: We could do token revocation here, if we wanted to. The above simply whacks the session.
152
+
153
+ return reqCtx.identity;
134
154
  }
135
155
 
136
156
  protected createClient(reqCtx: RequestContext) {
137
157
  const cache = new RequestContextTokenCache(reqCtx);
138
-
158
+
139
159
  if (reqCtx.identity.type === 'Anonymous') {
140
160
  reqCtx.identity = GuestIdentitySchema.parse({
141
161
  id: {
142
162
  userId: crypto.randomUUID().toString(),
143
163
  },
144
- type: 'Guest'
164
+ type: 'Guest',
145
165
  });
146
166
  }
147
167
 
148
168
  const identity = reqCtx.identity;
149
- let builder = this.createBaseClientBuilder();
169
+ let builder = this.createBaseClientBuilder(reqCtx);
150
170
 
151
171
  if (!identity.token || !identity.refresh_token) {
152
172
  builder = builder.withAnonymousSessionFlow({
@@ -175,8 +195,14 @@ export class CommercetoolsClient {
175
195
  return createApiBuilderFromCtpClient(builder.build());
176
196
  }
177
197
 
178
- protected createBaseClientBuilder() {
179
- const builder = new ClientBuilder()
198
+
199
+
200
+
201
+
202
+
203
+
204
+ protected createBaseClientBuilder(reqCtx?: RequestContext) {
205
+ let builder = new ClientBuilder()
180
206
  .withProjectKey(this.config.projectKey)
181
207
  .withQueueMiddleware({
182
208
  concurrency: 20,
@@ -195,10 +221,6 @@ export class CommercetoolsClient {
195
221
  return Promise.resolve(body);
196
222
  },
197
223
  })
198
- .withCorrelationIdMiddleware({
199
- // ideally this would be pushed in as part of the session context, so we can trace it end-to-end
200
- generate: () => `REACTIONARY-${randomUUID()}`,
201
- })
202
224
  .withHttpMiddleware({
203
225
  retryConfig: {
204
226
  backoff: true,
@@ -215,8 +237,17 @@ export class CommercetoolsClient {
215
237
  httpClient: fetch,
216
238
  });
217
239
 
218
- // CT's telemetry module is currently broken and consequently not included in the above (createTelemetryMiddleware)
240
+ const correlationId = reqCtx?.correlationId || 'REACTIONARY-' + (typeof crypto !== 'undefined' && 'randomUUID' in crypto ? crypto.randomUUID() : randomUUID());
241
+ builder = builder.withCorrelationIdMiddleware({
242
+ generate: () => correlationId,
243
+ });
244
+
245
+ // Note:
219
246
 
247
+ // CT's telemetry module is currently broken and consequently not included in the above (createTelemetryMiddleware)
248
+ if (debug.enabled) {
249
+ builder = builder.withLoggerMiddleware();
250
+ }
220
251
  return builder;
221
252
  }
222
253
  }
@@ -7,7 +7,10 @@ import type {
7
7
  InventoryProvider,
8
8
  PriceProvider,
9
9
  CategoryProvider,
10
- StoreProvider} from "@reactionary/core";
10
+ StoreProvider,
11
+ CheckoutProvider,
12
+ OrderProvider
13
+ } from "@reactionary/core";
11
14
  import {
12
15
  CartSchema,
13
16
  IdentitySchema,
@@ -16,7 +19,7 @@ import {
16
19
  ProductSchema,
17
20
  SearchResultSchema,
18
21
  CategorySchema,
19
- CartPaymentInstructionSchema
22
+ CheckoutSchema
20
23
  } from "@reactionary/core";
21
24
  import type { CommercetoolsCapabilities } from "../schema/capabilities.schema";
22
25
  import { CommercetoolsSearchProvider } from "../providers/search.provider";
@@ -27,7 +30,7 @@ import { CommercetoolsCartProvider } from "../providers/cart.provider";
27
30
  import { CommercetoolsInventoryProvider } from "../providers/inventory.provider";
28
31
  import { CommercetoolsPriceProvider } from "../providers/price.provider";
29
32
  import { CommercetoolsCategoryProvider } from "../providers/category.provider";
30
- import { CommercetoolsCartPaymentProvider } from "../providers/cart-payment.provider";
33
+ import { CommercetoolsCheckoutProvider } from "../providers";
31
34
 
32
35
  type CommercetoolsClient<T extends CommercetoolsCapabilities> =
33
36
  (T['cart'] extends true ? { cart: CartProvider } : object) &
@@ -37,8 +40,9 @@ type CommercetoolsClient<T extends CommercetoolsCapabilities> =
37
40
  (T['category'] extends true ? { category: CategoryProvider } : object) &
38
41
  (T['inventory'] extends true ? { inventory: InventoryProvider } : object) &
39
42
  (T['price'] extends true ? { price: PriceProvider } : object) &
40
- (T['store'] extends true ? { store: StoreProvider } : object);
41
-
43
+ (T['store'] extends true ? { store: StoreProvider } : object) &
44
+ (T['order'] extends true ? { order: OrderProvider } : object) &
45
+ (T['checkout'] extends true ? { checkout: CheckoutProvider } : object) ;
42
46
  export function withCommercetoolsCapabilities<T extends CommercetoolsCapabilities>(
43
47
  configuration: CommercetoolsConfiguration,
44
48
  capabilities: T
@@ -74,8 +78,8 @@ export function withCommercetoolsCapabilities<T extends CommercetoolsCapabilitie
74
78
  client.category = new CommercetoolsCategoryProvider(configuration, CategorySchema, cache);
75
79
  }
76
80
 
77
- if (capabilities.cartPayment) {
78
- client.cartPayment = new CommercetoolsCartPaymentProvider(configuration, CartPaymentInstructionSchema, cache);
81
+ if (capabilities.checkout) {
82
+ client.checkout = new CommercetoolsCheckoutProvider(configuration, CheckoutSchema, cache);
79
83
  }
80
84
 
81
85
 
@@ -19,6 +19,7 @@ import type {
19
19
  ,
20
20
  Cache
21
21
  } from '@reactionary/core';
22
+
22
23
  import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
23
24
  import type { z } from 'zod';
24
25
  import { CommercetoolsClient } from '../core/client';
@@ -156,6 +157,7 @@ export class CommercetoolsCartProvider<
156
157
  version: carts.body.version || 0
157
158
  });
158
159
  } catch (e: any) {
160
+
159
161
  return CommercetoolsCartIdentifierSchema.parse({
160
162
  key: '',
161
163
  version: 0
@@ -415,7 +417,7 @@ export class CommercetoolsCartProvider<
415
417
  const ctId = cart as CommercetoolsCartIdentifier;
416
418
 
417
419
 
418
-
420
+ try {
419
421
  const response = await client.carts
420
422
  .withId({ ID: ctId.key })
421
423
  .post({
@@ -426,7 +428,14 @@ export class CommercetoolsCartProvider<
426
428
  })
427
429
  .execute();
428
430
 
431
+ if (response.error) {
432
+ console.error(response.error);
433
+ }
429
434
  return this.parseSingle(response.body, reqCtx);
435
+ } catch (e: any) {
436
+ console.error('Error applying actions to cart:', e);
437
+ throw e;
438
+ }
430
439
 
431
440
  }
432
441