@reactionary/provider-medusa 0.0.84 → 0.1.1

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.
package/core/client.js CHANGED
@@ -203,17 +203,30 @@ class MedusaClient {
203
203
  }
204
204
  const customerResponse = await client.store.customer.retrieve();
205
205
  if (customerResponse.customer) {
206
- return RegisteredIdentitySchema.parse({});
206
+ const identity = {
207
+ id: {
208
+ userId: customerResponse.customer.id
209
+ },
210
+ type: "Registered",
211
+ meta: {
212
+ cache: {
213
+ hit: false,
214
+ key: customerResponse.customer.id
215
+ },
216
+ placeholder: false
217
+ }
218
+ };
219
+ return identity;
207
220
  }
208
221
  return {
209
- type: "Anonymous",
210
222
  meta: {
211
223
  cache: {
212
224
  hit: false,
213
225
  key: ""
214
226
  },
215
227
  placeholder: false
216
- }
228
+ },
229
+ type: "Anonymous"
217
230
  };
218
231
  } catch (error) {
219
232
  debug("Login failed:", error);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@reactionary/provider-medusa",
3
- "version": "0.0.84",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
8
  "zod": "4.1.9",
9
- "@reactionary/core": "0.0.84",
9
+ "@reactionary/core": "0.1.1",
10
10
  "@medusajs/js-sdk": "^2.0.0",
11
11
  "debug": "^4.3.4",
12
12
  "@medusajs/types": "^2.11.0",
@@ -68,16 +68,27 @@ class MedusaCartProvider extends CartProvider {
68
68
  }
69
69
  const medusaId = cartIdentifier;
70
70
  if (debug.enabled) {
71
- debug("Adding item to cart ID:", medusaId.key, "SKU:", payload.variant.sku, "Quantity:", payload.quantity);
71
+ debug(
72
+ "Adding item to cart ID:",
73
+ medusaId.key,
74
+ "SKU:",
75
+ payload.variant.sku,
76
+ "Quantity:",
77
+ payload.quantity
78
+ );
72
79
  }
73
80
  const variantId = await this.client.resolveVariantId(payload.variant.sku);
74
81
  const cc = this.context.languageContext;
75
- const response = await client.store.cart.createLineItem(medusaId.key, {
76
- variant_id: variantId,
77
- quantity: payload.quantity
78
- }, {
79
- fields: "+items.*"
80
- });
82
+ const response = await client.store.cart.createLineItem(
83
+ medusaId.key,
84
+ {
85
+ variant_id: variantId,
86
+ quantity: payload.quantity
87
+ },
88
+ {
89
+ fields: "+items.*"
90
+ }
91
+ );
81
92
  if (debug.enabled) {
82
93
  debug("Received add item response:", response);
83
94
  }
@@ -87,7 +98,9 @@ class MedusaCartProvider extends CartProvider {
87
98
  throw new Error("Failed to add item to cart");
88
99
  } catch (error) {
89
100
  debug("Failed to add item to cart:", error);
90
- throw new Error(`Failed to add item to cart: ${error instanceof Error ? error.message : "Unknown error"}`);
101
+ throw new Error(
102
+ `Failed to add item to cart: ${error instanceof Error ? error.message : "Unknown error"}`
103
+ );
91
104
  }
92
105
  }
93
106
  async remove(payload) {
@@ -107,12 +120,16 @@ class MedusaCartProvider extends CartProvider {
107
120
  throw new Error("Failed to remove item from cart");
108
121
  } catch (error) {
109
122
  debug("Failed to remove item from cart:", error);
110
- throw new Error(`Failed to remove item from cart: ${error instanceof Error ? error.message : "Unknown error"}`);
123
+ throw new Error(
124
+ `Failed to remove item from cart: ${error instanceof Error ? error.message : "Unknown error"}`
125
+ );
111
126
  }
112
127
  }
