@reactionary/provider-medusa 0.1.1 → 0.1.3

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
@@ -122,7 +122,7 @@ class MedusaClient {
122
122
  const productsResponse = await adminClient.admin.product.list({
123
123
  limit: 1,
124
124
  offset: 0,
125
- fields: "+categories.metadata.*",
125
+ fields: "+metadata.*,+categories.metadata.*",
126
126
  variants: {
127
127
  $or: [{ ean: sku }, { upc: sku }, { barcode: sku }]
128
128
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@reactionary/provider-medusa",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
- "main": "./src/index.js",
6
- "types": "./src/index.d.ts",
5
+ "main": "index.js",
6
+ "types": "src/index.d.ts",
7
7
  "dependencies": {
8
8
  "zod": "4.1.9",
9
- "@reactionary/core": "0.1.1",
9
+ "@reactionary/core": "0.1.3",
10
10
  "@medusajs/js-sdk": "^2.0.0",
11
11
  "debug": "^4.3.4",
12
12
  "@medusajs/types": "^2.11.0",
@@ -34,7 +34,9 @@ class MedusaProductProvider extends ProductProvider {
34
34
  }
35
35
  let response;
36
36
  try {
37
- response = await client.store.product.retrieve(payload.identifier.key);
37
+ response = await client.store.product.retrieve(payload.identifier.key, {
38
+ fields: "+metadata,+categories.metadata.*"
39
+ });
38
40
  } catch (error) {
39
41
  if (debug.enabled) {
40
42
  debug(`Product with ID: ${payload.identifier.key} not found, returning empty product. Error %O `, error);
@@ -51,7 +53,8 @@ class MedusaProductProvider extends ProductProvider {
51
53
  const response = await client.store.product.list({
52
54
  handle: payload.slug,
53
55
  limit: 1,
54
- offset: 0
56
+ offset: 0,
57
+ fields: "+metadata.*"
55
58
  });
56
59
  if (debug.enabled) {
57
60
  debug(`Found ${response.count} products for slug: ${payload.slug}`);
@@ -183,6 +186,11 @@ class MedusaProductProvider extends ProductProvider {
183
186
  if (_body.material) {
184
187
  sharedAttributes.push(this.createSynthAttribute("material", "Material", _body.material));
185
188
  }
189
+ if (_body.metadata) {
190
+ for (const [key, value] of Object.entries(_body.metadata)) {
191
+ sharedAttributes.push(this.createSynthAttribute(key, key, String(value)));
192
+ }
193
+ }
186
194
  return sharedAttributes;
187
195
  }
188
196
  }
@@ -31,6 +31,9 @@ describe("Medusa Product Provider", () => {
31
31
  expect(result.mainVariant).toBeDefined();
32
32
  expect(result.mainVariant.identifier.sku).toBe(testData.product.sku);
33
33
  expect(result.mainVariant.images[0].sourceUrl).toBe(testData.product.image);
34
+ expect(result.sharedAttributes.length).toBeGreaterThan(1);
35
+ expect(result.sharedAttributes[1].values.length).toBeGreaterThan(0);
36
+ expect(result.sharedAttributes[1].values[0].value).toBeTruthy();
34
37
  });
35
38
  it("should be able to get a product by slug", async () => {
36
39
  const result = await provider.getBySlug({ slug: testData.product.slug });
@@ -58,12 +61,22 @@ describe("Medusa Product Provider", () => {
58
61
  expect(result.mainVariant).toBeDefined();
59
62
  expect(result.mainVariant.identifier.sku).toBe(testData.product.sku);
60
63
  expect(result.mainVariant.images[0].sourceUrl).toBe(testData.product.image);
64
+ expect(result.sharedAttributes.length).toBeGreaterThan(1);
65
+ expect(result.sharedAttributes[1].values.length).toBeGreaterThan(0);
66
+ expect(result.sharedAttributes[1].values[0].value).toBeTruthy();
61
67
  }
62
68
  });
63
69
  it("should return null for unknown slug", async () => {
64
70
  const result = await provider.getBySlug({ slug: "unknown-slug" });
65
71
  expect(result).toBeNull();
66
72
  });
73
+ it("should contain both product level and variant level attributes", async () => {
74
+ const result = await provider.getBySlug({ slug: testData.product.slug });
75
+ expect(result).toBeTruthy();
76
+ expect(result.sharedAttributes.length).toBeGreaterThan(1);
77
+ expect(result.sharedAttributes[1].values.length).toBeGreaterThan(0);
78
+ expect(result.sharedAttributes[1].values[0].value).toBeTruthy();
79
+ });
67
80
  it("should return a placeholder product for unknown id", async () => {
68
81
  const result = await provider.getById({ identifier: { key: "unknown-id" } });
69
82
  expect(result).toBeTruthy();