@reactionary/medusa 0.6.9 → 0.6.10

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.
@@ -10,28 +10,29 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
12
  import {
13
+ CartCapability,
13
14
  CartIdentifierSchema,
14
15
  CartMutationApplyCouponSchema,
15
16
  CartMutationChangeCurrencySchema,
17
+ CartMutationCreateCartSchema,
16
18
  CartMutationDeleteCartSchema,
17
19
  CartMutationItemAddSchema,
18
20
  CartMutationItemQuantityChangeSchema,
19
21
  CartMutationItemRemoveSchema,
20
22
  CartMutationRemoveCouponSchema,
21
- CartCapability,
23
+ CartMutationRenameCartSchema,
24
+ CartPaginatedSearchResultSchema,
22
25
  CartQueryByIdSchema,
26
+ CartQueryListSchema,
23
27
  CartSchema,
24
28
  error,
25
- ProductVariantIdentifierSchema,
26
29
  Reactionary,
27
30
  success
28
31
  } from "@reactionary/core";
32
+ import {} from "@medusajs/types";
29
33
  import createDebug from "debug";
30
- import { MedusaCartIdentifierSchema } from "../schema/medusa.schema.js";
31
34
  import {
32
- handleProviderError,
33
- parseMedusaCostBreakdown,
34
- parseMedusaItemPrice
35
+ handleProviderError
35
36
  } from "../utils/medusa-helpers.js";
36
37
  const debug = createDebug("reactionary:medusa:cart");