113
128
  async changeQuantity(payload) {
114
129
  if (payload.quantity < 1) {
115
- throw new Error("Changing quantity to 0 is not allowed. Use the remove call instead.");
130
+ throw new Error(
131
+ "Changing quantity to 0 is not allowed. Use the remove call instead."
132
+ );
116
133
  }
117
134
  try {
118
135
  const client = await this.getClient();
@@ -133,7 +150,9 @@ class MedusaCartProvider extends CartProvider {
133
150
  throw new Error("Failed to change item quantity");
134
151
  } catch (error) {
135
152
  debug("Failed to change item quantity:", error);
136
- throw new Error(`Failed to change item quantity: ${error instanceof Error ? error.message : "Unknown error"}`);
153
+ throw new Error(
154
+ `Failed to change item quantity: ${error instanceof Error ? error.message : "Unknown error"}`
155
+ );
137
156
  }
138
157
  }
139
158
  async getActiveCartId() {
@@ -171,20 +190,15 @@ class MedusaCartProvider extends CartProvider {
171
190
  const sessionData = this.client.getSessionData();
172
191
  if (sessionData.activeCartId) {
173
192
  delete sessionData.activeCartId;
174
- this.client.setSessionData(
175
- {
176
- activeCartId: void 0
177
- }
178
- );
193
+ this.client.setSessionData({
194
+ activeCartId: void 0
195
+ });
179
196
  }
180
197
  }
181
198
  const cartResponse = await client.store.cart.retrieve(medusaId.key);
182
199
  if (cartResponse.cart) {
183
200
  for (const item of cartResponse.cart.items || []) {
184
- await client.store.cart.deleteLineItem(
185
- medusaId.key,
186
- item.id
187
- );
201
+ await client.store.cart.deleteLineItem(medusaId.key, item.id);
188
202
  }
189
203
  }
190
204
  return this.createEmptyCart();
@@ -197,18 +211,24 @@ class MedusaCartProvider extends CartProvider {
197
211
  try {
198
212
  const client = await this.getClient();
199
213
  const medusaId = payload.cart;
200
- const response = await client.store.cart.update(medusaId.key, {
201
- promo_codes: [payload.couponCode]
202
- }, {
203
- fields: "+items.*"
204
- });
214
+ const response = await client.store.cart.update(
215
+ medusaId.key,
216
+ {
217
+ promo_codes: [payload.couponCode]
218
+ },
219
+ {
220
+ fields: "+items.*"
221
+ }
222
+ );
205
223
  if (response.cart) {
206
224
  return this.parseSingle(response.cart);
207
225
  }
208
226
  throw new Error("Failed to apply coupon code");
209
227
  } catch (error) {
210
228
  debug("Failed to apply coupon code:", error);
211
- throw new Error(`Failed to apply coupon code: ${error instanceof Error ? error.message : "Unknown error"}`);
229
+ throw new Error(
230
+ `Failed to apply coupon code: ${error instanceof Error ? error.message : "Unknown error"}`
231
+ );
212
232
  }
213
233
  }
214
234
  async removeCouponCode(payload) {
@@ -217,7 +237,9 @@ class MedusaCartProvider extends CartProvider {
217
237
  const medusaId = payload.cart;
218
238
  const cartResponse = await client.store.cart.retrieve(medusaId.key);
219
239
  if (cartResponse.cart?.promotions) {
220
- const manualDiscounts = cartResponse.cart.promotions.filter((x) => !x.is_automatic && x.code);
240
+ const manualDiscounts = cartResponse.cart.promotions.filter(
241
+ (x) => !x.is_automatic && x.code
242
+ );
221
243
  const remainingCodes = manualDiscounts.filter((x) => x.code !== payload.couponCode).map((promotion) => promotion.code) || [];
222
244
  const response = await client.store.cart.update(medusaId.key, {
223
245
  promo_codes: remainingCodes || []
@@ -229,13 +251,17 @@ class MedusaCartProvider extends CartProvider {
229
251
  throw new Error("Failed to remove coupon code");
230
252
  } catch (error) {
231
253
  debug("Failed to remove coupon code:", error);
232
- throw new Error(`Failed to remove coupon code: ${error instanceof Error ? error.message : "Unknown error"}`);
254
+ throw new Error(
255
+ `Failed to remove coupon code: ${error instanceof Error ? error.message : "Unknown error"}`
256
+ );
233
257
  }
234
258
  }
235
259
  async changeCurrency(payload) {
236
260
  try {
237
261
  const client = await this.getClient();
238
- const currentCartResponse = await client.store.cart.retrieve(payload.cart.key);
262
+ const currentCartResponse = await client.store.cart.retrieve(
263
+ payload.cart.key
264
+ );
239
265
  client.store.cart.update(
240
266
  payload.cart.key,
241
267
  {
@@ -248,7 +274,9 @@ class MedusaCartProvider extends CartProvider {
248
274
  if (!currentCartResponse.cart) {
249
275
  throw new Error("Cart not found");
250
276
  }
251
- const newCartResponse = await client.store.cart.retrieve(payload.cart.key);
277
+ const newCartResponse = await client.store.cart.retrieve(
278
+ payload.cart.key
279
+ );
252
280
  if (newCartResponse.cart) {
253
281
  this.client.setSessionData({
254
282
  activeCartId: newCartResponse.cart.id
@@ -258,7 +286,9 @@ class MedusaCartProvider extends CartProvider {
258
286
  throw new Error("Failed to change currency");
259
287
  } catch (error) {
260
288
  debug("Failed to change currency:", error);
261
- throw new Error(`Failed to change currency: ${error instanceof Error ? error.message : "Unknown error"}`);
289
+ throw new Error(
290
+ `Failed to change currency: ${error instanceof Error ? error.message : "Unknown error"}`
291
+ );
262
292
  }
263
293
  }
264
294
  async createCart(currency) {
@@ -277,22 +307,58 @@ class MedusaCartProvider extends CartProvider {
277
307
  key: response.cart.id,
278
308
  region_id: response.cart.region_id
279
309
  });
280
- this.client.setSessionData(
281
- {
282
- activeCartId: cartIdentifier.key
283
- }
284
- );
310
+ this.client.setSessionData({
311
+ activeCartId: cartIdentifier.key
312
+ });
285
313
  return cartIdentifier;
286
314
  }
287
315
  throw new Error("Failed to create cart");
288
316
  } catch (error) {
289
317
  debug("Failed to create cart:", error);
290
- throw new Error(`Failed to create cart: ${error instanceof Error ? error.message : "Unknown error"}`);
318
+ throw new Error(
319
+ `Failed to create cart: ${error instanceof Error ? error.message : "Unknown error"}`
320
+ );
291
321
  }
292
322
  }
293
323
  async getClient() {
294
324
  return this.client.getClient();
295
325
  }
326
+ parseCartItem(remoteItem, currency) {
327
+ const unitPrice = remoteItem.unit_price || 0;
328
+ const totalPrice = unitPrice * remoteItem.quantity || 0;
329
+ const discountTotal = remoteItem.discount_total || 0;
330
+ const item = {
331
+ identifier: {
332
+ key: remoteItem.id
333
+ },
334
+ product: {
335
+ key: remoteItem.product_id || ""
336
+ },
337
+ variant: ProductVariantIdentifierSchema.parse({
338
+ sku: remoteItem.variant_sku || ""
339
+ }),
340
+ quantity: remoteItem.quantity || 1,
341
+ price: {
342
+ unitPrice: {
343
+ value: unitPrice,
344
+ currency
345
+ },
346
+ unitDiscount: {
347
+ value: discountTotal / remoteItem.quantity,
348
+ currency
349
+ },
350
+ totalPrice: {
351
+ value: totalPrice,
352
+ currency
353
+ },
354
+ totalDiscount: {
355
+ value: discountTotal,
356
+ currency
357
+ }
358
+ }
359
+ };
360
+ return item;
361
+ }
296
362
  parseSingle(remote) {
297
363
  const identifier = MedusaCartIdentifierSchema.parse({
298
364
  key: remote.id,
@@ -333,36 +399,10 @@ class MedusaCartProvider extends CartProvider {
333
399
  }
334
400
  };
335
401
  const items = new Array();
336
- for (const remoteItem of remote.items || []) {
337
- const item = CartItemSchema.parse({});
338
- item.identifier.key = remoteItem.id;
339
- item.product.key = remoteItem.product_id || "";
340
- item.variant = ProductVariantIdentifierSchema.parse({
341
- sku: remoteItem.variant_sku || ""
342
- });
343
- item.quantity = remoteItem.quantity || 1;
344
- const unitPrice = remoteItem.unit_price || 0;
345
- const totalPrice = unitPrice * item.quantity || 0;
346
- const discountTotal2 = remoteItem.discount_total || 0;
347
- item.price = {
348
- unitPrice: {
349
- value: unitPrice,
350
- currency
351
- },
352
- unitDiscount: {
353
- value: discountTotal2 / remoteItem.quantity,
354
- currency
355
- },
356
- totalPrice: {
357
- value: totalPrice,
358
- currency
359
- },
360
- totalDiscount: {
361
- value: discountTotal2,
362
- currency
363
- }
364
- };
365
- items.push(item);
402
+ const allItems = remote.items || [];
403
+ allItems.sort((a, b) => a.created_at && b.created_at ? new Date(a.created_at).getTime() - new Date(b.created_at).getTime() : 0);
404
+ for (const remoteItem of allItems) {
405
+ items.push(this.parseCartItem(remoteItem, remote.currency_code.toUpperCase()));
366
406
  }
367
407
  const meta = {
368
408
  cache: {
@@ -75,7 +75,7 @@ class MedusaCategoryProvider extends CategoryProvider {
75
75
  hit: false,
76
76
  key: ""
77
77
  },
78
- placeholder: false
78
+ placeholder: true
79
79
  }
80
80
  };
81
81
  return dummyCategory;
@@ -11,8 +11,6 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  };
12
12
  import {
13
13
  AddressIdentifierSchema,
14
- CheckoutIdentifierSchema,
15
- CheckoutItemSchema,
16
14
  CheckoutMutationAddPaymentInstructionSchema,
17
15
  CheckoutMutationFinalizeCheckoutSchema,
18
16
  CheckoutMutationInitiateCheckoutSchema,
@@ -25,21 +23,14 @@ import {
25
23
  CheckoutQueryForAvailableShippingMethodsSchema,
26
24
  CheckoutSchema,
27
25
  MonetaryAmountSchema,
28
- PaymentInstructionIdentifierSchema,
29
- PaymentInstructionSchema,
30
- PaymentMethodIdentifierSchema,
31
26
  PaymentMethodSchema,
32
- ProductVariantIdentifierSchema,
33
27
  Reactionary,
34
- ShippingInstructionSchema,
35
28
  ShippingMethodIdentifierSchema,
36
29
  ShippingMethodSchema
37
30
  } from "@reactionary/core";
38
31
  import createDebug from "debug";
39
32
  import z from "zod";
40
33
  import {
41
- MedusaCartIdentifierSchema,
42
- MedusaOrderIdentifierSchema
43
34
  } from "../schema/medusa.schema.js";
44
35
  const debug = createDebug("reactionary:medusa:checkout");
45
36
  class CheckoutNotReadyForFinalizationError extends Error {
@@ -123,7 +114,8 @@ class MedusaCheckoutProvider extends CheckoutProvider {
123
114
  price: MonetaryAmountSchema.parse({
124
115
  value: sm.calculated_price.calculated_amount || 0,
125
116
  currency: sm.calculated_price.currency_code?.toUpperCase()
126
- })
117
+ }),
118
+ deliveryTime: ""
127
119
  })
128
120
  );
129
121
  }
@@ -149,15 +141,23 @@ class MedusaCheckoutProvider extends CheckoutProvider {
149
141
  const paymentMethods = [];
150
142
  for (const pm of paymentMethodResponse.payment_providers) {
151
143
  paymentMethods.push(
152
- PaymentMethodSchema.parse({
153
- identifier: PaymentMethodIdentifierSchema.parse({
144
+ {
145
+ identifier: {
154
146
  method: pm.id,
155
147
  name: pm.id,
156
- processor: pm.id
157
- }),
148
+ paymentProcessor: pm.id
149
+ },
158
150
  logo: void 0,
159
- name: pm.id
160
- })
151
+ description: pm.id,
152
+ isPunchOut: true,
153
+ meta: {
154
+ cache: {
155
+ hit: false,
156
+ key: ""
157
+ },
158
+ placeholder: false
159
+ }
160
+ }
161
161
  );
162
162
  }
163
163
  if (debug.enabled) {
@@ -291,11 +291,44 @@ class MedusaCheckoutProvider extends CheckoutProvider {
291
291
  region: ""
292
292
  };
293
293
  }
294
+ parseCheckoutItem(remoteItem, currency) {
295
+ const unitPrice = remoteItem.unit_price || 0;
296
+ const totalPrice = unitPrice * remoteItem.quantity || 0;
297
+ const discountTotal = remoteItem.discount_total || 0;
298
+ const item = {
299
+ identifier: {
300
+ key: remoteItem.id
301
+ },
302
+ variant: {
303
+ sku: remoteItem.variant_sku || ""
304
+ },
305
+ quantity: remoteItem.quantity || 1,
306
+ price: {
307
+ unitPrice: {
308
+ value: unitPrice,
309
+ currency
310
+ },
311
+ unitDiscount: {
312
+ value: discountTotal / remoteItem.quantity,
313
+ currency
314
+ },
315
+ totalPrice: {
316
+ value: totalPrice,
317
+ currency
318
+ },
319
+ totalDiscount: {
320
+ value: discountTotal,
321
+ currency
322
+ }
323
+ }
324
+ };
325
+ return item;
326
+ }
294
327
  parseSingle(remote) {
295
- const identifier = CheckoutIdentifierSchema.parse({
328
+ const identifier = {
296
329
  key: remote.id
297
330
  // region_id: remote.region_id,
298
- });
331
+ };
299
332
  const name = "" + (remote.metadata?.["name"] || "");
300
333
  const description = "" + (remote.metadata?.["description"] || "");
301
334
  const grandTotal = remote.total || 0;
@@ -332,34 +365,7 @@ class MedusaCheckoutProvider extends CheckoutProvider {
332
365
  };
333
366
  const items = new Array();
334
367
  for (const remoteItem of remote.items || []) {
335
- const item = CheckoutItemSchema.parse({});
336
- item.identifier.key = remoteItem.id;
337
- item.variant = ProductVariantIdentifierSchema.parse({
338
- sku: remoteItem.variant_sku || ""
339
- });
340
- item.quantity = remoteItem.quantity || 1;
341
- const unitPrice = remoteItem.unit_price || 0;
342
- const totalPrice = unitPrice * item.quantity || 0;
343
- const discountTotal2 = remoteItem.discount_total || 0;
344
- item.price = {
345
- unitPrice: {
346
- value: unitPrice,
347
- currency
348
- },
349
- unitDiscount: {
350
- value: discountTotal2 / remoteItem.quantity,
351
- currency
352
- },
353
- totalPrice: {
354
- value: totalPrice,
355
- currency
356
- },
357
- totalDiscount: {
358
- value: discountTotal2,
359
- currency
360
- }
361
- };
362
- items.push(item);
368
+ items.push(this.parseCheckoutItem(remoteItem, currency));
363
369
  }
364
370
  const meta = {
365
371
  cache: {
@@ -392,15 +398,13 @@ class MedusaCheckoutProvider extends CheckoutProvider {
392
398
  if (!consentForUnattendedDelivery) {
393
399
  consentForUnattendedDelivery = backupUnattendedDelivery || false;
394
400
  }
395
- shippingInstruction = ShippingInstructionSchema.parse({
396
- shippingMethod: ShippingMethodIdentifierSchema.parse({
397
- key: sm.shipping_option_id
398
- }),
401
+ shippingInstruction = {
402
+ shippingMethod: { key: sm.shipping_option_id },
399
403
  consentForUnattendedDelivery,
400
404
  instructions,
401
405
  pickupPoint,
402
406
  meta
403
- });
407
+ };
404
408
  });
405
409
  const paymentInstructions = new Array();
406
410
  for (const remotePayment of remote.payment_collection?.payment_sessions || []) {
@@ -410,38 +414,40 @@ class MedusaCheckoutProvider extends CheckoutProvider {
410
414
  );
411
415
  continue;
412
416
  }
413
- const paymentMethodIdentifier = PaymentMethodIdentifierSchema.parse({
417
+ const paymentMethodIdentifier = {
414
418
  method: remotePayment.provider_id,
415
419
  name: remotePayment.provider_id,
416
- processor: remotePayment.provider_id
417
- });
418
- paymentInstructions.push({
419
- meta,
420
- identifier: PaymentInstructionIdentifierSchema.parse({
421
- key: remotePayment.id
422
- }),
423
- amount: MonetaryAmountSchema.parse({
424
- value: remotePayment.amount,
425
- currency: remotePayment.currency_code?.toUpperCase()
426
- }),
427
- paymentMethod: paymentMethodIdentifier,
428
- protocolData: remotePayment.data ? Object.entries(remotePayment.data).map(([key, value]) => ({
429
- key,
430
- value: String(value)
431
- })) : [],
432
- status: "pending"
433
- });
420
+ paymentProcessor: remotePayment.provider_id
421
+ };
422
+ paymentInstructions.push(
423
+ {
424
+ meta,
425
+ identifier: {
426
+ key: remotePayment.id
427
+ },
428
+ amount: {
429
+ value: remotePayment.amount,
430
+ currency: remotePayment.currency_code?.toUpperCase()
431
+ },
432
+ paymentMethod: paymentMethodIdentifier,
433
+ protocolData: remotePayment.data ? Object.entries(remotePayment.data).map(([key, value]) => ({
434
+ key,
435
+ value: String(value)
436
+ })) : [],
437
+ status: "pending"
438
+ }
439
+ );
434
440
  }
435
- const originalCartReference = MedusaCartIdentifierSchema.parse({
441
+ const originalCartReference = {
436
442
  key: remote.id,
437
443
  region: remote.region_id
438
- });
439
- let resultingOrder;
444
+ };
445
+ let resultingOrder = void 0;
440
446
  if (remote.metadata?.["order_id"]) {
441
- resultingOrder = MedusaOrderIdentifierSchema.parse({
447
+ resultingOrder = {
442
448
  key: remote.metadata?.["order_id"] + "" || "",
443
449
  display_id: Number(remote.metadata?.["order_display_id"] + "" || "0")
444
- });
450
+ };
445
451
  }
446
452
  const result = {
447
453
  identifier,
@@ -11,16 +11,12 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  };
12
12
  import {
13
13
  CategoryIdentifierSchema,
14
- ImageSchema,
15
- ProductAttributeSchema,
16
14
  ProductIdentifierSchema,
17
15
  ProductProvider,
18
- ProductSchema,
19
16
  ProductQueryByIdSchema,
20
- ProductQueryBySlugSchema,
21
17
  ProductQueryBySKUSchema,
22
- ProductVariantIdentifierSchema,
23
- ProductVariantSchema,
18
+ ProductQueryBySlugSchema,
19
+ ProductSchema,
24
20
  Reactionary
25
21
  } from "@reactionary/core";
26
22
  import createDebug from "debug";
@@ -116,63 +112,76 @@ class MedusaProductProvider extends ProductProvider {
116
112
  return result;
117
113
  }
118
114
  parseVariant(variant, product) {
119
- const result = ProductVariantSchema.parse({
120
- identifier: ProductVariantIdentifierSchema.parse({
115
+ const options = (variant.options ?? []).map((option) => {
116
+ const optionId = { key: option.option_id || "" };
117
+ const title = option.option?.title || "?";
118
+ const valueIdentifier = { key: option.option_id || "", option: optionId };
119
+ const value = option.value || "";
120
+ const result2 = {
121
+ identifier: optionId,
122
+ name: title,
123
+ value: {
124
+ identifier: valueIdentifier,
125
+ label: value
126
+ }
127
+ };
128
+ return result2;
129
+ });
130
+ const result = {
131
+ identifier: {
121
132
  sku: variant.sku || ""
122
- }),
133
+ },
123
134
  name: variant.title || product.title,
124
- upc: variant.upc || void 0,
125
- ean: variant.ean || void 0,
126
- images: (product.images || []).map((img) => ImageSchema.parse({
127
- sourceUrl: img.url,
128
- altText: variant.title || product.title
129
- }))
130
- });
135
+ upc: variant.upc || "",
136
+ ean: variant.ean || "",
137
+ images: (product.images || []).map((img) => {
138
+ return {
139
+ sourceUrl: img.url,
140
+ altText: variant.title || product.title || ""
141
+ };
142
+ }),
143
+ options,
144
+ gtin: variant.ean || "",
145
+ barcode: variant.ean || ""
146
+ };
131
147
  return result;
132
148
  }
149
+ createSynthAttribute(key, name, value) {
150
+ const attributeIdentifier = { key };
151
+ const valueIdentifier = { key: `${key}-${value}` };
152
+ const attribute = {
153
+ identifier: { key },
154
+ name,
155
+ group: "",
156
+ values: [
157
+ {
158
+ identifier: valueIdentifier,
159
+ label: String(value),
160
+ value
161
+ }
162
+ ]
163
+ };
164
+ return attribute;
165
+ }
133
166
  parseAttributes(_body) {
134
167
  const sharedAttributes = [];
135
168
  if (_body.origin_country) {
136
- sharedAttributes.push(ProductAttributeSchema.parse({
137
- id: "origin_country",
138
- name: "Origin Country",
139
- value: _body.origin_country
140
- }));
169
+ sharedAttributes.push(this.createSynthAttribute("origin_country", "Origin Country", _body.origin_country));
141
170
  }
142
171
  if (_body.height) {
143
- sharedAttributes.push(ProductAttributeSchema.parse({
144
- id: "height",
145
- name: "Height",
146
- value: _body.height
147
- }));
172
+ sharedAttributes.push(this.createSynthAttribute("height", "Height", String(_body.height)));
148
173
  }
149
174
  if (_body.weight) {
150
- sharedAttributes.push(ProductAttributeSchema.parse({
151
- id: "weight",
152
- name: "Weight",
153
- value: _body.weight
154
- }));
175
+ sharedAttributes.push(this.createSynthAttribute("weight", "Weight", String(_body.weight)));
155
176
  }
156
177
  if (_body.length) {
157
- sharedAttributes.push(ProductAttributeSchema.parse({
158
- id: "length",
159
- name: "Length",
160
- value: _body.length
161
- }));
178
+ sharedAttributes.push(this.createSynthAttribute("length", "Length", String(_body.length)));
162
179
  }
163
180
  if (_body.width) {
164
- sharedAttributes.push(ProductAttributeSchema.parse({
165
- id: "width",
166
- name: "Width",
167
- value: _body.width
168
- }));
181
+ sharedAttributes.push(this.createSynthAttribute("width", "Width", String(_body.width)));
169
182
  }
170
183
  if (_body.material) {
171
- sharedAttributes.push(ProductAttributeSchema.parse({
172
- id: "material",
173
- name: "Material",
174
- value: _body.material
175
- }));
184
+ sharedAttributes.push(this.createSynthAttribute("material", "Material", _body.material));
176
185
  }
177
186
  return sharedAttributes;
178
187
  }
@@ -58,23 +58,10 @@ export declare class MedusaClient {
58
58
  getSessionData(): MedusaSession;
59
59
  setSessionData(sessionData: Partial<MedusaSession>): void;
60
60
  register(email: string, password: string, firstName: string, lastName: string, reqCtx: RequestContext): Promise<{
61
- [x: string]: unknown;
62
- meta: {
63
- [x: string]: unknown;
64
- cache: {
65
- [x: string]: unknown;
66
- hit: boolean;
67
- key: string;
68
- };
69
- placeholder: boolean;
70
- };
71
61
  id: {
72
- [x: string]: unknown;
73
62
  userId: string;
74
63
  };
75
64
  type: "Registered";
76
- } | {
77
- type: "Anonymous";
78
65
  meta: {
79
66
  cache: {
80
67
  hit: false;
@@ -82,25 +69,29 @@ export declare class MedusaClient {
82
69
  };
83
70
  placeholder: false;
84
71
  };
85
- }>;
86
- login(email: string, password: string, reqCtx: RequestContext): Promise<{
87
- [x: string]: unknown;
72
+ } | {
88
73
  meta: {
89
- [x: string]: unknown;
90
74
  cache: {
91
- [x: string]: unknown;
92
- hit: boolean;
75
+ hit: false;
93
76
  key: string;
94
77
  };
95
- placeholder: boolean;
78
+ placeholder: false;
96
79
  };
80
+ type: "Anonymous";
81
+ }>;
82
+ login(email: string, password: string, reqCtx: RequestContext): Promise<{
97
83
  id: {
98
- [x: string]: unknown;
99
84
  userId: string;
100
85
  };
101
86
  type: "Registered";
87
+ meta: {
88
+ cache: {
89
+ hit: false;
90
+ key: string;
91
+ };
92
+ placeholder: false;
93
+ };
102
94
  } | {
103
- type: "Anonymous";
104
95
  meta: {
105
96
  cache: {
106
97
  hit: false;
@@ -108,6 +99,7 @@ export declare class MedusaClient {
108
99
  };
109
100
  placeholder: false;
110
101
  };
102
+ type: "Anonymous";
111
103
  }>;
112
104
  logout(reqCtx: RequestContext): Promise<{
113
105
  type: "Anonymous";
@@ -1,4 +1,4 @@
1
- import type { Cache, Cart, CartIdentifier, CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartQueryById, RequestContext } from '@reactionary/core';
1
+ import type { Cache, Cart, CartIdentifier, CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartQueryById, Currency, RequestContext, CartItem } from '@reactionary/core';
2
2
  import { CartProvider } from '@reactionary/core';
3
3
  import type { MedusaClient } from '../core/client.js';
4
4
  import type { MedusaConfiguration } from '../schema/configuration.schema.js';
@@ -23,5 +23,6 @@ export declare class MedusaCartProvider extends CartProvider {
23
23
  store: import("@medusajs/js-sdk").Store;
24
24
  auth: import("@medusajs/js-sdk").Auth;
25
25
  }>;
26
+ protected parseCartItem(remoteItem: MedusaTypes.StoreCartLineItem, currency: Currency): CartItem;
26
27
  protected parseSingle(remote: MedusaTypes.StoreCart): Cart;
27
28
  }
@@ -1,5 +1,5 @@
1
1
  import type { StoreCart } from '@medusajs/types';
2
- import type { Address, Cache, Checkout, CheckoutIdentifier, CheckoutMutationAddPaymentInstruction, CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingAddress, CheckoutMutationSetShippingInstruction, CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods, PaymentMethod, RequestContext, ShippingMethod } from '@reactionary/core';
2
+ import type { Address, Cache, Checkout, CheckoutIdentifier, CheckoutItem, CheckoutMutationAddPaymentInstruction, CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingAddress, CheckoutMutationSetShippingInstruction, CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods, Currency, PaymentMethod, RequestContext, ShippingMethod } from '@reactionary/core';
3
3
  import { CheckoutProvider } from '@reactionary/core';
4
4
  import type { MedusaClient } from '../core/client.js';
5
5
  import type { MedusaConfiguration } from '../schema/configuration.schema.js';
@@ -31,5 +31,6 @@ export declare class MedusaCheckoutProvider extends CheckoutProvider {
31
31
  country_code: string | undefined;
32
32
  };
33
33
  protected composeAddressFromStoreAddress(storeAddress: any): Address;
34
+ protected parseCheckoutItem(remoteItem: any, currency: Currency): CheckoutItem;
34
35
  protected parseSingle(remote: StoreCart): Checkout;
35
36
  }
@@ -12,14 +12,11 @@ export declare class MedusaProductProvider extends ProductProvider {
12
12
  getBySKU(payload: ProductQueryBySKU): Promise<Product>;
13
13
  protected parseSingle(_body: StoreProduct): Product;
14
14
  protected parseVariant(variant: StoreProductVariant, product: StoreProduct): {
15
- [x: string]: unknown;
16
15
  identifier: {
17
- [x: string]: unknown;
18
16
  sku: string;
19
17
  };
20
18
  name: string;
21
19
  images: {
22
- [x: string]: unknown;
23
20
  sourceUrl: string;
24
21
  altText: string;
25
22
  width?: number | undefined;
@@ -30,18 +27,13 @@ export declare class MedusaProductProvider extends ProductProvider {
30
27
  upc: string;
31
28
  barcode: string;
32
29
  options: {
33
- [x: string]: unknown;
34
30
  identifier: {
35
- [x: string]: unknown;
36
31
  key: string;
37
32
  };
38
33
  name: string;
39
34
  value: {
40
- [x: string]: unknown;
41
35
  identifier: {
42
- [x: string]: unknown;
43
36
  option: {
44
- [x: string]: unknown;
45
37
  key: string;
46
38
  };
47
39
  key: string;
@@ -50,5 +42,6 @@ export declare class MedusaProductProvider extends ProductProvider {
50
42
  };
51
43
  }[];
52
44
  };
45
+ protected createSynthAttribute(key: string, name: string, value: string): ProductAttribute;
53
46
  protected parseAttributes(_body: StoreProduct): Array<ProductAttribute>;
54
47
  }
@@ -1,4 +1,3 @@
1
- import "dotenv/config";
2
1
  import {
3
2
  ClientBuilder,
4
3
  createInitialRequestContext,
@@ -6,9 +5,10 @@ import {
6
5
  PaymentInstructionSchema,
7
6
  ShippingInstructionSchema
8
7
  } from "@reactionary/core";
9
- import { describe, expect, it, beforeEach } from "vitest";
10
- import { getMedusaTestConfiguration } from "./test-utils.js";
8
+ import "dotenv/config";
9
+ import { beforeEach, describe, expect, it } from "vitest";
11
10
  import { withMedusaCapabilities } from "../core/initialize.js";
11
+ import { getMedusaTestConfiguration } from "./test-utils.js";
12
12
  const testData = {
13
13
  skuWithoutTiers: "0766623301831",
14
14
  skuWithTiers: "0766623360203"
@@ -196,11 +196,16 @@ describe.each(["Medusa"])("Checkout Capability - %s", (provider) => {
196
196
  expect(sm).toBeDefined();
197
197
  const shippingInstruction = {
198
198
  shippingMethod: sm?.identifier || { key: "" },
199
- amount: checkout.price.totalShipping,
200
199
  instructions: "Leave at front door if not home",
201
200
  consentForUnattendedDelivery: true,
202
- pickupPoint: "4190asx141"
203
- // this would be a real pickup point ID in a real scenario
201
+ pickupPoint: "4190asx141",
202
+ meta: {
203
+ cache: {
204
+ hit: false,
205
+ key: ""
206
+ },
207
+ placeholder: false
208
+ }
204
209
  };
205
210
  const checkoutWithShipping = await client.checkout.setShippingInstruction(
206
211
  {