@medusajs/cart 0.0.4-snapshot-20240607093839 → 0.0.4-snapshot-20240701122250

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { moduleDefinition } from "./module-definition";
1
+ import { ModuleExports } from "@medusajs/types";
2
+ export declare const moduleDefinition: ModuleExports;
2
3
  export default moduleDefinition;
package/dist/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const module_definition_1 = require("./module-definition");
4
- exports.default = module_definition_1.moduleDefinition;
3
+ exports.moduleDefinition = void 0;
4
+ const services_1 = require("./services");
5
+ const service = services_1.CartModuleService;
6
+ exports.moduleDefinition = {
7
+ service,
8
+ };
9
+ exports.default = exports.moduleDefinition;
@@ -1,14 +1,3 @@
1
- import { ModuleJoinerConfig } from "@medusajs/types";
2
1
  import { MapToConfig } from "@medusajs/utils";
3
- export declare const LinkableKeys: {
4
- cart_id: string;
5
- line_item_id: string;
6
- shipping_method_id: string;
7
- address_id: string;
8
- line_item_adjustment_id: string;
9
- shipping_method_adjustment_id: string;
10
- line_item_tax_line_id: string;
11
- shipping_method_tax_line_id: string;
12
- };
2
+ export declare const joinerConfig: Omit<import("@medusajs/types").ModuleJoinerConfig, "serviceName" | "primaryKeys" | "alias" | "linkableKeys"> & Required<Pick<import("@medusajs/types").ModuleJoinerConfig, "serviceName" | "primaryKeys" | "alias" | "linkableKeys">>;
13
3
  export declare const entityNameToLinkableKeysMap: MapToConfig;
14
- export declare const joinerConfig: ModuleJoinerConfig;
@@ -1,86 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
4
- const modules_sdk_1 = require("@medusajs/modules-sdk");
5
- const _models_1 = require("./models");
6
- exports.LinkableKeys = {
7
- cart_id: _models_1.Cart.name,
8
- line_item_id: _models_1.LineItem.name,
9
- shipping_method_id: _models_1.ShippingMethod.name,
10
- address_id: _models_1.Address.name,
11
- line_item_adjustment_id: _models_1.LineItemAdjustment.name,
12
- shipping_method_adjustment_id: _models_1.ShippingMethodAdjustment.name,
13
- line_item_tax_line_id: _models_1.LineItemTaxLine.name,
14
- shipping_method_tax_line_id: _models_1.ShippingMethodTaxLine.name,
15
- };
16
- const entityLinkableKeysMap = {};
17
- Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
18
- entityLinkableKeysMap[value] ??= [];
19
- entityLinkableKeysMap[value].push({
20
- mapTo: key,
21
- valueFrom: key.split("_").pop(),
22
- });
23
- });
24
- exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
25
- exports.joinerConfig = {
26
- serviceName: modules_sdk_1.Modules.CART,
27
- primaryKeys: ["id"],
28
- linkableKeys: exports.LinkableKeys,
29
- alias: [
30
- {
31
- name: ["cart", "carts"],
32
- args: {
33
- entity: _models_1.Cart.name,
34
- },
35
- },
36
- {
37
- name: ["line_item", "line_items"],
38
- args: {
39
- entity: _models_1.LineItem.name,
40
- methodSuffix: "LineItems",
41
- },
42
- },
43
- {
44
- name: ["shipping_method", "shipping_methods"],
45
- args: {
46
- entity: _models_1.ShippingMethod.name,
47
- methodSuffix: "ShippingMethods",
48
- },
49
- },
50
- {
51
- name: ["address", "addresses"],
52
- args: {
53
- entity: _models_1.Address.name,
54
- methodSuffix: "Addresses",
55
- },
56
- },
57
- {
58
- name: ["line_item_adjustment", "line_item_adjustments"],
59
- args: {
60
- entity: _models_1.LineItemAdjustment.name,
61
- methodSuffix: "LineItemAdjustments",
62
- },
63
- },
64
- {
65
- name: ["shipping_method_adjustment", "shipping_method_adjustments"],
66
- args: {
67
- entity: _models_1.ShippingMethodAdjustment.name,
68
- methodSuffix: "ShippingMethodAdjustments",
69
- },
70
- },
71
- {
72
- name: ["line_item_tax_line", "line_item_tax_lines"],
73
- args: {
74
- entity: _models_1.LineItemTaxLine.name,
75
- methodSuffix: "LineItemTaxLines",
76
- },
77
- },
78
- {
79
- name: ["shipping_method_tax_line", "shipping_method_tax_lines"],
80
- args: {
81
- entity: _models_1.ShippingMethodTaxLine.name,
82
- methodSuffix: "ShippingMethodTaxLines",
83
- },
84
- },
85
- ],
86
- };
3
+ exports.entityNameToLinkableKeysMap = exports.joinerConfig = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ exports.joinerConfig = (0, utils_1.defineJoinerConfig)(utils_1.Modules.CART);
6
+ exports.entityNameToLinkableKeysMap = (0, utils_1.buildEntitiesNameToLinkableKeysMap)(exports.joinerConfig.linkableKeys);
@@ -1,5 +1,5 @@
1
1
  import { DAL } from "@medusajs/types";