37
38
  class MedusaCartCapability extends CartCapability {
@@ -50,6 +51,29 @@ class MedusaCartCapability extends CartCapability {
50
51
  * example: this.includedFields = [includedFields, '+discounts.*'].join(',');
51
52
  */
52
53
  includedFields = ["+items.*"].join(",");
54
+ async listCarts(payload) {
55
+ const client = await this.getClient();
56
+ const sessionData = this.medusaApi.getSessionData();
57
+ let cartCollection = payload.search.company ? sessionData.allOwnedCarts?.[payload.search.company.taxIdentifier] : sessionData.allOwnedCarts?.["_me"];
58
+ const totalCount = cartCollection ? cartCollection.length : 0;
59
+ if (cartCollection) {
60
+ cartCollection = cartCollection.slice((payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize, payload.search.paginationOptions.pageNumber * payload.search.paginationOptions.pageSize);
61
+ } else {
62
+ cartCollection = [];
63
+ }
64
+ const shortFields = ["id", "customerId", "updated_at", "metadata", "items.id"].join(",");
65
+ const allPromises = cartCollection.map((cartIdentifier) => client.store.cart.retrieve(cartIdentifier.key, { fields: shortFields }));
66
+ const responses = await Promise.all(allPromises);
67
+ const carts = responses.map((response) => response.cart).filter((cart) => !!cart);
68
+ return success(this.factory.parseCartPaginatedSearchResult(
69
+ this.context,
70
+ {
71
+ items: carts,
72
+ totalCount
73
+ },
74
+ payload
75
+ ));
76
+ }
53
77
  async getById(payload) {
54
78
  try {
55
79
  const client = await this.getClient();
@@ -69,7 +93,7 @@ class MedusaCartCapability extends CartCapability {
69
93
  identifier: payload
70
94
  });
71
95
  } catch (err) {
72
- debug("Failed to get cart by ID:", error);
96
+ debug("Failed to get cart by ID:", err);
73
97
  return error({
74
98
  type: "NotFound",
75
99
  identifier: payload
@@ -92,9 +116,12 @@ class MedusaCartCapability extends CartCapability {
92
116
  async add(payload) {
93
117
  try {
94
118
  const client = await this.getClient();
95
- let cartIdentifier = payload.cart;
119
+ const cartIdentifier = payload.cart;
96
120
  if (!cartIdentifier) {
97
- cartIdentifier = await this.createCart();
121
+ return error({
122
+ type: "InvalidInput",
123
+ error: "Cart identifier is required to add item to cart"
124
+ });
98
125
  }
99
126
  const medusaId = cartIdentifier;
100
127
  if (debug.enabled) {
@@ -126,6 +153,95 @@ class MedusaCartCapability extends CartCapability {
126
153
  handleProviderError("add item to cart", error2);
127
154
  }
128
155
  }
156
+ async renameCart(payload) {
157
+ const client = await this.getClient();
158
+ const medusaId = payload.cart;
159
+ const cartResponse = await client.store.cart.retrieve(medusaId.key, { fields: ["metadata.*"].join(",") });
160
+ if (!cartResponse.cart) {
161
+ return error({
162
+ type: "NotFound",
163
+ identifier: payload.cart
164
+ });
165
+ }
166
+ const currentMetadata = cartResponse.cart.metadata || {};
167
+ const updatedMetadata = {
168
+ ...currentMetadata,
169
+ name: payload.newName
170
+ };
171
+ const response = await client.store.cart.update(
172
+ medusaId.key,
173
+ {
174
+ metadata: updatedMetadata
175
+ },
176
+ {
177
+ fields: this.includedFields
178
+ }
179
+ );
180
+ if (response.cart) {
181
+ return success(this.factory.parseCart(this.context, response.cart));
182
+ }
183
+ throw new Error("Failed to rename cart");
184
+ }
185
+ /**
186
+ * Extension point to control the payload sent to Medusa when creating a cart. By default, it only includes the currency code, but you can override it to include more fields as needed.
187
+ * @param currency
188
+ * @returns
189
+ */
190
+ createCartPayload(payload) {
191
+ return {
192
+ currency_code: (this.context.languageContext.currencyCode || "EUR").toLowerCase(),
193
+ locale: this.context.languageContext.locale || "en",
194
+ metadata: {
195
+ name: payload.name
196
+ }
197
+ };
198
+ }
199
+ addCartToOwnedList(cartIdentifier, companyId) {
200
+ const sessionData = this.medusaApi.getSessionData();
201
+ const companyIdToUse = companyId ? companyId.taxIdentifier : "_me";
202
+ if (sessionData.allOwnedCarts) {
203
+ sessionData.allOwnedCarts[companyIdToUse] = [
204
+ ...sessionData.allOwnedCarts[companyIdToUse] || [],
205
+ cartIdentifier
206
+ ];
207
+ } else {
208
+ sessionData.allOwnedCarts = {
209
+ [companyIdToUse]: [cartIdentifier]
210
+ };
211
+ }
212
+ this.medusaApi.setSessionData(sessionData);
213
+ }
214
+ removeCartFromOwnedList(cartIdentifier, company) {
215
+ const sessionData = this.medusaApi.getSessionData();
216
+ const companyIdToUse = company ? company.taxIdentifier : "_me";
217
+ if (sessionData.allOwnedCarts && sessionData.allOwnedCarts[companyIdToUse]) {
218
+ sessionData.allOwnedCarts[companyIdToUse] = sessionData.allOwnedCarts[companyIdToUse].filter(
219
+ (c) => c.key !== cartIdentifier.key
220
+ );
221
+ this.medusaApi.setSessionData(sessionData);
222
+ }
223
+ }
224
+ async createCart(payload) {
225
+ try {
226
+ const client = await this.getClient();
227
+ const response = await client.store.cart.create(
228
+ this.createCartPayload(payload),
229
+ {
230
+ fields: this.includedFields
231
+ }
232
+ );
233
+ if (response.cart) {
234
+ this.addCartToOwnedList(this.factory.parseCartIdentifier(this.context, response.cart), payload.company);
235
+ this.medusaApi.setSessionData({
236
+ activeCartId: this.factory.parseCartIdentifier(this.context, response.cart)
237
+ });
238
+ return success(this.factory.parseCart(this.context, response.cart));
239
+ }
240
+ throw new Error("Failed to create cart");
241
+ } catch (error2) {
242
+ handleProviderError("create cart", error2);
243
+ }
244
+ }
129
245
  async remove(payload) {
130
246
  try {
131
247
  const client = await this.getClient();
@@ -184,16 +300,25 @@ class MedusaCartCapability extends CartCapability {
184
300
  try {
185
301
  const client = await this.getClient();
186
302
  const sessionData = this.medusaApi.getSessionData();
187
- const activeCartId = sessionData.activeCartId;
303
+ let activeCartId = sessionData.activeCartId;
304
+ if (!activeCartId && sessionData && sessionData.allOwnedCarts) {
305
+ if (sessionData.allOwnedCarts["_me"]) {
306
+ activeCartId = sessionData.allOwnedCarts["_me"][0] || void 0;
307
+ }
308
+ }
188
309
  if (activeCartId) {
189
- try {
190
- await client.store.cart.retrieve(activeCartId);
191
- return success(this.factory.parseCartIdentifier(this.context, {
192
- key: activeCartId,
193
- region_id: (await this.medusaApi.getActiveRegion()).id
194
- }));
195
- } catch {
310
+ const response = await client.store.cart.retrieve(activeCartId.key, { fields: "id,region_id" });
311
+ if (!response.cart) {
312
+ delete sessionData.activeCartId;
313
+ this.medusaApi.setSessionData({
314
+ activeCartId: void 0
315
+ });
316
+ return error({
317
+ type: "NotFound",
318
+ identifier: activeCartId
319
+ });
196
320
  }
321
+ return success(this.factory.parseCartIdentifier(this.context, response.cart));
197
322
  }
198
323
  return error({
199
324
  type: "NotFound",
@@ -320,7 +445,7 @@ class MedusaCartCapability extends CartCapability {
320
445
  );
321
446
  if (updatedCartResponse.cart) {
322
447
  this.medusaApi.setSessionData({
323
- activeCartId: updatedCartResponse.cart.id
448
+ activeCartId: this.factory.parseCartIdentifier(this.context, updatedCartResponse.cart)
324
449
  });
325
450
  return success(this.factory.parseCart(this.context, updatedCartResponse.cart));
326
451
  }
@@ -329,44 +454,17 @@ class MedusaCartCapability extends CartCapability {
329
454
  handleProviderError("change currency", error2);
330
455
  }
331
456
  }
332
- /**
333
- * Extension point to control the payload sent to Medusa when creating a cart. By default, it only includes the currency code, but you can override it to include more fields as needed.
334
- * @param currency
335
- * @returns
336
- */
337
- createCartPayload(currency) {
338
- return {
339
- currency_code: (currency || this.context.languageContext.currencyCode || "").toLowerCase()
340
- };
341
- }
342
- async createCart(currency) {
343
- try {
344
- const client = await this.getClient();
345
- const response = await client.store.cart.create(
346
- this.createCartPayload(currency),
347
- {
348
- fields: this.includedFields
349
- }
350
- );
351
- if (response.cart) {
352
- const cartIdentifier = this.factory.parseCartIdentifier(this.context, {
353
- key: response.cart.id,
354
- region_id: response.cart.region_id
355
- });
356
- this.medusaApi.setSessionData({
357
- activeCartId: cartIdentifier.key
358
- });
359
- return cartIdentifier;
360
- }
361
- throw new Error("Failed to create cart");
362
- } catch (error2) {
363
- handleProviderError("create cart", error2);
364
- }
365
- }
366
457
  async getClient() {
367
458
  return this.medusaApi.getClient();
368
459
  }
369
460
  }
461
+ __decorateClass([
462
+ Reactionary({
463
+ inputSchema: CartQueryListSchema,
464
+ outputSchema: CartPaginatedSearchResultSchema,
465
+ cache: false
466
+ })
467
+ ], MedusaCartCapability.prototype, "listCarts", 1);
370
468
  __decorateClass([
371
469
  Reactionary({
372
470
  inputSchema: CartQueryByIdSchema,
@@ -379,6 +477,18 @@ __decorateClass([
379
477
  outputSchema: CartSchema
380
478
  })
381
479
  ], MedusaCartCapability.prototype, "add", 1);
480
+ __decorateClass([
481
+ Reactionary({
482
+ inputSchema: CartMutationRenameCartSchema,
483
+ outputSchema: CartSchema
484
+ })
485
+ ], MedusaCartCapability.prototype, "renameCart", 1);
486
+ __decorateClass([
487
+ Reactionary({
488
+ inputSchema: CartMutationCreateCartSchema,
489
+ outputSchema: CartSchema
490
+ })
491
+ ], MedusaCartCapability.prototype, "createCart", 1);
382
492
  __decorateClass([
383
493
  Reactionary({
384
494
  inputSchema: CartMutationItemRemoveSchema,
@@ -250,7 +250,7 @@ class MedusaCheckoutCapability extends CheckoutCapability {
250
250
  const medusaId = payload.checkout;
251
251
  const response = await client.store.cart.complete(medusaId.key);
252
252
  if (response.type === "order") {
253
- await client.store.cart.update(medusaId.key, {
253
+ const updatedCart = await client.store.cart.update(medusaId.key, {
254
254
  metadata: {
255
255
  order_id: response.order.id,
256
256
  order_display_id: response.order?.display_id ? response.order.display_id + "" : ""
@@ -259,6 +259,18 @@ class MedusaCheckoutCapability extends CheckoutCapability {
259
259
  const refreshedCheckout = await this.getById({
260
260
  identifier: payload.checkout
261
261
  });
262
+ const sessionData = this.medusaApi.getSessionData();
263
+ const cartCollectionKey = "_me";
264
+ if (sessionData.allOwnedCarts?.[cartCollectionKey]) {
265
+ const updatedCollection = sessionData.allOwnedCarts[cartCollectionKey].filter((x) => x.key !== updatedCart.cart.id);
266
+ this.medusaApi.setSessionData({
267
+ allOwnedCarts: {
268
+ ...sessionData.allOwnedCarts,
269
+ [cartCollectionKey]: updatedCollection
270
+ },
271
+ activeCartId: updatedCollection.length > 0 ? updatedCollection[0] : void 0
272
+ });
273
+ }
262
274
  if (!refreshedCheckout.success) {
263
275
  throw new Error(`Unable to reload checkout ${payload.checkout.key} after completion`);
264
276
  }
@@ -40,6 +40,17 @@ class MedusaIdentityCapability extends IdentityCapability {
40
40
  const token = await medusaClient.client.getToken();
41
41
  if (!token) {
42
42
  debug("No active session token found, returning anonymous identity");
43
+ if (this.medusaApi.getSessionData().activeCartId) {
44
+ debug("Active cart found in session without token, treating as guest session");
45
+ const identity3 = {
46
+ type: "Guest",
47
+ id: {
48
+ userId: "guest"
49
+ }
50
+ };
51
+ this.updateIdentityContext(identity3);
52
+ return success(identity3);
53
+ }
43
54
  const identity2 = this.createAnonymousIdentity();
44
55
  this.updateIdentityContext(identity2);
45
56
  return success(identity2);
package/core/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Admin, Auth, Client, Store } from "@medusajs/js-sdk";
2
2
  import {
3
3
  AnonymousIdentitySchema,
4
+ GuestIdentitySchema,
4
5
  Reactionary,
5
6
  RegisteredIdentitySchema
6
7
  } from "@reactionary/core";
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  CartIdentifierSchema,
3
+ CartPaginatedSearchResultSchema,
3
4
  CartSchema,
4
5
  CategoryPaginatedResultSchema,
5
6
  CategorySchema,
@@ -157,7 +158,11 @@ function withMedusaCapabilities(configuration, capabilities) {
157
158
  client.cart = resolveCapabilityWithFactory(
158
159
  capabilities.cart,
159
160
  {
160
- factory: new MedusaCartFactory(CartSchema, CartIdentifierSchema),
161
+ factory: new MedusaCartFactory(
162
+ CartSchema,
163
+ CartIdentifierSchema,
164
+ CartPaginatedSearchResultSchema
165
+ ),
161
166
  capability: (args) => new MedusaCartCapability(
162
167
  args.config,
163
168
  args.cache,
@@ -6,9 +6,35 @@ import { parseMedusaCostBreakdown, parseMedusaItemPrice } from "../../utils/medu
6
6
  class MedusaCartFactory {
7
7
  cartSchema;
8
8
  cartIdentifierSchema;
9
- constructor(cartSchema, cartIdentifierSchema) {
9
+ cartPaginatedSearchResultSchema;
10
+ constructor(cartSchema, cartIdentifierSchema, cartPaginatedSearchResultSchema) {
10
11
  this.cartSchema = cartSchema;
11
12
  this.cartIdentifierSchema = cartIdentifierSchema;
13
+ this.cartPaginatedSearchResultSchema = cartPaginatedSearchResultSchema;
14
+ }
15
+ parseCartPaginatedSearchResult(_context, data, _query) {
16
+ const result = {
17
+ identifier: _query.search,
18
+ items: data.items.map((item) => this.parseCartSearchResultItem(_context, item)),
19
+ totalCount: data.totalCount,
20
+ pageNumber: _query.search.paginationOptions.pageNumber,
21
+ pageSize: _query.search.paginationOptions.pageSize,
22
+ totalPages: Math.ceil(data.totalCount / _query.search.paginationOptions.pageSize)
23
+ };
24
+ return this.cartPaginatedSearchResultSchema.parse(result);
25
+ }
26
+ parseCartSearchResultItem(_context, data) {
27
+ const result = {
28
+ identifier: this.parseCartIdentifier(_context, data),
29
+ numItems: data.items?.length || 0,
30
+ lastModifiedDate: new Date(data.updated_at).toISOString(),
31
+ user: {
32
+ userId: data.customer_id || "???"
33
+ },
34
+ company: void 0,
35
+ name: "" + (data.metadata?.["name"] || "")
36
+ };
37
+ return result;
12
38
  }
13
39
  parseCart(context, data) {
14
40
  const identifier = MedusaCartIdentifierSchema.parse({
@@ -52,14 +78,18 @@ class MedusaCartFactory {
52
78
  price,
53
79
  items,
54
80
  appliedPromotions,
55
- userId: {
56
- userId: "???"
81
+ user: {
82
+ userId: data.customer_id || "???"
57
83
  }
58
84
  };
59
85
  return this.cartSchema.parse(result);
60
86
  }
61
87
  parseCartIdentifier(_context, data) {
62
- return this.cartIdentifierSchema.parse(data);
88
+ const result = {
89
+ key: data.id,
90
+ region_id: data.region_id
91
+ };
92
+ return this.cartIdentifierSchema.parse(result);
63
93
  }
64
94
  /**
65
95
  * Extension point to control the parsing of a single cart item price
@@ -148,7 +148,7 @@ class MedusaCheckoutFactory {
148
148
  }
149
149
  const originalCartReference = {
150
150
  key: data.id,
151
- region: data.region_id
151
+ region_id: data.region_id
152
152
  };
153
153
  const pointOfContact = {
154
154
  email: data.email || "",
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@reactionary/medusa",
3
- "version": "0.6.9",
3
+ "version": "0.6.10",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
8
  "@medusajs/js-sdk": "^2.13.3",
9
- "@reactionary/core": "0.6.9",
9
+ "@reactionary/core": "0.6.10",
10
10
  "debug": "^4.4.3",
11
11
  "@medusajs/types": "^2.13.3",
12
12
  "zod": "4.1.9",
@@ -12,7 +12,8 @@ const MedusaRegionSchema = z.looseObject({
12
12
  currency_code: z.string()
13
13
  });
14
14
  const MedusaSessionSchema = z.looseObject({
15
- activeCartId: z.string().optional(),
15
+ activeCartId: MedusaCartIdentifierSchema.optional(),
16
+ allOwnedCarts: z.record(z.string(), z.array(MedusaCartIdentifierSchema)).optional(),
16
17
  token: z.string().optional(),
17
18
  expires: z.string().optional(),
18
19
  allRegions: z.array(MedusaRegionSchema).optional(),
@@ -1,9 +1,10 @@
1
- import type { Cache, CartFactory, CartFactoryCartOutput, CartFactoryIdentifierOutput, CartFactoryWithOutput, CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartQueryById, NotFoundError, RequestContext, Result } from '@reactionary/core';
1
+ import type { Cache, CartFactory, CartFactoryCartOutput, CartFactoryIdentifierOutput, CartFactoryWithOutput, CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCreateCart, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationRenameCart, CartPaginatedSearchResult, CartQueryById, CartQueryList, CompanyIdentifier, NotFoundError, RequestContext, Result } from '@reactionary/core';
2
2
  import { CartCapability } from '@reactionary/core';
3
+ import { type StoreAddCartLineItem, type StoreCartAddPromotion, type StoreCartRemovePromotion, type StoreCreateCart, type StoreUpdateCart, type StoreUpdateCartLineItem } from '@medusajs/types';
3
4
  import type { MedusaAPI } from '../core/client.js';
4
- import type { MedusaConfiguration } from '../schema/configuration.schema.js';
5
- import type { StoreAddCartLineItem, StoreCartAddPromotion, StoreCartRemovePromotion, StoreCreateCart, StoreUpdateCart, StoreUpdateCartLineItem } from '@medusajs/types';
6
5
  import type { MedusaCartFactory } from '../factories/cart/cart.factory.js';
6
+ import type { MedusaConfiguration } from '../schema/configuration.schema.js';
7
+ import type { MedusaCartIdentifier } from '../schema/medusa.schema.js';
7
8
  export declare class MedusaCartCapability<TFactory extends CartFactory = MedusaCartFactory> extends CartCapability<CartFactoryCartOutput<TFactory>, CartFactoryIdentifierOutput<TFactory>> {
8
9
  medusaApi: MedusaAPI;
9
10
  protected config: MedusaConfiguration;
@@ -16,6 +17,7 @@ export declare class MedusaCartCapability<TFactory extends CartFactory = MedusaC
16
17
  */
17
18
  protected includedFields: string;
18
19
  constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI, factory: CartFactoryWithOutput<TFactory>);
20
+ listCarts(payload: CartQueryList): Promise<Result<CartPaginatedSearchResult>>;
19
21
  getById(payload: CartQueryById): Promise<Result<CartFactoryCartOutput<TFactory>, NotFoundError>>;
20
22
  /**
21
23
  * Extension point for the `add` operation to control the payload sent to Medusa when adding an item to the cart. By default, it only includes the variant ID and quantity, but you can override it to include more fields as needed.
@@ -26,6 +28,16 @@ export declare class MedusaCartCapability<TFactory extends CartFactory = MedusaC
26
28
  */
27
29
  protected addPayload(payload: CartMutationItemAdd, variantId: string): StoreAddCartLineItem;
28
30
  add(payload: CartMutationItemAdd): Promise<Result<CartFactoryCartOutput<TFactory>>>;
31
+ renameCart(payload: CartMutationRenameCart): Promise<Result<CartFactoryCartOutput<TFactory>>>;
32
+ /**
33
+ * Extension point to control the payload sent to Medusa when creating a cart. By default, it only includes the currency code, but you can override it to include more fields as needed.
34
+ * @param currency
35
+ * @returns
36
+ */
37
+ protected createCartPayload(payload: CartMutationCreateCart): StoreCreateCart;
38
+ protected addCartToOwnedList(cartIdentifier: MedusaCartIdentifier, companyId?: CompanyIdentifier): void;
39
+ protected removeCartFromOwnedList(cartIdentifier: MedusaCartIdentifier, company?: CompanyIdentifier): void;
40
+ createCart(payload: CartMutationCreateCart): Promise<Result<CartFactoryCartOutput<TFactory>>>;
29
41
  remove(payload: CartMutationItemRemove): Promise<Result<CartFactoryCartOutput<TFactory>>>;
30
42
  /**
31
43
  * Extension point for the `changeQuantity` operation to control the payload sent to Medusa when changing the quantity of an item in the cart. By default, it only includes the new quantity, but you can override it to include more fields as needed.
@@ -58,13 +70,6 @@ export declare class MedusaCartCapability<TFactory extends CartFactory = MedusaC
58
70
  */
59
71
  protected changeCurrencyPayload(payload: CartMutationChangeCurrency, newRegionId: string): StoreUpdateCart;
60
72
  changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<CartFactoryCartOutput<TFactory>>>;
61
- /**
62
- * Extension point to control the payload sent to Medusa when creating a cart. By default, it only includes the currency code, but you can override it to include more fields as needed.
63
- * @param currency
64
- * @returns
65
- */
66
- protected createCartPayload(currency?: string): StoreCreateCart;
67
- protected createCart(currency?: string): Promise<CartFactoryIdentifierOutput<TFactory>>;
68
73
  protected getClient(): Promise<{
69
74
  client: import("@medusajs/js-sdk").Client;
70
75
  admin: import("@medusajs/js-sdk").Admin;
@@ -1,12 +1,19 @@
1
1
  import type { StoreCart, StoreCartLineItem } from '@medusajs/types';
2
- import { type AnyCartIdentifierSchema, type AnyCartSchema, type CartFactory, type CartIdentifierSchema, type CartItem, type CartSchema, type CostBreakDown, type Currency, type ItemCostBreakdown, type RequestContext } from '@reactionary/core';
2
+ import { type AnyCartIdentifierSchema, type AnyCartPaginatedSearchResult, type AnyCartSchema, type CartFactory, type CartIdentifierSchema, type CartItem, type CartPaginatedSearchResultSchema, type CartQueryList, type CartSchema, type CartSearchResultItem, type CostBreakDown, type Currency, type ItemCostBreakdown, type RequestContext } from '@reactionary/core';
3
3
  import type * as z from 'zod';
4
- export declare class MedusaCartFactory<TCartSchema extends AnyCartSchema = typeof CartSchema, TCartIdentifierSchema extends AnyCartIdentifierSchema = typeof CartIdentifierSchema> implements CartFactory<TCartSchema, TCartIdentifierSchema> {
4
+ export interface ParseMedusaCartPaginatedSearchResultInput {
5
+ items: StoreCart[];
6
+ totalCount: number;
7
+ }
8
+ export declare class MedusaCartFactory<TCartSchema extends AnyCartSchema = typeof CartSchema, TCartIdentifierSchema extends AnyCartIdentifierSchema = typeof CartIdentifierSchema, TCartPaginatedSearchResult extends AnyCartPaginatedSearchResult = typeof CartPaginatedSearchResultSchema> implements CartFactory<TCartSchema, TCartIdentifierSchema, TCartPaginatedSearchResult> {
5
9
  readonly cartSchema: TCartSchema;
6
10
  readonly cartIdentifierSchema: TCartIdentifierSchema;
7
- constructor(cartSchema: TCartSchema, cartIdentifierSchema: TCartIdentifierSchema);
11
+ readonly cartPaginatedSearchResultSchema: TCartPaginatedSearchResult;
12
+ constructor(cartSchema: TCartSchema, cartIdentifierSchema: TCartIdentifierSchema, cartPaginatedSearchResultSchema: TCartPaginatedSearchResult);
13
+ parseCartPaginatedSearchResult(_context: RequestContext, data: ParseMedusaCartPaginatedSearchResultInput, _query: CartQueryList): z.output<TCartPaginatedSearchResult>;
14
+ parseCartSearchResultItem(_context: RequestContext, data: StoreCart): CartSearchResultItem;
8
15
  parseCart(context: RequestContext, data: StoreCart): z.output<TCartSchema>;
9
- parseCartIdentifier(_context: RequestContext, data: unknown): z.output<TCartIdentifierSchema>;
16
+ parseCartIdentifier(_context: RequestContext, data: StoreCart): z.output<TCartIdentifierSchema>;
10
17
  /**
11
18
  * Extension point to control the parsing of a single cart item price
12
19
  * @param remoteItem
@@ -1,3 +1,4 @@
1
+ import { type InferType } from '@reactionary/core';
1
2
  import * as z from 'zod';
2
3
  export declare const MedusaCartIdentifierSchema: z.ZodObject<{
3
4
  key: z.ZodString;
@@ -13,7 +14,14 @@ export declare const MedusaRegionSchema: z.ZodObject<{
13
14
  currency_code: z.ZodString;
14
15
  }, z.core.$loose>;
15
16
  export declare const MedusaSessionSchema: z.ZodObject<{
16
- activeCartId: z.ZodOptional<z.ZodString>;
17
+ activeCartId: z.ZodOptional<z.ZodObject<{
18
+ key: z.ZodString;
19
+ region_id: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$loose>>;
21
+ allOwnedCarts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
22
+ key: z.ZodString;
23
+ region_id: z.ZodOptional<z.ZodString>;
24
+ }, z.core.$loose>>>>;
17
25
  token: z.ZodOptional<z.ZodString>;
18
26
  expires: z.ZodOptional<z.ZodString>;
19
27
  allRegions: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -27,7 +35,7 @@ export declare const MedusaSessionSchema: z.ZodObject<{
27
35
  currency_code: z.ZodString;
28
36
  }, z.core.$loose>>;
29
37
  }, z.core.$loose>;
30
- export type MedusaCartIdentifier = z.infer<typeof MedusaCartIdentifierSchema>;
38
+ export type MedusaCartIdentifier = InferType<typeof MedusaCartIdentifierSchema>;
31
39
  export type MedusaOrderIdentifier = z.infer<typeof MedusaOrderIdentifierSchema>;
32
40
  export type MedusaSession = z.infer<typeof MedusaSessionSchema>;
33
41
  export type MedusaRegion = z.infer<typeof MedusaRegionSchema>;