@reactionary/provider-medusa 0.0.81 → 0.0.83

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.
@@ -26,28 +26,28 @@ function withMedusaCapabilities(configuration, capabilities) {
26
26
  const caps = MedusaCapabilitiesSchema.parse(capabilities);
27
27
  const medusaClient = new MedusaClient(config, context);
28
28
  if (caps.productSearch) {
29
- client.productSearch = new MedusaSearchProvider(configuration, ProductSearchResultItemSchema, cache, context, medusaClient);
29
+ client.productSearch = new MedusaSearchProvider(configuration, cache, context, medusaClient);
30
30
  }
31
31
  if (caps.category) {
32
- client.category = new MedusaCategoryProvider(configuration, CategorySchema, cache, context, medusaClient);
32
+ client.category = new MedusaCategoryProvider(configuration, cache, context, medusaClient);
33
33
  }
34
34
  if (caps.checkout) {
35
- client.checkout = new MedusaCheckoutProvider(configuration, CheckoutSchema, cache, context, medusaClient);
35
+ client.checkout = new MedusaCheckoutProvider(configuration, cache, context, medusaClient);
36
36
  }
37
37
  if (caps.product) {
38
- client.product = new MedusaProductProvider(configuration, ProductSchema, cache, context, medusaClient);
38
+ client.product = new MedusaProductProvider(configuration, cache, context, medusaClient);
39
39
  }
40
40
  if (caps.cart) {
41
- client.cart = new MedusaCartProvider(configuration, CartSchema, cache, context, medusaClient);
41
+ client.cart = new MedusaCartProvider(configuration, cache, context, medusaClient);
42
42
  }
43
43
  if (caps.price) {
44
- client.price = new MedusaPriceProvider(configuration, PriceSchema, cache, context, medusaClient);
44
+ client.price = new MedusaPriceProvider(configuration, cache, context, medusaClient);
45
45
  }
46
46
  if (caps.inventory) {
47
- client.inventory = new MedusaInventoryProvider(configuration, InventorySchema, cache, context, medusaClient);
47
+ client.inventory = new MedusaInventoryProvider(configuration, cache, context, medusaClient);
48
48
  }
49
49
  if (caps.identity) {
50
- client.identity = new MedusaIdentityProvider(configuration, IdentitySchema, cache, context, medusaClient);
50
+ client.identity = new MedusaIdentityProvider(configuration, cache, context, medusaClient);
51
51
  }
52
52
  return client;
53
53
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@reactionary/provider-medusa",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
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.81",
9
+ "@reactionary/core": "0.0.83",
10
10
  "@medusajs/js-sdk": "^2.0.0",
11
11
  "debug": "^4.3.4",
12
12
  "@medusajs/types": "^2.11.0",
@@ -14,19 +14,14 @@ import {
14
14
  CartProvider,
15
15
  CartSchema,
16
16
  CartIdentifierSchema,
17
- OrderIdentifierSchema,
18
17
  CartQueryByIdSchema,
19
18
  CartMutationItemAddSchema,
20
19
  CartMutationItemRemoveSchema,
21
20
  CartMutationItemQuantityChangeSchema,
22
21
  CartMutationDeleteCartSchema,
23
- CartMutationSetShippingInfoSchema,
24
- CartMutationSetBillingAddressSchema,
25
22
  CartMutationApplyCouponSchema,
26
23
  CartMutationRemoveCouponSchema,
27
- CartMutationCheckoutSchema,
28
24
  CartMutationChangeCurrencySchema,
29
- LanguageContextSchema,
30
25
  ProductVariantIdentifierSchema,
31
26
  Reactionary
32
27
  } from "@reactionary/core";
@@ -39,8 +34,8 @@ import {
39
34
  } from "../schema/medusa.schema.js";
40
35
  const debug = createDebug("reactionary:medusa:cart");
41
36
  class MedusaCartProvider extends CartProvider {
42
- constructor(config, schema, cache, context, client) {
43
- super(schema, cache, context);
37
+ constructor(config, cache, context, client) {
38
+ super(cache, context);
44
39
  this.client = client;
45
40
  this.config = config;
46
41
  }
@@ -299,20 +294,19 @@ class MedusaCartProvider extends CartProvider {
299
294
  return this.client.getClient();
300
295
  }
301
296
  parseSingle(remote) {
302
- const result = this.newModel();
303
- result.identifier = MedusaCartIdentifierSchema.parse({
297
+ const identifier = MedusaCartIdentifierSchema.parse({
304
298
  key: remote.id,
305
299
  region_id: remote.region_id
306
300
  });
307
- result.name = "" + (remote.metadata?.["name"] || "");
308
- result.description = "" + (remote.metadata?.["description"] || "");
301
+ const name = "" + (remote.metadata?.["name"] || "");
302
+ const description = "" + (remote.metadata?.["description"] || "");
309
303
  const grandTotal = remote.total || 0;
310
304
  const shippingTotal = remote.shipping_total || 0;
311
305
  const taxTotal = remote.tax_total || 0;
312
306
  const discountTotal = remote.discount_total || 0;
313
307
  const subtotal = remote.subtotal || 0;
314
308
  const currency = (remote.currency_code || "EUR").toUpperCase();
315
- result.price = {
309
+ const price = {
316
310
  totalTax: {
317
311
  value: taxTotal,
318
312
  currency
@@ -338,6 +332,7 @@ class MedusaCartProvider extends CartProvider {
338
332
  currency
339
333
  }
340
334
  };
335
+ const items = new Array();
341
336
  for (const remoteItem of remote.items || []) {
342
337
  const item = CartItemSchema.parse({});
343
338
  item.identifier.key = remoteItem.id;
@@ -367,16 +362,27 @@ class MedusaCartProvider extends CartProvider {
367
362
  currency
368
363
  }
369
364
  };
370
- result.items.push(item);
365
+ items.push(item);
371
366
  }
372
- result.meta = {
367
+ const meta = {
373
368
  cache: {
374
369
  hit: false,
375
- key: this.generateCacheKeySingle(result.identifier)
370
+ key: this.generateCacheKeySingle(identifier)
376
371
  },
377
372
  placeholder: false
378
373
  };
379
- return this.assert(result);
374
+ const result = {
375
+ identifier,
376
+ name,
377
+ description,
378
+ price,
379
+ items,
380
+ meta,
381
+ userId: {
382
+ userId: "???"
383
+ }
384
+ };
385
+ return result;
380
386
  }
381
387
  }
382
388
  __decorateClass([
@@ -19,11 +19,13 @@ import {
19
19
  CategoryQueryForChildCategoriesSchema,
20
20
  CategoryQueryForTopCategoriesSchema,
21
21
  createPaginatedResponseSchema,
22
- Reactionary
22
+ Reactionary,
23
+ CategoryPaginatedResultSchema
23
24
  } from "@reactionary/core";
25
+ import z from "zod";
24
26
  class MedusaCategoryProvider extends CategoryProvider {
25
- constructor(config, schema, cache, context, client) {
26
- super(schema, cache, context);
27
+ constructor(config, cache, context, client) {
28
+ super(cache, context);
27
29
  this.client = client;
28
30
  this.config = config;
29
31
  }
@@ -41,13 +43,17 @@ class MedusaCategoryProvider extends CategoryProvider {
41
43
  if (categoryResult.product_categories.length === 0) {
42
44
  break;
43
45
  }
44
- candidate = categoryResult.product_categories.find((cat) => cat.metadata?.["external_id"] === externalId);
46
+ candidate = categoryResult.product_categories.find(
47
+ (cat) => cat.metadata?.["external_id"] === externalId
48
+ );
45
49
  if (candidate) {
46
50
  break;
47
51
  }
48
52
  offset += limit;
49
53
  } catch (error) {
50
- throw new Error("Category not found " + externalId + " due to error: " + error);
54
+ throw new Error(
55
+ "Category not found " + externalId + " due to error: " + error
56
+ );
51
57
  break;
52
58
  }
53
59
  }
@@ -56,9 +62,22 @@ class MedusaCategoryProvider extends CategoryProvider {
56
62
  async getById(payload) {
57
63
  const candidate = await this.resolveCategoryIdByExternalId(payload.id.key);
58
64
  if (!candidate) {
59
- const dummyCategory = this.newModel();
60
- dummyCategory.meta.placeholder = true;
61
- dummyCategory.identifier = { key: payload.id.key };
65
+ const dummyCategory = {
66
+ identifier: {
67
+ key: payload.id.key
68
+ },
69
+ images: [],
70
+ name: "",
71
+ slug: "",
72
+ text: "",
73
+ meta: {
74
+ cache: {
75
+ hit: false,
76
+ key: ""
77
+ },
78
+ placeholder: false
79
+ }
80
+ };
62
81
  return dummyCategory;
63
82
  }
64
83
  return this.parseSingle(candidate);
@@ -76,7 +95,9 @@ class MedusaCategoryProvider extends CategoryProvider {
76
95
  return this.parseSingle(categoryResult.product_categories[0]);
77
96
  }
78
97
  async getBreadcrumbPathToCategory(payload) {
79
- const actualCategoryId = await this.resolveCategoryIdByExternalId(payload.id.key);
98
+ const actualCategoryId = await this.resolveCategoryIdByExternalId(
99
+ payload.id.key
100
+ );
80
101
  if (!actualCategoryId) {
81
102
  throw new Error("Category not found " + payload.id.key);
82
103
  }
@@ -85,7 +106,7 @@ class MedusaCategoryProvider extends CategoryProvider {
85
106
  fields: "+metadata,+parent_category.metadata",
86
107
  include_ancestors_tree: true
87
108
  });
88
- let results = [];
109
+ let results = new Array();
89
110
  let current = path.product_category;
90
111
  while (current) {
91
112
  results.push(this.parseSingle(current));
@@ -96,7 +117,9 @@ class MedusaCategoryProvider extends CategoryProvider {
96
117
  }
97
118
  async findChildCategories(payload) {
98
119
  const sdk = await this.client.getClient();
99
- const actualParentId = await this.resolveCategoryIdByExternalId(payload.parentId.key);
120
+ const actualParentId = await this.resolveCategoryIdByExternalId(
121
+ payload.parentId.key
122
+ );
100
123
  if (!actualParentId) {
101
124
  throw new Error("Parent category not found " + payload.parentId.key);
102
125
  }
@@ -110,10 +133,7 @@ class MedusaCategoryProvider extends CategoryProvider {
110
133
  result.meta = {
111
134
  cache: {
112
135
  hit: false,
113
- key: this.generateCacheKeyPaginatedResult(
114
- "top",
115
- result
116
- )
136
+ key: this.generateCacheKeyPaginatedResult("top", result)
117
137
  },
118
138
  placeholder: false
119
139
  };
@@ -131,39 +151,55 @@ class MedusaCategoryProvider extends CategoryProvider {
131
151
  result.meta = {
132
152
  cache: {
133
153
  hit: false,
134
- key: this.generateCacheKeyPaginatedResult(
135
- "top",
136
- result
137
- )
154
+ key: this.generateCacheKeyPaginatedResult("top", result)
138
155
  },
139
156
  placeholder: false
140
157
  };
141
158
  return result;
142
159
  }
143
160
  parseSingle(_body) {
144
- const model = this.newModel();
145
- model.identifier = CategoryIdentifierSchema.parse({ key: _body.metadata?.["external_id"] || "" });
146
- model.name = _body.name;
147
- model.slug = _body.handle;
148
- model.text = _body.description || _body.name || "";
149
- model.parentCategory = _body.parent_category_id ? { key: _body.parent_category?.metadata?.["external_id"] + "" || "" } : void 0;
150
- return this.assert(model);
161
+ const identifier = CategoryIdentifierSchema.parse({
162
+ key: _body.metadata?.["external_id"] || ""
163
+ });
164
+ const name = _body.name;
165
+ const slug = _body.handle;
166
+ const text = _body.description || _body.name || "";
167
+ const parentCategory = _body.parent_category_id ? { key: _body.parent_category?.metadata?.["external_id"] + "" || "" } : void 0;
168
+ const result = {
169
+ identifier,
170
+ name,
171
+ slug,
172
+ text,
173
+ parentCategory,
174
+ images: [],
175
+ meta: {
176
+ cache: {
177
+ hit: false,
178
+ key: ""
179
+ },
180
+ placeholder: false
181
+ }
182
+ };
183
+ return result;
151
184
  }
152
185
  parsePaginatedResult(body) {
153
186
  const items = body.product_categories.map((x) => this.parseSingle(x));
154
- const totalPages = Math.ceil((body.count ?? 0) / Math.max(body.product_categories.length, 1));
187
+ const totalPages = Math.ceil(
188
+ (body.count ?? 0) / Math.max(body.product_categories.length, 1)
189
+ );
155
190
  const pageNumber = body.count === 0 ? 1 : Math.floor(body.offset / body.product_categories.length) + 1;
156
- const result = createPaginatedResponseSchema(this.schema).parse({
157
- meta: {
158
- cache: { hit: false, key: "unknown" },
159
- placeholder: false
160
- },
191
+ const meta = {
192
+ cache: { hit: false, key: "unknown" },
193
+ placeholder: false
194
+ };
195
+ const result = {
161
196
  pageNumber,
162
197
  pageSize: Math.max(body.product_categories.length, 1),
163
198
  totalCount: body.count,
164
199
  totalPages,
165
- items
166
- });
200
+ items,
201
+ meta
202
+ };
167
203
  return result;
168
204
  }
169
205
  }
@@ -181,17 +217,20 @@ __decorateClass([
181
217
  ], MedusaCategoryProvider.prototype, "getBySlug", 1);
182
218
  __decorateClass([
183
219
  Reactionary({
184
- inputSchema: CategoryQueryForBreadcrumbSchema
220
+ inputSchema: CategoryQueryForBreadcrumbSchema,
221
+ outputSchema: z.array(CategorySchema)
185
222
  })
186
223
  ], MedusaCategoryProvider.prototype, "getBreadcrumbPathToCategory", 1);
187
224
  __decorateClass([
188
225
  Reactionary({
189
- inputSchema: CategoryQueryForChildCategoriesSchema
226
+ inputSchema: CategoryQueryForChildCategoriesSchema,
227
+ outputSchema: CategoryPaginatedResultSchema
190
228
  })
191
229
  ], MedusaCategoryProvider.prototype, "findChildCategories", 1);
192
230
  __decorateClass([
193
231
  Reactionary({
194
- inputSchema: CategoryQueryForTopCategoriesSchema
232
+ inputSchema: CategoryQueryForTopCategoriesSchema,
233
+ outputSchema: CategoryPaginatedResultSchema
195
234
  })
196
235
  ], MedusaCategoryProvider.prototype, "findTopCategories", 1);
197
236
  export {
@@ -24,7 +24,6 @@ import {
24
24
  CheckoutQueryForAvailablePaymentMethodsSchema,
25
25
  CheckoutQueryForAvailableShippingMethodsSchema,
26
26
  CheckoutSchema,
27
- ImageSchema,
28
27
  MonetaryAmountSchema,
29
28
  PaymentInstructionIdentifierSchema,
30
29
  PaymentInstructionSchema,
@@ -37,6 +36,7 @@ import {
37
36
  ShippingMethodSchema
38
37
  } from "@reactionary/core";
39
38
  import createDebug from "debug";
39
+ import z from "zod";
40
40
  import {
41
41
  MedusaCartIdentifierSchema,
42
42
  MedusaOrderIdentifierSchema
@@ -52,8 +52,8 @@ class CheckoutNotReadyForFinalizationError extends Error {
52
52
  }
53
53
  }
54
54
  class MedusaCheckoutProvider extends CheckoutProvider {
55
- constructor(config, schema, cache, context, client) {
56
- super(schema, cache, context);
55
+ constructor(config, cache, context, client) {
56
+ super(cache, context);
57
57
  this.client = client;
58
58
  this.returnedCheckoutFields = "+items.*";
59
59
  this.config = config;
@@ -289,20 +289,19 @@ class MedusaCheckoutProvider extends CheckoutProvider {
289
289
  };
290
290
  }
291
291
  parseSingle(remote) {
292
- const result = this.newModel();
293
- result.identifier = CheckoutIdentifierSchema.parse({
292
+ const identifier = CheckoutIdentifierSchema.parse({
294
293
  key: remote.id
295
294
  // region_id: remote.region_id,
296
295
  });
297
- result.name = "" + (remote.metadata?.["name"] || "");
298
- result.description = "" + (remote.metadata?.["description"] || "");
296
+ const name = "" + (remote.metadata?.["name"] || "");
297
+ const description = "" + (remote.metadata?.["description"] || "");
299
298
  const grandTotal = remote.total || 0;
300
299
  const shippingTotal = remote.shipping_total || 0;
301
300
  const taxTotal = remote.tax_total || 0;
302
301
  const discountTotal = remote.discount_total || 0;
303
302
  const subtotal = remote.subtotal || 0;
304
303
  const currency = (remote.currency_code || "EUR").toUpperCase();
305
- result.price = {
304
+ const price = {
306
305
  totalTax: {
307
306
  value: taxTotal,
308
307
  currency
@@ -328,6 +327,7 @@ class MedusaCheckoutProvider extends CheckoutProvider {
328
327
  currency
329
328
  }
330
329
  };
330
+ const items = new Array();
331
331
  for (const remoteItem of remote.items || []) {
332
332
  const item = CheckoutItemSchema.parse({});
333
333
  item.identifier.key = remoteItem.id;
@@ -356,21 +356,21 @@ class MedusaCheckoutProvider extends CheckoutProvider {
356
356
  currency
357
357
  }
358
358
  };
359
- result.items.push(item);
359
+ items.push(item);
360
360
  }
361
361
  const meta = {
362
362
  cache: {
363
363
  hit: false,
364
- key: this.generateCacheKeySingle(result.identifier)
364
+ key: this.generateCacheKeySingle(identifier)
365
365
  },
366
366
  placeholder: false
367
367
  };
368
- result.billingAddress = remote.billing_address ? this.composeAddressFromStoreAddress(remote.billing_address) : void 0;
369
- result.shippingAddress = remote.shipping_address ? this.composeAddressFromStoreAddress(remote.shipping_address) : void 0;
370
- result.meta = meta;
368
+ const billingAddress = remote.billing_address ? this.composeAddressFromStoreAddress(remote.billing_address) : void 0;
369
+ const shippingAddress = remote.shipping_address ? this.composeAddressFromStoreAddress(remote.shipping_address) : void 0;
371
370
  const backupUnattendedDelivery = remote.metadata?.["consent_for_unattended_delivery"] !== void 0 ? remote.metadata?.["consent_for_unattended_delivery"] === "true" : void 0;
372
371
  const backupInstructions = remote.metadata?.["instructions"] !== void 0 ? remote.metadata?.["instructions"] + "" : void 0;
373
372
  const backupPickupPoint = remote.metadata?.["pickup_point"] !== void 0 ? remote.metadata?.["pickup_point"] + "" : void 0;
373
+ let shippingInstruction;
374
374
  remote.shipping_methods?.forEach((sm) => {
375
375
  let pickupPoint = "";
376
376
  ;
@@ -390,7 +390,7 @@ class MedusaCheckoutProvider extends CheckoutProvider {
390
390
  if (!consentForUnattendedDelivery) {
391
391
  consentForUnattendedDelivery = backupUnattendedDelivery || false;
392
392
  }
393
- result.shippingInstruction = ShippingInstructionSchema.parse({
393
+ shippingInstruction = ShippingInstructionSchema.parse({
394
394
  shippingMethod: ShippingMethodIdentifierSchema.parse({ key: sm.shipping_option_id }),
395
395
  consentForUnattendedDelivery,
396
396
  instructions,
@@ -398,6 +398,7 @@ class MedusaCheckoutProvider extends CheckoutProvider {
398
398
  meta
399
399
  });
400
400
  });
401
+ const paymentInstructions = new Array();
401
402
  for (const remotePayment of remote.payment_collection?.payment_sessions || []) {
402
403
  if (remotePayment.status === "canceled" || remotePayment.status === "error") {
403
404
  console.warn(
@@ -410,7 +411,7 @@ class MedusaCheckoutProvider extends CheckoutProvider {
410
411
  name: remotePayment.provider_id,
411
412
  processor: remotePayment.provider_id
412
413
  });
413
- result.paymentInstructions.push(
414
+ paymentInstructions.push(
414
415
  PaymentInstructionSchema.parse({
415
416
  meta,
416
417
  identifier: PaymentInstructionIdentifierSchema.parse({
@@ -429,17 +430,33 @@ class MedusaCheckoutProvider extends CheckoutProvider {
429
430
  })
430
431
  );
431
432
  }
432
- result.originalCartReference = MedusaCartIdentifierSchema.parse({
433
+ const originalCartReference = MedusaCartIdentifierSchema.parse({
433
434
  key: remote.id,
434
435
  region: remote.region_id
435
436
  });
437
+ let resultingOrder;
436
438
  if (remote.metadata?.["order_id"]) {
437
- result.resultingOrder = MedusaOrderIdentifierSchema.parse({
439
+ resultingOrder = MedusaOrderIdentifierSchema.parse({
438
440
  key: remote.metadata?.["order_id"] + "" || "",
439
441
  display_id: Number(remote.metadata?.["order_display_id"] + "" || "0")
440
442
  });
441
443
  }
442
- return this.assert(result);
444
+ const result = {
445
+ identifier,
446
+ name,
447
+ description,
448
+ price,
449
+ items,
450
+ meta,
451
+ originalCartReference,
452
+ paymentInstructions,
453
+ readyForFinalization: false,
454
+ billingAddress,
455
+ resultingOrder,
456
+ shippingAddress,
457
+ shippingInstruction
458
+ };
459
+ return result;
443
460
  }
444
461
  }
445
462
  __decorateClass([
@@ -462,12 +479,14 @@ __decorateClass([
462
479
  ], MedusaCheckoutProvider.prototype, "setShippingAddress", 1);
463
480
  __decorateClass([
464
481
  Reactionary({
465
- inputSchema: CheckoutQueryForAvailableShippingMethodsSchema
482
+ inputSchema: CheckoutQueryForAvailableShippingMethodsSchema,
483
+ outputSchema: z.array(ShippingMethodSchema)
466
484
  })
467
485
  ], MedusaCheckoutProvider.prototype, "getAvailableShippingMethods", 1);
468
486
  __decorateClass([
469
487
  Reactionary({
470
- inputSchema: CheckoutQueryForAvailablePaymentMethodsSchema
488
+ inputSchema: CheckoutQueryForAvailablePaymentMethodsSchema,
489
+ outputSchema: z.array(PaymentMethodSchema)
471
490
  })
472
491
  ], MedusaCheckoutProvider.prototype, "getAvailablePaymentMethods", 1);
473
492
  __decorateClass([
@@ -23,28 +23,52 @@ import {
23
23
  import createDebug from "debug";
24
24
  const debug = createDebug("reactionary:medusa:identity");
25
25
  class MedusaIdentityProvider extends IdentityProvider {
26
- constructor(config, schema, cache, context, client) {
27
- super(schema, cache, context);
26
+ constructor(config, cache, context, client) {
27
+ super(cache, context);
28
28
  this.config = config;
29
29
  this.client = client;
30
30
  }
31
+ createAnonymousIdentity() {
32
+ return {
33
+ meta: {
34
+ cache: {
35
+ hit: false,
36
+ key: ""
37
+ },
38
+ placeholder: false
39
+ },
40
+ type: "Anonymous"
41
+ };
42
+ }
31
43
  async getSelf(_payload) {
32
44
  try {
33
45
  const medusaClient = await this.client.getClient();
34
46
  const token = await medusaClient.client.getToken();
35
47
  if (!token) {
36
48
  debug("No active session token found, returning anonymous identity");
37
- return AnonymousIdentitySchema.parse({});
49
+ return this.createAnonymousIdentity();
38
50
  }
39
51
  const customerResponse = await medusaClient.store.customer.retrieve();
40
52
  if (customerResponse.customer) {
41
53
  debug("Customer authenticated:", customerResponse.customer.email);
42
- return RegisteredIdentitySchema.parse({});
54
+ return {
55
+ id: {
56
+ userId: customerResponse.customer.id
57
+ },
58
+ meta: {
59
+ cache: {
60
+ hit: false,
61
+ key: ""
62
+ },
63
+ placeholder: false
64
+ },
65
+ type: "Registered"
66
+ };
43
67
  }
44
- return AnonymousIdentitySchema.parse({});
68
+ return this.createAnonymousIdentity();
45
69
  } catch (error) {
46
70
  debug("getSelf failed, returning anonymous identity:", error);
47
- return AnonymousIdentitySchema.parse({});
71
+ return this.createAnonymousIdentity();
48
72
  }
49
73
  }
50
74
  async login(payload) {
@@ -75,6 +99,7 @@ class MedusaIdentityProvider extends IdentityProvider {
75
99
  this.context
76
100
  );
77
101
  return identity;
102
+ ;
78
103
  }
79
104
  }
80
105
  __decorateClass([
@@ -13,15 +13,14 @@ import {
13
13
  InventoryProvider,
14
14
  InventorySchema,
15
15
  InventoryQueryBySKUSchema,
16
- Reactionary,
17
- ProductVariantIdentifierSchema
16
+ Reactionary
18
17
  } from "@reactionary/core";
19
18
  import { MedusaAdminClient } from "../core/client.js";
20
19
  import createDebug from "debug";
21
20
  const debug = createDebug("reactionary:medusa:inventory");
22
21
  class MedusaInventoryProvider extends InventoryProvider {
23
- constructor(config, schema, cache, context, client) {
24
- super(schema, cache, context);
22
+ constructor(config, cache, context, client) {
23
+ super(cache, context);
25
24
  this.client = client;
26
25
  this.config = config;
27
26
  }
@@ -84,8 +83,7 @@ class MedusaInventoryProvider extends InventoryProvider {
84
83
  }
85
84
  parseSingle(_body) {
86
85
  const { sku, fulfillmentCenterKey, quantity } = _body;
87
- const model = this.newModel();
88
- model.identifier = {
86
+ const identifier = {
89
87
  variant: {
90
88
  sku
91
89
  },
@@ -93,20 +91,24 @@ class MedusaInventoryProvider extends InventoryProvider {
93
91
  key: fulfillmentCenterKey
94
92
  }
95
93
  };
96
- model.quantity = quantity;
97
- if (model.quantity > 0) {
98
- model.status = "inStock";
99
- } else {
100
- model.status = "outOfStock";
94
+ let status = "outOfStock";
95
+ if (quantity > 0) {
96
+ status = "inStock";
101
97
  }
102
- model.meta = {
98
+ const meta = {
103
99
  cache: {
104
100
  hit: false,
105
- key: this.generateCacheKeySingle(model.identifier)
101
+ key: this.generateCacheKeySingle(identifier)
106
102
  },
107
103
  placeholder: false
108
104
  };
109
- return this.assert(model);
105
+ const result = {
106
+ identifier,
107
+ meta,
108
+ quantity,
109
+ status
110
+ };
111
+ return result;
110
112
  }
111
113
  /**
112
114
  * Utility function to create an empty inventory result.
@@ -116,21 +118,26 @@ class MedusaInventoryProvider extends InventoryProvider {
116
118
  * @returns
117
119
  */
118
120
  createEmptyInventoryResult(sku, fulfillmentCenterKey) {
119
- const model = this.newModel();
120
- model.identifier = {
121
+ const identifier = {
121
122
  variant: { sku },
122
123
  fulfillmentCenter: { key: fulfillmentCenterKey }
123
124
  };
124
- model.quantity = 0;
125
- model.status = "outOfStock";
126
- model.meta = {
125
+ const quantity = 0;
126
+ const status = "outOfStock";
127
+ const meta = {
127
128
  cache: {
128
129
  hit: false,
129
- key: this.generateCacheKeySingle(model.identifier)
130
+ key: this.generateCacheKeySingle(identifier)
130
131
  },
131
132
  placeholder: true
132
133
  };
133
- return this.assert(model);
134
+ const result = {
135
+ identifier,
136
+ meta,
137
+ quantity,
138
+ status
139
+ };
140
+ return result;
134
141
  }
135
142
  getResourceName() {
136
143
  return "inventory";