2
- import { Collection, OptionalProps } from "@mikro-orm/core";
2
+ import { Collection, OptionalProps, Rel } from "@mikro-orm/core";
3
3
  import Address from "./address";
4
4
  import LineItem from "./line-item";
5
5
  import ShippingMethod from "./shipping-method";
@@ -13,9 +13,9 @@ export default class Cart {
13
13
  email: string | null;
14
14
  currency_code: string;
15
15
  shipping_address_id: string | null;
16
- shipping_address: Address | null;
16
+ shipping_address: Rel<Address> | null;
17
17
  billing_address_id: string | null;
18
- billing_address: Address | null;
18
+ billing_address: Rel<Address> | null;
19
19
  metadata: Record<string, unknown> | null;
20
20
  items: Collection<LineItem, object>;
21
21
  shipping_methods: Collection<ShippingMethod, object>;
@@ -1,7 +1,8 @@
1
+ import { Rel } from "@mikro-orm/core";
1
2
  import AdjustmentLine from "./adjustment-line";
2
3
  import LineItem from "./line-item";
3
4
  export default class LineItemAdjustment extends AdjustmentLine {
4
- item: LineItem;
5
+ item: Rel<LineItem>;
5
6
  item_id: string;
6
7
  promotion_id: string | null;
7
8
  deleted_at: Date | null;
@@ -48,7 +48,7 @@ let LineItemAdjustment = class LineItemAdjustment extends adjustment_line_1.defa
48
48
  };
49
49
  __decorate([
50
50
  (0, core_1.ManyToOne)({ entity: () => line_item_1.default, persist: false }),
51
- __metadata("design:type", line_item_1.default)
51
+ __metadata("design:type", Object)
52
52
  ], LineItemAdjustment.prototype, "item", void 0);
53
53
  __decorate([
54
54
  LineItemIdIndex(),
@@ -1,7 +1,8 @@
1
+ import { Rel } from "@mikro-orm/core";
1
2
  import LineItem from "./line-item";
2
3
  import TaxLine from "./tax-line";
3
4
  export default class LineItemTaxLine extends TaxLine {
4
- item: LineItem;
5
+ item: Rel<LineItem>;
5
6
  item_id: string;
6
7
  tax_rate_id: string | null;
7
8
  deleted_at: Date | null;
@@ -48,7 +48,7 @@ let LineItemTaxLine = class LineItemTaxLine extends tax_line_1.default {
48
48
  };
49
49
  __decorate([
50
50
  (0, core_1.ManyToOne)({ entity: () => line_item_1.default, persist: false }),
51
- __metadata("design:type", line_item_1.default)
51
+ __metadata("design:type", Object)
52
52
  ], LineItemTaxLine.prototype, "item", void 0);
53
53
  __decorate([
54
54
  LineItemIdIndex(),
@@ -1,6 +1,6 @@
1
1
  import { BigNumberRawValue, DAL } from "@medusajs/types";
2
2
  import { BigNumber } from "@medusajs/utils";
3
- import { Collection, OptionalProps } from "@mikro-orm/core";
3
+ import { Collection, OptionalProps, Rel } from "@mikro-orm/core";
4
4
  import Cart from "./cart";
5
5
  import LineItemAdjustment from "./line-item-adjustment";
6
6
  import LineItemTaxLine from "./line-item-tax-line";
@@ -9,7 +9,7 @@ export default class LineItem {
9
9
  [OptionalProps]?: OptionalLineItemProps;
10
10
  id: string;
11
11
  cart_id: string;
12
- cart: Cart;
12
+ cart: Rel<Cart>;
13
13
  title: string;
14
14
  subtitle: string | null;
15
15
  thumbnail: string | null;
@@ -89,7 +89,7 @@ __decorate([
89
89
  ], LineItem.prototype, "cart_id", void 0);
90
90
  __decorate([
91
91
  (0, core_1.ManyToOne)({ entity: () => cart_1.default, persist: false }),
92
- __metadata("design:type", cart_1.default)
92
+ __metadata("design:type", Object)
93
93
  ], LineItem.prototype, "cart", void 0);
94
94
  __decorate([
95
95
  (0, core_1.Property)({ columnType: "text" }),
@@ -159,15 +159,15 @@ __decorate([
159
159
  ], LineItem.prototype, "variant_option_values", void 0);
160
160
  __decorate([
161
161
  (0, core_1.Property)({ columnType: "boolean" }),
162
- __metadata("design:type", Object)
162
+ __metadata("design:type", Boolean)
163
163
  ], LineItem.prototype, "requires_shipping", void 0);
164
164
  __decorate([
165
165
  (0, core_1.Property)({ columnType: "boolean" }),
166
- __metadata("design:type", Object)
166
+ __metadata("design:type", Boolean)
167
167
  ], LineItem.prototype, "is_discountable", void 0);
168
168
  __decorate([
169
169
  (0, core_1.Property)({ columnType: "boolean" }),
170
- __metadata("design:type", Object)
170
+ __metadata("design:type", Boolean)
171
171
  ], LineItem.prototype, "is_tax_inclusive", void 0);
172
172
  __decorate([
173
173
  (0, utils_1.MikroOrmBigNumberProperty)({ nullable: true }),
@@ -1,7 +1,8 @@
1
+ import { Rel } from "@mikro-orm/core";
1
2
  import AdjustmentLine from "./adjustment-line";
2
3
  import ShippingMethod from "./shipping-method";
3
4
  export default class ShippingMethodAdjustment extends AdjustmentLine {
4
- shipping_method: ShippingMethod;
5
+ shipping_method: Rel<ShippingMethod>;
5
6
  shipping_method_id: string;
6
7
  promotion_id: string | null;
7
8
  deleted_at: Date | null;
@@ -48,7 +48,7 @@ let ShippingMethodAdjustment = class ShippingMethodAdjustment extends adjustment
48
48
  };
49
49
  __decorate([
50
50
  (0, core_1.ManyToOne)({ entity: () => shipping_method_1.default, persist: false }),
51
- __metadata("design:type", shipping_method_1.default)
51
+ __metadata("design:type", Object)
52
52
  ], ShippingMethodAdjustment.prototype, "shipping_method", void 0);
53
53
  __decorate([
54
54
  ShippingMethodIdIndex(),
@@ -1,7 +1,8 @@
1
+ import { Rel } from "@mikro-orm/core";
1
2
  import ShippingMethod from "./shipping-method";
2
3
  import TaxLine from "./tax-line";
3
4
  export default class ShippingMethodTaxLine extends TaxLine {
4
- shipping_method: ShippingMethod;
5
+ shipping_method: Rel<ShippingMethod>;
5
6
  shipping_method_id: string;
6
7
  tax_rate_id: string | null;
7
8
  deleted_at: Date | null;
@@ -48,7 +48,7 @@ let ShippingMethodTaxLine = class ShippingMethodTaxLine extends tax_line_1.defau
48
48
  };
49
49
  __decorate([
50
50
  (0, core_1.ManyToOne)({ entity: () => shipping_method_1.default, persist: false }),
51
- __metadata("design:type", shipping_method_1.default)
51
+ __metadata("design:type", Object)
52
52
  ], ShippingMethodTaxLine.prototype, "shipping_method", void 0);
53
53
  __decorate([
54
54
  ShippingMethodIdIndex(),
@@ -1,6 +1,6 @@
1
1
  import { BigNumberRawValue, DAL } from "@medusajs/types";
2
2
  import { BigNumber } from "@medusajs/utils";
3
- import { Collection, OptionalProps } from "@mikro-orm/core";
3
+ import { Collection, OptionalProps, Rel } from "@mikro-orm/core";
4
4
  import Cart from "./cart";
5
5
  import ShippingMethodAdjustment from "./shipping-method-adjustment";
6
6
  import ShippingMethodTaxLine from "./shipping-method-tax-line";
@@ -9,7 +9,7 @@ export default class ShippingMethod {
9
9
  [OptionalProps]?: OptionalShippingMethodProps;
10
10
  id: string;
11
11
  cart_id: string;
12
- cart: Cart;
12
+ cart: Rel<Cart>;
13
13
  name: string;
14
14
  description: string | null;
15
15
  amount: BigNumber | number;
@@ -68,7 +68,7 @@ __decorate([
68
68
  ], ShippingMethod.prototype, "cart_id", void 0);
69
69
  __decorate([
70
70
  (0, core_1.ManyToOne)({ entity: () => cart_1.default, persist: false }),
71
- __metadata("design:type", cart_1.default)
71
+ __metadata("design:type", Object)
72
72
  ], ShippingMethod.prototype, "cart", void 0);
73
73
  __decorate([
74
74
  (0, core_1.Property)({ columnType: "text" }),
@@ -88,7 +88,7 @@ __decorate([
88
88
  ], ShippingMethod.prototype, "raw_amount", void 0);
89
89
  __decorate([
90
90
  (0, core_1.Property)({ columnType: "boolean" }),
91
- __metadata("design:type", Object)
91
+ __metadata("design:type", Boolean)
92
92
  ], ShippingMethod.prototype, "is_tax_inclusive", void 0);
93
93
  __decorate([
94
94
  ShippingOptionIdIndex(),
@@ -4,16 +4,19 @@ import { Address, Cart, LineItem, LineItemAdjustment, LineItemTaxLine, ShippingM
4
4
  import { CreateLineItemDTO } from "../types";
5
5
  type InjectedDependencies = {
6
6
  baseRepository: DAL.RepositoryService;
7
- cartService: ModulesSdkTypes.InternalModuleService<any>;
8
- addressService: ModulesSdkTypes.InternalModuleService<any>;
9
- lineItemService: ModulesSdkTypes.InternalModuleService<any>;
10
- shippingMethodAdjustmentService: ModulesSdkTypes.InternalModuleService<any>;
11
- shippingMethodService: ModulesSdkTypes.InternalModuleService<any>;
12
- lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService<any>;
13
- lineItemTaxLineService: ModulesSdkTypes.InternalModuleService<any>;
14
- shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService<any>;
7
+ cartService: ModulesSdkTypes.IMedusaInternalService<any>;
8
+ addressService: ModulesSdkTypes.IMedusaInternalService<any>;
9
+ lineItemService: ModulesSdkTypes.IMedusaInternalService<any>;
10
+ shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>;
11
+ shippingMethodService: ModulesSdkTypes.IMedusaInternalService<any>;
12
+ lineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any>;
13
+ lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>;
14
+ shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService<any>;
15
15
  };
16
- declare const CartModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, CartDTO, {
16
+ declare const CartModuleService_base: new (...args: any[]) => ModulesSdkUtils.AbstractModuleService<{
17
+ Cart: {
18
+ dto: CartTypes.CartDTO;
19
+ };
17
20
  Address: {
18
21
  dto: CartTypes.CartAddressDTO;
19
22
  };
@@ -36,31 +39,31 @@ declare const CartModuleService_base: new (container: InjectedDependencies) => M
36
39
  dto: CartTypes.ShippingMethodTaxLineDTO;
37
40
  };
38
41
  }>;
39
- export default class CartModuleService<TCart extends Cart = Cart, TAddress extends Address = Address, TLineItem extends LineItem = LineItem, TLineItemAdjustment extends LineItemAdjustment = LineItemAdjustment, TLineItemTaxLine extends LineItemTaxLine = LineItemTaxLine, TShippingMethodAdjustment extends ShippingMethodAdjustment = ShippingMethodAdjustment, TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine, TShippingMethod extends ShippingMethod = ShippingMethod> extends CartModuleService_base implements ICartModuleService {
42
+ export default class CartModuleService extends CartModuleService_base implements ICartModuleService {
40
43
  protected readonly moduleDeclaration: InternalModuleDeclaration;
41
44
  protected baseRepository_: DAL.RepositoryService;
42
- protected cartService_: ModulesSdkTypes.InternalModuleService<TCart>;
43
- protected addressService_: ModulesSdkTypes.InternalModuleService<TAddress>;
44
- protected lineItemService_: ModulesSdkTypes.InternalModuleService<TLineItem>;
45
- protected shippingMethodAdjustmentService_: ModulesSdkTypes.InternalModuleService<TShippingMethodAdjustment>;
46
- protected shippingMethodService_: ModulesSdkTypes.InternalModuleService<TShippingMethod>;
47
- protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService<TLineItemAdjustment>;
48
- protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService<TLineItemTaxLine>;
49
- protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService<TShippingMethodTaxLine>;
45
+ protected cartService_: ModulesSdkTypes.IMedusaInternalService<Cart>;
46
+ protected addressService_: ModulesSdkTypes.IMedusaInternalService<Address>;
47
+ protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<LineItem>;
48
+ protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethodAdjustment>;
49
+ protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethod>;
50
+ protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<LineItemAdjustment>;
51
+ protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<LineItemTaxLine>;
52
+ protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethodTaxLine>;
50
53
  constructor({ baseRepository, cartService, addressService, lineItemService, shippingMethodAdjustmentService, shippingMethodService, lineItemAdjustmentService, shippingMethodTaxLineService, lineItemTaxLineService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
51
54
  __joinerConfig(): ModuleJoinerConfig;
52
55
  private shouldIncludeTotals;
53
56
  private addRelationsToCalculateTotals;
54
- retrieve(id: string, config?: FindConfig<any> | undefined, sharedContext?: Context | undefined): Promise<CartDTO>;
55
- list(filters?: any, config?: FindConfig<any> | undefined, sharedContext?: Context | undefined): Promise<CartDTO[]>;
56
- listAndCount(filters?: any, config?: FindConfig<any> | undefined, sharedContext?: Context | undefined): Promise<[CartDTO[], number]>;
57
- create(data: CartTypes.CreateCartDTO[], sharedContext?: Context): Promise<CartTypes.CartDTO[]>;
58
- create(data: CartTypes.CreateCartDTO, sharedContext?: Context): Promise<CartTypes.CartDTO>;
59
- protected create_(data: CartTypes.CreateCartDTO[], sharedContext?: Context): Promise<Cart[]>;
60
- update(data: CartTypes.UpdateCartDTO[]): Promise<CartTypes.CartDTO[]>;
61
- update(cartId: string, data: CartTypes.UpdateCartDataDTO, sharedContext?: Context): Promise<CartTypes.CartDTO>;
62
- update(selector: Partial<CartTypes.CartDTO>, data: CartTypes.UpdateCartDataDTO, sharedContext?: Context): Promise<CartTypes.CartDTO[]>;
63
- protected update_(dataOrIdOrSelector: CartTypes.UpdateCartDTO[] | string | Partial<CartTypes.CartDTO>, data?: CartTypes.UpdateCartDataDTO, sharedContext?: Context): Promise<TCart[]>;
57
+ retrieveCart(id: string, config?: FindConfig<any> | undefined, sharedContext?: Context | undefined): Promise<CartDTO>;
58
+ listCarts(filters?: any, config?: FindConfig<any> | undefined, sharedContext?: Context | undefined): Promise<CartDTO[]>;
59
+ listAndCountCarts(filters?: any, config?: FindConfig<any> | undefined, sharedContext?: Context | undefined): Promise<[CartDTO[], number]>;
60
+ createCarts(data: CartTypes.CreateCartDTO[], sharedContext?: Context): Promise<CartTypes.CartDTO[]>;
61
+ createCarts(data: CartTypes.CreateCartDTO, sharedContext?: Context): Promise<CartTypes.CartDTO>;
62
+ protected createCarts_(data: CartTypes.CreateCartDTO[], sharedContext?: Context): Promise<Cart[]>;
63
+ updateCarts(data: CartTypes.UpdateCartDTO[]): Promise<CartTypes.CartDTO[]>;
64
+ updateCarts(cartId: string, data: CartTypes.UpdateCartDataDTO, sharedContext?: Context): Promise<CartTypes.CartDTO>;
65
+ updateCarts(selector: Partial<CartTypes.CartDTO>, data: CartTypes.UpdateCartDataDTO, sharedContext?: Context): Promise<CartTypes.CartDTO[]>;
66
+ protected updateCarts_(dataOrIdOrSelector: CartTypes.UpdateCartDTO[] | string | Partial<CartTypes.CartDTO>, data?: CartTypes.UpdateCartDataDTO, sharedContext?: Context): Promise<Cart[]>;
64
67
  addLineItems(data: CartTypes.CreateLineItemForCartDTO): Promise<CartTypes.CartLineItemDTO[]>;
65
68
  addLineItems(data: CartTypes.CreateLineItemForCartDTO[]): Promise<CartTypes.CartLineItemDTO[]>;
66
69
  addLineItems(cartId: string, items: CartTypes.CreateLineItemDTO[], sharedContext?: Context): Promise<CartTypes.CartLineItemDTO[]>;
@@ -73,10 +76,10 @@ export default class CartModuleService<TCart extends Cart = Cart, TAddress exten
73
76
  protected updateLineItemsWithSelector_(updates: CartTypes.UpdateLineItemWithSelectorDTO[], sharedContext?: Context): Promise<LineItem[]>;
74
77
  createAddresses(data: CartTypes.CreateAddressDTO, sharedContext?: Context): Promise<CartTypes.CartAddressDTO>;
75
78
  createAddresses(data: CartTypes.CreateAddressDTO[], sharedContext?: Context): Promise<CartTypes.CartAddressDTO[]>;
76
- protected createAddresses_(data: CartTypes.CreateAddressDTO[], sharedContext?: Context): Promise<TAddress[]>;
79
+ protected createAddresses_(data: CartTypes.CreateAddressDTO[], sharedContext?: Context): Promise<Address[]>;
77
80
  updateAddresses(data: CartTypes.UpdateAddressDTO, sharedContext?: Context): Promise<CartTypes.CartAddressDTO>;
78
81
  updateAddresses(data: CartTypes.UpdateAddressDTO[], sharedContext?: Context): Promise<CartTypes.CartAddressDTO[]>;
79
- protected updateAddresses_(data: CartTypes.UpdateAddressDTO[], sharedContext?: Context): Promise<TAddress[]>;
82
+ protected updateAddresses_(data: CartTypes.UpdateAddressDTO[], sharedContext?: Context): Promise<Address[]>;
80
83
  addShippingMethods(data: CartTypes.CreateShippingMethodDTO): Promise<CartTypes.CartShippingMethodDTO>;
81
84
  addShippingMethods(data: CartTypes.CreateShippingMethodDTO[]): Promise<CartTypes.CartShippingMethodDTO[]>;
82
85
  addShippingMethods(cartId: string, methods: CartTypes.CreateShippingMethodForSingleCartDTO[], sharedContext?: Context): Promise<CartTypes.CartShippingMethodDTO[]>;
@@ -16,16 +16,17 @@ const types_1 = require("@medusajs/types");
16
16
  const utils_1 = require("@medusajs/utils");
17
17
  const _models_1 = require("../models");
18
18
  const joiner_config_1 = require("../joiner-config");
19
- const generateMethodForModels = [
20
- _models_1.Address,
21
- _models_1.LineItem,
22
- _models_1.LineItemAdjustment,
23
- _models_1.LineItemTaxLine,
24
- _models_1.ShippingMethod,
25
- _models_1.ShippingMethodAdjustment,
26
- _models_1.ShippingMethodTaxLine,
27
- ];
28
- class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Cart, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
19
+ const generateMethodForModels = {
20
+ Cart: _models_1.Cart,
21
+ Address: _models_1.Address,
22
+ LineItem: _models_1.LineItem,
23
+ LineItemAdjustment: _models_1.LineItemAdjustment,
24
+ LineItemTaxLine: _models_1.LineItemTaxLine,
25
+ ShippingMethod: _models_1.ShippingMethod,
26
+ ShippingMethodAdjustment: _models_1.ShippingMethodAdjustment,
27
+ ShippingMethodTaxLine: _models_1.ShippingMethodTaxLine,
28
+ };
29
+ class CartModuleService extends utils_1.ModulesSdkUtils.MedusaService(generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
29
30
  constructor({ baseRepository, cartService, addressService, lineItemService, shippingMethodAdjustmentService, shippingMethodService, lineItemAdjustmentService, shippingMethodTaxLineService, lineItemTaxLineService, }, moduleDeclaration) {
30
31
  // @ts-ignore
31
32
  super(...arguments);
@@ -90,19 +91,21 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
90
91
  return (!requiredFieldsForTotals.some((val) => val.startsWith(field)) && !totalFields.includes(field));
91
92
  });
92
93
  }
93
- async retrieve(id, config, sharedContext) {
94
+ // @ts-expect-error
95
+ async retrieveCart(id, config, sharedContext) {
94
96
  config ??= {};
95
97
  const includeTotals = this.shouldIncludeTotals(config);
96
- const cart = await super.retrieve(id, config, sharedContext);
98
+ const cart = await super.retrieveCart(id, config, sharedContext);
97
99
  if (includeTotals) {
98
100
  (0, utils_1.createRawPropertiesFromBigNumber)((0, utils_1.decorateCartTotals)(cart));
99
101
  }
100
102
  return cart;
101
103
  }
102
- async list(filters, config, sharedContext) {
104
+ // @ts-expect-error
105
+ async listCarts(filters, config, sharedContext) {
103
106
  config ??= {};
104
107
  const includeTotals = this.shouldIncludeTotals(config);
105
- const carts = await super.list(filters, config, sharedContext);
108
+ const carts = await super.listCarts(filters, config, sharedContext);
106
109
  if (includeTotals) {
107
110
  carts.forEach((cart) => {
108
111
  (0, utils_1.createRawPropertiesFromBigNumber)((0, utils_1.decorateCartTotals)(cart));
@@ -110,10 +113,11 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
110
113
  }
111
114
  return carts;
112
115
  }
113
- async listAndCount(filters, config, sharedContext) {
116
+ // @ts-expect-error
117
+ async listAndCountCarts(filters, config, sharedContext) {
114
118
  config ??= {};
115
119
  const includeTotals = this.shouldIncludeTotals(config);
116
- const [carts, count] = await super.listAndCount(filters, config, sharedContext);
120
+ const [carts, count] = await super.listAndCountCarts(filters, config, sharedContext);
117
121
  if (includeTotals) {
118
122
  carts.forEach((cart) => {
119
123
  (0, utils_1.createRawPropertiesFromBigNumber)((0, utils_1.decorateCartTotals)(cart));
@@ -121,15 +125,15 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
121
125
  }
122
126
  return [carts, count];
123
127
  }
124
- async create(data, sharedContext = {}) {
128
+ async createCarts(data, sharedContext = {}) {
125
129
  const input = Array.isArray(data) ? data : [data];
126
- const carts = await this.create_(input, sharedContext);
127
- const result = await this.list({ id: carts.map((p) => p.id) }, {
130
+ const carts = await this.createCarts_(input, sharedContext);
131
+ const result = await this.listCarts({ id: carts.map((p) => p.id) }, {
128
132
  relations: ["shipping_address", "billing_address"],
129
133
  }, sharedContext);
130
134
  return (Array.isArray(data) ? result : result[0]);
131
135
  }
132
- async create_(data, sharedContext = {}) {
136
+ async createCarts_(data, sharedContext = {}) {
133
137
  const lineItemsToCreate = [];
134
138
  const createdCarts = [];
135
139
  for (const { items, ...cart } of data) {
@@ -150,14 +154,14 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
150
154
  }
151
155
  return createdCarts;
152
156
  }
153
- async update(dataOrIdOrSelector, data, sharedContext = {}) {
154
- const result = await this.update_(dataOrIdOrSelector, data, sharedContext);
157
+ async updateCarts(dataOrIdOrSelector, data, sharedContext = {}) {
158
+ const result = await this.updateCarts_(dataOrIdOrSelector, data, sharedContext);
155
159
  const serializedResult = await this.baseRepository_.serialize(result, {
156
160
  populate: true,
157
161
  });
158
162
  return (0, utils_1.isString)(dataOrIdOrSelector) ? serializedResult[0] : serializedResult;
159
163
  }
160
- async update_(dataOrIdOrSelector, data, sharedContext = {}) {
164
+ async updateCarts_(dataOrIdOrSelector, data, sharedContext = {}) {
161
165
  let toUpdate = [];
162
166
  if ((0, utils_1.isString)(dataOrIdOrSelector)) {
163
167
  toUpdate = [
@@ -196,7 +200,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
196
200
  });
197
201
  }
198
202
  async addLineItems_(cartId, items, sharedContext = {}) {
199
- const cart = await this.retrieve(cartId, { select: ["id"] }, sharedContext);
203
+ const cart = await this.retrieveCart(cartId, { select: ["id"] }, sharedContext);
200
204
  const toUpdate = items.map((item) => {
201
205
  return {
202
206
  ...item,
@@ -276,7 +280,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
276
280
  return await this.baseRepository_.serialize(methods, { populate: true });
277
281
  }
278
282
  async addShippingMethods_(cartId, data, sharedContext = {}) {
279
- const cart = await this.retrieve(cartId, { select: ["id"] }, sharedContext);
283
+ const cart = await this.retrieveCart(cartId, { select: ["id"] }, sharedContext);
280
284
  const methods = data.map((method) => {
281
285
  return {
282
286
  ...method,
@@ -291,7 +295,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
291
295
  async addLineItemAdjustments(cartIdOrData, adjustments, sharedContext = {}) {
292
296
  let addedAdjustments = [];
293
297
  if ((0, utils_1.isString)(cartIdOrData)) {
294
- const cart = await this.retrieve(cartIdOrData, { select: ["id"], relations: ["items"] }, sharedContext);
298
+ const cart = await this.retrieveCart(cartIdOrData, { select: ["id"], relations: ["items"] }, sharedContext);
295
299
  const lineIds = cart.items?.map((item) => item.id);
296
300
  for (const adj of adjustments || []) {
297
301
  if (!lineIds?.includes(adj.item_id)) {
@@ -309,7 +313,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
309
313
  });
310
314
  }
311
315
  async setLineItemAdjustments(cartId, adjustments, sharedContext = {}) {
312
- const cart = await this.retrieve(cartId, { select: ["id"], relations: ["items.adjustments"] }, sharedContext);
316
+ const cart = await this.retrieveCart(cartId, { select: ["id"], relations: ["items.adjustments"] }, sharedContext);
313
317
  const existingAdjustments = await this.listLineItemAdjustments({ item: { cart_id: cart.id } }, { select: ["id"] }, sharedContext);
314
318
  const adjustmentsSet = new Set(adjustments
315
319
  .map((a) => a.id)
@@ -330,7 +334,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
330
334
  });
331
335
  }
332
336
  async setShippingMethodAdjustments(cartId, adjustments, sharedContext = {}) {
333
- const cart = await this.retrieve(cartId, { select: ["id"], relations: ["shipping_methods.adjustments"] }, sharedContext);
337
+ const cart = await this.retrieveCart(cartId, { select: ["id"], relations: ["shipping_methods.adjustments"] }, sharedContext);
334
338
  const existingAdjustments = await this.listShippingMethodAdjustments({ shipping_method: { cart_id: cart.id } }, { select: ["id"] }, sharedContext);
335
339
  const adjustmentsSet = new Set(adjustments
336
340
  .map((a) => a?.id)
@@ -353,7 +357,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
353
357
  async addShippingMethodAdjustments(cartIdOrData, adjustments, sharedContext = {}) {
354
358
  let addedAdjustments = [];
355
359
  if ((0, utils_1.isString)(cartIdOrData)) {
356
- const cart = await this.retrieve(cartIdOrData, { select: ["id"], relations: ["shipping_methods"] }, sharedContext);
360
+ const cart = await this.retrieveCart(cartIdOrData, { select: ["id"], relations: ["shipping_methods"] }, sharedContext);
357
361
  const methodIds = cart.shipping_methods?.map((method) => method.id);
358
362
  for (const adj of adjustments || []) {
359
363
  if (!methodIds?.includes(adj.shipping_method_id)) {
@@ -379,7 +383,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
379
383
  let addedTaxLines;
380
384
  if ((0, utils_1.isString)(cartIdOrData)) {
381
385
  // existence check
382
- await this.retrieve(cartIdOrData, { select: ["id"] }, sharedContext);
386
+ await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext);
383
387
  const lines = Array.isArray(taxLines) ? taxLines : [taxLines];
384
388
  addedTaxLines = await this.lineItemTaxLineService_.create(lines, sharedContext);
385
389
  }
@@ -396,7 +400,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
396
400
  return serialized;
397
401
  }
398
402
  async setLineItemTaxLines(cartId, taxLines, sharedContext = {}) {
399
- const cart = await this.retrieve(cartId, { select: ["id"], relations: ["items.tax_lines"] }, sharedContext);
403
+ const cart = await this.retrieveCart(cartId, { select: ["id"], relations: ["items.tax_lines"] }, sharedContext);
400
404
  const existingTaxLines = await this.listLineItemTaxLines({ item: { cart_id: cart.id } }, { select: ["id"] }, sharedContext);
401
405
  const taxLinesSet = new Set(taxLines
402
406
  .map((taxLine) => taxLine?.id)
@@ -420,7 +424,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
420
424
  let addedTaxLines;
421
425
  if ((0, utils_1.isString)(cartIdOrData)) {
422
426
  // existence check
423
- await this.retrieve(cartIdOrData, { select: ["id"] }, sharedContext);
427
+ await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext);
424
428
  const lines = Array.isArray(taxLines) ? taxLines : [taxLines];
425
429
  addedTaxLines = await this.shippingMethodTaxLineService_.create(lines, sharedContext);
426
430
  }
@@ -436,7 +440,7 @@ class CartModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
436
440
  return serialized;
437
441
  }
438
442
  async setShippingMethodTaxLines(cartId, taxLines, sharedContext = {}) {
439
- const cart = await this.retrieve(cartId, { select: ["id"], relations: ["shipping_methods.tax_lines"] }, sharedContext);
443
+ const cart = await this.retrieveCart(cartId, { select: ["id"], relations: ["shipping_methods.tax_lines"] }, sharedContext);
440
444
  const existingTaxLines = await this.listShippingMethodTaxLines({ shipping_method: { cart_id: cart.id } }, { select: ["id"] }, sharedContext);
441
445
  const taxLinesSet = new Set(taxLines
442
446
  .map((taxLine) => taxLine?.id)
@@ -464,28 +468,28 @@ __decorate([
464
468
  __metadata("design:type", Function),
465
469
  __metadata("design:paramtypes", [Object, Object]),
466
470
  __metadata("design:returntype", Promise)
467
- ], CartModuleService.prototype, "create", null);
471
+ ], CartModuleService.prototype, "createCarts", null);
468
472
  __decorate([
469
473
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
470
474
  __param(1, (0, utils_1.MedusaContext)()),
471
475
  __metadata("design:type", Function),
472
476
  __metadata("design:paramtypes", [Array, Object]),
473
477
  __metadata("design:returntype", Promise)
474
- ], CartModuleService.prototype, "create_", null);
478
+ ], CartModuleService.prototype, "createCarts_", null);
475
479
  __decorate([
476
480
  (0, utils_1.InjectManager)("baseRepository_"),
477
481
  __param(2, (0, utils_1.MedusaContext)()),
478
482
  __metadata("design:type", Function),
479
483
  __metadata("design:paramtypes", [Object, Object, Object]),
480
484
  __metadata("design:returntype", Promise)
481
- ], CartModuleService.prototype, "update", null);
485
+ ], CartModuleService.prototype, "updateCarts", null);
482
486
  __decorate([
483
487
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
484
488
  __param(2, (0, utils_1.MedusaContext)()),
485
489
  __metadata("design:type", Function),
486
490
  __metadata("design:paramtypes", [Object, Object, Object]),
487
491
  __metadata("design:returntype", Promise)
488
- ], CartModuleService.prototype, "update_", null);
492
+ ], CartModuleService.prototype, "updateCarts_", null);
489
493
  __decorate([
490
494
  (0, utils_1.InjectManager)("baseRepository_"),
491
495
  __param(2, (0, utils_1.MedusaContext)()),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/cart",
3
- "version": "0.0.4-snapshot-20240607093839",
3
+ "version": "0.0.4-snapshot-20240701122250",
4
4
  "description": "Medusa Cart module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,10 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=16"
12
- },
13
- "bin": {
14
- "medusa-cart-seed": "dist/scripts/bin/run-seed.js"
11
+ "node": ">=20"
15
12
  },
16
13
  "repository": {
17
14
  "type": "git",
@@ -40,17 +37,16 @@
40
37
  "@medusajs/types": "workspace:^",
41
38
  "@mikro-orm/cli": "5.9.7",
42
39
  "cross-env": "^5.2.1",
43
- "jest": "^29.6.3",
44
- "medusa-test-utils": "1.1.45-snapshot-20240607093839",
40
+ "jest": "^29.7.0",
41
+ "medusa-test-utils": "1.1.45-snapshot-20240701122250",
45
42
  "rimraf": "^3.0.2",
46
- "ts-jest": "^29.1.1",
47
43
  "ts-node": "^10.9.1",
48
44
  "tsc-alias": "^1.8.6",
49
45
  "typescript": "^5.1.6"
50
46
  },
51
47
  "dependencies": {
52
- "@medusajs/modules-sdk": "1.13.0-snapshot-20240607093839",
53
- "@medusajs/utils": "1.12.0-snapshot-20240607093839",
48
+ "@medusajs/modules-sdk": "1.13.0-snapshot-20240701122250",
49
+ "@medusajs/utils": "1.12.0-snapshot-20240701122250",
54
50
  "@mikro-orm/core": "5.9.7",
55
51
  "@mikro-orm/migrations": "5.9.7",
56
52
  "@mikro-orm/postgresql": "5.9.7",
@@ -1,2 +0,0 @@
1
- import { ModuleExports } from "@medusajs/types";
2
- export declare const moduleDefinition: ModuleExports;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.moduleDefinition = void 0;
4
- const services_1 = require("./services");
5
- const service = services_1.CartModuleService;
6
- exports.moduleDefinition = {
7
- service,
8
- };
@@ -1 +0,0 @@
1
- export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseRepository = void 0;
4
- var utils_1 = require("@medusajs/utils");
5
- Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- declare const _default: Promise<void>;
3
- export default _default;
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- const os_1 = require("os");
28
- const seed_1 = require("../seed");
29
- const args = process.argv;
30
- const path = args.pop();
31
- exports.default = (async () => {
32
- const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
33
- config();
34
- if (!path) {
35
- throw new Error(`filePath is required.${os_1.EOL}Example: medusa-cart-seed <filePath>`);
36
- }
37
- await (0, seed_1.run)({ path });
38
- })();
@@ -1,4 +0,0 @@
1
- import { LoaderOptions, ModulesSdkTypes } from "@medusajs/types";
2
- export declare function run({ options, logger, path, }: Partial<Pick<LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>, "options" | "logger">> & {
3
- path: string;
4
- }): Promise<void>;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.run = void 0;
27
- const modules_sdk_1 = require("@medusajs/modules-sdk");
28
- const utils_1 = require("@medusajs/utils");
29
- const CartModels = __importStar(require("../models"));
30
- const os_1 = require("os");
31
- const path_1 = require("path");
32
- async function run({ options, logger, path, }) {
33
- logger ??= console;
34
- logger.info(`Loading seed data from ${path}...`);
35
- const { cartData } = await Promise.resolve(`${(0, path_1.resolve)(process.cwd(), path)}`).then(s => __importStar(require(s))).catch((e) => {
36
- logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: cartData.${os_1.EOL}${e}`);
37
- throw e;
38
- });
39
- const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig(modules_sdk_1.Modules.CART, options);
40
- const entities = Object.values(CartModels);
41
- const pathToMigrations = __dirname + "/../migrations";
42
- const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
43
- const manager = orm.em.fork();
44
- try {
45
- logger.info("Seeding cart data..");
46
- // TODO: implement cart seed data
47
- // await createCarts(manager, cartsData)
48
- }
49
- catch (e) {
50
- logger.error(`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${os_1.EOL}${e}`);
51
- }
52
- await orm.close(true);
53
- }
54
- exports.run = run;