From 3507e5e2636ac80256c9cc2ce516afb79a454543 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Fri, 5 Apr 2024 13:02:46 +0300 Subject: [PATCH] chore: updated TSDocs of the Pricing Module (#6894) --- .../types/src/pricing/common/price-list.ts | 4 +- .../types/src/pricing/common/price-set.ts | 10 +- packages/types/src/pricing/service.ts | 2421 +++++------------ 3 files changed, 736 insertions(+), 1699 deletions(-) diff --git a/packages/types/src/pricing/common/price-list.ts b/packages/types/src/pricing/common/price-list.ts index c937c9886b..96b4ce78ca 100644 --- a/packages/types/src/pricing/common/price-list.ts +++ b/packages/types/src/pricing/common/price-list.ts @@ -452,11 +452,11 @@ export interface UpdatePriceListPricesDTO { /** * @interface * - * The rules to add to a price list. + * The rules to set in a price list. */ export interface SetPriceListRulesDTO { /** - * The ID of the price list to add rules to. + * The ID of the price list to set its rules. */ price_list_id: string /** diff --git a/packages/types/src/pricing/common/price-set.ts b/packages/types/src/pricing/common/price-set.ts index e115135df5..26579be235 100644 --- a/packages/types/src/pricing/common/price-set.ts +++ b/packages/types/src/pricing/common/price-set.ts @@ -33,11 +33,12 @@ export interface PricingContext { /** * @interface * - * Filters to apply on prices. + * Filters to apply when calculating prices. */ export interface PricingFilters { /** - * IDs to filter prices. + * IDs of the price sets to use in the + * calculation. */ id: string[] } @@ -282,11 +283,12 @@ export interface CreatePriceSetDTO { /** * @interface * - * The data to upsert in a price set. The `id` is used in the case we are doing an update. + * The data to upsert in a price set. */ export interface UpsertPriceSetDTO extends UpdatePriceSetDTO { /** * A string indicating the ID of the price set to update. + * If not provided, a price set is created. */ id?: string } @@ -294,7 +296,7 @@ export interface UpsertPriceSetDTO extends UpdatePriceSetDTO { /** * @interface * - * The data to update in a price set. The `id` is used to identify which price set to update. + * The data to update in a price set. */ export interface UpdatePriceSetDTO { /** diff --git a/packages/types/src/pricing/service.ts b/packages/types/src/pricing/service.ts index d5767f47b2..4adda14c7c 100644 --- a/packages/types/src/pricing/service.ts +++ b/packages/types/src/pricing/service.ts @@ -33,14 +33,13 @@ import { UpdateRuleTypeDTO, UpsertPriceSetDTO, } from "./common" - import { FindConfig } from "../common" import { RestoreReturn, SoftDeleteReturn } from "../dal" import { IModuleService } from "../modules-sdk" import { Context } from "../shared-context" /** - * The main service interface for the pricing module. + * The main service interface for the Pricing Module. */ export interface IPricingModuleService extends IModuleService { /** @@ -57,69 +56,48 @@ export interface IPricingModuleService extends IModuleService { * When you calculate prices, you must at least specify the currency code: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * async function calculatePrice (priceSetId: string, currencyCode: string) { - * const pricingService = await initializePricingModule() - * - * const price = await pricingService.calculatePrices( - * { id: [priceSetId] }, - * { - * context: { - * currency_code: currencyCode - * } - * } - * ) - * - * // do something with the price or return it - * } + * const price = await pricingModuleService.calculatePrices( + * { + * id: ["pset_123", "pset_321"], + * }, + * { + * context: { + * currency_code: "usd", + * }, + * } + * ) * ``` * * To calculate prices for specific minimum and/or maximum quantity: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * async function calculatePrice (priceSetId: string, currencyCode: string) { - * const pricingService = await initializePricingModule() - * - * const price = await pricingService.calculatePrices( - * { id: [priceSetId] }, - * { - * context: { - * currency_code: currencyCode, - * min_quantity: 4 - * } - * } - * ) - * - * // do something with the price or return it - * } + * const price = await pricingModuleService.calculatePrices( + * { + * id: ["pset_123", "pset_321"], + * }, + * { + * context: { + * currency_code: "usd", + * min_quantity: 4, + * }, + * } + * ) * ``` * * To calculate prices for custom rule types: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * async function calculatePrice (priceSetId: string, currencyCode: string) { - * const pricingService = await initializePricingModule() - * - * const price = await pricingService.calculatePrices( - * { id: [priceSetId] }, - * { - * context: { - * currency_code: currencyCode, - * region_id: "US" - * } - * } - * ) - * - * // do something with the price or return it - * } + * const price = await pricingModuleService.calculatePrices( + * { + * id: ["pset_123", "pset_321"], + * }, + * { + * context: { + * currency_code: "usd", + * region_id: "US", + * }, + * } + * ) * ``` */ calculatePrices( @@ -142,40 +120,19 @@ export interface IPricingModuleService extends IModuleService { * A simple example that retrieves a price set by its ID: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSet = await pricingService.retrieve( - * priceSetId - * ) - * - * // do something with the price set or return it - * } + * const priceSet = + * await pricingModuleService.retrieve("pset_123") * ``` * * To specify relations that should be retrieved: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSet = await pricingService.retrieve( - * priceSetId, - * { - * relations: ["prices"] - * } - * ) - * - * // do something with the price set or return it - * } + * const priceSet = await pricingModuleService.retrieve( + * "pset_123", + * { + * relations: ["prices"], + * } + * ) * ``` */ retrieve( @@ -199,103 +156,37 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of price sets using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.list( - * { - * id: priceSetIds - * }, - * ) - * - * // do something with the price sets or return them - * } + * const priceSets = await pricingModuleService.list({ + * id: ["pset_123", "pset_321"], + * }) * ``` * * To specify relations that should be retrieved within the price sets: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.list( - * { - * id: priceSetIds - * }, - * { - * relations: ["prices"] - * } - * ) - * - * // do something with the price sets or return them - * } + * const priceSets = await pricingModuleService.list( + * { + * id: ["pset_123", "pset_321"], + * }, + * { + * relations: ["prices"], + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.list( - * { - * id: priceSetIds - * }, - * { - * relations: ["prices"], - * skip, - * take - * } - * ) - * - * // do something with the price sets or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[], priceIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.list( - * { - * $and: [ - * { - * id: priceSetIds - * }, - * { - * prices: { - * id: priceIds - * } - * } - * ] - * }, - * { - * relations: ["prices"], - * skip, - * take - * } - * ) - * - * // do something with the price sets or return them - * } + * const priceSets = await pricingModuleService.list( + * { + * id: ["pset_123", "pset_321"], + * }, + * { + * relations: ["prices"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ list( @@ -319,103 +210,40 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of prices sets using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const [priceSets, count] = await pricingService.listAndCount( - * { - * id: priceSetIds - * }, - * ) - * - * // do something with the price sets or return them - * } + * const [priceSets, count] = + * await pricingModuleService.listAndCount({ + * id: ["pset_123", "pset_321"], + * }) * ``` * * To specify relations that should be retrieved within the price sets: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const [priceSets, count] = await pricingService.listAndCount( + * const [priceSets, count] = + * await pricingModuleService.listAndCount( * { - * id: priceSetIds + * id: ["pset_123", "pset_321"], * }, * { - * relations: ["prices"] + * relations: ["prices"], * } * ) - * - * // do something with the price sets or return them - * } * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceSets, count] = await pricingService.listAndCount( + * const [priceSets, count] = + * await pricingModuleService.listAndCount( * { - * id: priceSetIds + * id: ["pset_123", "pset_321"], * }, * { * relations: ["prices"], - * skip, - * take + * take: 20, + * skip: 2, * } * ) - * - * // do something with the price sets or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceSets (priceSetIds: string[], priceIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceSets, count] = await pricingService.listAndCount( - * { - * $and: [ - * { - * id: priceSetIds - * }, - * { - * prices: { - * id: priceIds - * } - * } - * ] - * }, - * { - * relations: ["prices"], - * skip, - * take - * } - * ) - * - * // do something with the price sets or return them - * } * ``` */ listAndCount( @@ -435,88 +263,65 @@ export interface IPricingModuleService extends IModuleService { * To create a default price set, don't pass any rules. For example: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createPriceSet () { - * const pricingService = await initializePricingModule() - * - * const priceSet = await pricingService.create( + * const priceSet = await pricingModuleService.create({ + * rules: [], + * prices: [ * { - * rules: [], - * prices: [ - * { - * amount: 500, - * currency_code: "USD", - * min_quantity: 0, - * max_quantity: 4, - * rules: {}, - * }, - * { - * amount: 400, - * currency_code: "USD", - * min_quantity: 5, - * max_quantity: 10, - * rules: {}, - * }, - * ], + * amount: 500, + * currency_code: "USD", + * min_quantity: 0, + * max_quantity: 4, + * rules: {}, * }, - * ) - * - * // do something with the price set or return it - * } + * { + * amount: 400, + * currency_code: "USD", + * min_quantity: 5, + * max_quantity: 10, + * rules: {}, + * }, + * ], + * }) * ``` * * To create a price set and associate it with rule types: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createPriceSet () { - * const pricingService = await initializePricingModule() - * - * const priceSet = await pricingService.create( + * const priceSet = await pricingModuleService.create({ + * rules: [ + * { rule_attribute: "region_id" }, + * { rule_attribute: "city" }, + * ], + * prices: [ * { - * rules: [{ rule_attribute: "region_id" }, { rule_attribute: "city" }], - * prices: [ - * { - * amount: 300, - * currency_code: "EUR", - * rules: { - * region_id: "PL", - * city: "krakow" - * }, - * }, - * { - * amount: 400, - * currency_code: "EUR", - * rules: { - * region_id: "PL" - * }, - * }, - * { - * amount: 450, - * currency_code: "EUR", - * rules: { - * city: "krakow" - * }, - * } - * ], + * amount: 300, + * currency_code: "EUR", + * rules: { + * region_id: "PL", + * city: "krakow", + * }, * }, - * ) - * - * // do something with the price set or return it - * } + * { + * amount: 400, + * currency_code: "EUR", + * rules: { + * region_id: "PL", + * }, + * }, + * { + * amount: 450, + * currency_code: "EUR", + * rules: { + * city: "krakow", + * }, + * }, + * ], + * }) * ``` */ create(data: CreatePriceSetDTO, sharedContext?: Context): Promise /** - * @overload - * * This method is used to create multiple price sets. * * @param {CreatePriceSetDTO[]} data - The price sets to create. @@ -524,78 +329,59 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The list of created price sets. * * @example - * To create price sets with a default price, don't pass any rules and make sure to pass the `currency_code` of the price. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createPriceSets () { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.create([ - * { - * rules: [], - * prices: [ - * { - * amount: 500, - * currency_code: "USD", - * rules: {}, + * const priceSets = await pricingModuleService.create([ + * // default price set + * { + * rules: [], + * prices: [ + * { + * amount: 500, + * currency_code: "USD", + * min_quantity: 0, + * max_quantity: 4, + * rules: {}, + * }, + * { + * amount: 400, + * currency_code: "USD", + * min_quantity: 5, + * max_quantity: 10, + * rules: {}, + * }, + * ], + * }, + * // price set with rules + * { + * rules: [ + * { rule_attribute: "region_id" }, + * { rule_attribute: "city" }, + * ], + * prices: [ + * { + * amount: 300, + * currency_code: "EUR", + * rules: { + * region_id: "PL", + * city: "krakow", * }, - * ], - * }, - * ]) - * - * // do something with the price sets or return them - * } - * ``` - * - * To create price sets and associate them with rule types: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createPriceSets () { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.create([ - * { - * rules: [{ rule_attribute: "region_id" }, { rule_attribute: "city" }], - * prices: [ - * { - * amount: 300, - * currency_code: "EUR", - * rules: { - * region_id: "PL", - * city: "krakow" - * }, + * }, + * { + * amount: 400, + * currency_code: "EUR", + * rules: { + * region_id: "PL", * }, - * { - * amount: 400, - * currency_code: "EUR", - * min_quantity: 0, - * max_quantity: 4, - * rules: { - * region_id: "PL" - * }, + * }, + * { + * amount: 450, + * currency_code: "EUR", + * rules: { + * city: "krakow", * }, - * { - * amount: 450, - * currency_code: "EUR", - * rules: { - * city: "krakow" - * }, - * } - * ], - * }, - * ]) - * - * // do something with the price sets or return them - * } - * ``` + * }, + * ], + * }, + * ]) */ create( data: CreatePriceSetDTO[], @@ -610,21 +396,20 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The updated and created price sets. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function upsertPriceSet (title: string) { - * const pricingModule = await initializePricingModule() - * - * const createdPriceSets = await pricingModule.upsert([ - * { - * prices: [{amount: 100, currency_code: "USD"}] - * } - * ]) - * - * // do something with the price sets or return them - * } + * const priceSets = await pricingModuleService.upsert([ + * { + * prices: [ + * { + * amount: 100, + * currency_code: "USD", + * }, + * ], + * }, + * { + * id: "pset_123", + * rules: [{ rule_attribute: "region_id" }], + * }, + * ]) */ upsert( data: UpsertPriceSetDTO[], @@ -639,21 +424,10 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The updated or created price set. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function upsertPriceSet (title: string) { - * const pricingModule = await initializePricingModule() - * - * const createdPriceSet = await pricingModule.upsert( - * { - * prices: [{amount: 100, currency_code: "USD"}] - * } - * ) - * - * // do something with the price set or return it - * } + * const priceSet = await pricingModuleService.upsert({ + * id: "pset_123", + * rules: [{ rule_attribute: "region_id" }], + * }) */ upsert(data: UpsertPriceSetDTO, sharedContext?: Context): Promise @@ -666,20 +440,12 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The updated price set. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function updatePriceSet (id: string, title: string) { - * const pricingtModule = await initializePricingModule() - * - * const priceSet = await pricingtModule.update(id, { - * prices: [{amount: 100, currency_code: "USD"}] - * } - * ) - * - * // do something with the price set or return it - * } + * const priceSet = await pricingModuleService.update( + * "pset_123", + * { + * rules: [{ rule_attribute: "region_id" }], + * } + * ) */ update( id: string, @@ -696,20 +462,14 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The updated price sets. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function updatePriceSet(id: string, title: string) { - * const pricingModule = await initializePricingModule() - * - * const priceSets = await pricingModule.update({id}, { - * prices: [{amount: 100, currency_code: "USD"}] - * } - * ) - * - * // do something with the price sets or return them - * } + * const priceSets = await pricingModuleService.update( + * { + * id: ["pset_123", "pset_321"], + * }, + * { + * rules: [{ rule_attribute: "region_id" }], + * } + * ) */ update( selector: FilterablePriceSetProps, @@ -725,20 +485,12 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} Resolves when rules are successfully removed. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function removePriceSetRule (priceSetId: string, ruleAttributes: []) { - * const pricingService = await initializePricingModule() - * - * await pricingService.removeRules([ - * { - * id: priceSetId, - * rules: ruleAttributes - * }, - * ]) - * } + * await pricingModuleService.removeRules([ + * { + * id: "pset_123", + * rules: ["region_id"], + * }, + * ]) */ removeRules( data: RemovePriceSetRulesDTO[], @@ -753,15 +505,7 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} Resolves when the price sets are successfully deleted. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function removePriceSetRule (priceSetIds: string[]) { - * const pricingService = await initializePricingModule() - * - * await pricingService.delete(priceSetIds) - * } + * await pricingModuleService.delete(["pset_123", "pset_321"]) */ delete(ids: string[], sharedContext?: Context): Promise @@ -777,70 +521,50 @@ export interface IPricingModuleService extends IModuleService { * To add a default price to a price set, don't pass it any rules and make sure to pass it the `currency_code`: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function addPricesToPriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSet = await pricingService.addPrices({ - * priceSetId, - * prices: [ - * { - * amount: 500, - * currency_code: "USD", - * rules: {}, - * }, - * ], - * }) - * - * // do something with the price set or return it - * } + * const priceSet = await pricingModuleService.addPrices({ + * priceSetId: "pset_123", + * prices: [ + * { + * amount: 500, + * currency_code: "USD", + * rules: {}, + * }, + * ], + * }) * ``` * * To add prices with rules: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function addPricesToPriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSet = await pricingService.addPrices({ - * priceSetId, - * prices: [ - * { - * amount: 300, - * currency_code: "EUR", - * rules: { - * region_id: "PL", - * city: "krakow" - * }, + * const priceSet = await pricingModuleService.addPrices({ + * priceSetId: "pset_123", + * prices: [ + * { + * amount: 300, + * currency_code: "EUR", + * rules: { + * region_id: "PL", + * city: "krakow", * }, - * { - * amount: 400, - * currency_code: "EUR", - * min_quantity: 0, - * max_quantity: 4, - * rules: { - * region_id: "PL" - * }, + * }, + * { + * amount: 400, + * currency_code: "EUR", + * min_quantity: 0, + * max_quantity: 4, + * rules: { + * region_id: "PL", * }, - * { - * amount: 450, - * currency_code: "EUR", - * rules: { - * city: "krakow" - * }, - * } - * ], - * }) - * - * // do something with the price set or return it - * } + * }, + * { + * amount: 450, + * currency_code: "EUR", + * rules: { + * city: "krakow", + * }, + * }, + * ], + * }) * ``` */ addPrices(data: AddPricesDTO, sharedContext?: Context): Promise @@ -853,75 +577,34 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The list of the price sets that prices were added to. * * @example - * - * To add a default price to a price set, don't pass it any rules and make sure to pass it the `currency_code`: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function addPricesToPriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.addPrices([{ - * priceSetId, + * const priceSets = await pricingModuleService.addPrices([ + * { + * priceSetId: "pset_123", * prices: [ - * { + * // default price because it doesn't + * // have rules + * { * amount: 500, * currency_code: "USD", * rules: {}, * }, * ], - * }]) - * - * // do something with the price sets or return them - * } - * ``` - * - * To add prices with rules: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function addPricesToPriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.addPrices([{ - * priceSetId, + * }, + * { + * priceSetId: "pset_321", * prices: [ + * // prices with rules * { * amount: 300, * currency_code: "EUR", * rules: { * region_id: "PL", - * city: "krakow" + * city: "krakow", * }, * }, - * { - * amount: 400, - * currency_code: "EUR", - * min_quantity: 0, - * max_quantity: 4, - * rules: { - * region_id: "PL" - * }, - * }, - * { - * amount: 450, - * currency_code: "EUR", - * rules: { - * city: "krakow" - * }, - * } * ], - * }]) - * - * // do something with the price sets or return them - * } - * ``` + * }, + * ]) */ addPrices( data: AddPricesDTO[], @@ -936,22 +619,14 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The price set that the rules were added to. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function addRulesToPriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSet = await pricingService.addRules({ - * priceSetId, - * rules: [{ - * attribute: "region_id" - * }] - * }) - * - * // do something with the price set or return it - * } + * const priceSet = await pricingModuleService.addRules({ + * priceSetId: "pset_123", + * rules: [ + * { + * attribute: "region_id", + * }, + * ], + * }) */ addRules(data: AddRulesDTO, sharedContext?: Context): Promise @@ -963,22 +638,24 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The list of the price sets that the rules were added to. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function addRulesToPriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() - * - * const priceSets = await pricingService.addRules([{ - * priceSetId, - * rules: [{ - * attribute: "region_id" - * }] - * }]) - * - * // do something with the price sets or return them - * } + * const priceSets = await pricingModuleService.addRules([ + * { + * priceSetId: "pset_123", + * rules: [ + * { + * attribute: "region_id", + * }, + * ], + * }, + * { + * priceSetId: "pset_321", + * rules: [ + * { + * attribute: "customer_group_id", + * }, + * ], + * }, + * ]) */ addRules(data: AddRulesDTO[], sharedContext?: Context): Promise @@ -996,35 +673,19 @@ export interface IPricingModuleService extends IModuleService { * A simple example that retrieves a rule type by its code: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleType (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * const ruleType = await pricingService.retrieveRuleType(ruleTypeId) - * - * // do something with the rule type or return it - * } + * const ruleType = + * await pricingModuleService.retrieveRuleType("rul-typ_123") * ``` * - * To specify attributes that should be retrieved: + * To specify relations that should be retrieved: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleType (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * const ruleType = await pricingService.retrieveRuleType(ruleTypeId, { - * select: ["name"] - * }) - * - * // do something with the rule type or return it - * } + * const ruleType = await pricingModuleService.retrieveRuleType( + * "rul-typ_123", + * { + * relations: ["price_sets"], + * } + * ) * ``` */ retrieveRuleType( @@ -1048,96 +709,37 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of rule types using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * const ruleTypes = await pricingService.listRuleTypes({ - * id: [ - * ruleTypeId - * ] - * }) - * - * // do something with the rule types or return them - * } + * const ruleTypes = await pricingModuleService.listRuleTypes({ + * id: ["rul-typ_123", "rul-typ_321"], + * }) * ``` * - * To specify attributes that should be retrieved within the rule types: + * To specify relations that should be retrieved: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * const ruleTypes = await pricingService.listRuleTypes({ - * id: [ - * ruleTypeId - * ] - * }, { - * select: ["name"] - * }) - * - * // do something with the rule types or return them - * } + * const ruleTypes = await pricingModuleService.listRuleTypes( + * { + * id: ["rul-typ_123", "rul-typ_321"], + * }, + * { + * relations: ["price_sets"], + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const ruleTypes = await pricingService.listRuleTypes({ - * id: [ - * ruleTypeId - * ] - * }, { - * select: ["name"], - * skip, - * take - * }) - * - * // do something with the rule types or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const ruleTypes = await pricingService.listRuleTypes({ - * $and: [ - * { - * id: ruleTypeId - * }, - * { - * name - * } - * ] - * }, { - * select: ["name"], - * skip, - * take - * }) - * - * // do something with the rule types or return them - * } + * const ruleTypes = await pricingModuleService.listRuleTypes( + * { + * id: ["rul-typ_123", "rul-typ_321"], + * }, + * { + * relations: ["price_sets"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ listRuleTypes( @@ -1161,96 +763,40 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of rule types using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({ - * id: [ - * ruleTypeId - * ] + * const [ruleTypes, count] = + * await pricingModuleService.listAndCountRuleTypes({ + * id: ["rul-typ_123", "rul-typ_321"], * }) - * - * // do something with the rule types or return them - * } * ``` * * To specify attributes that should be retrieved within the rule types: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({ - * id: [ - * ruleTypeId - * ] - * }, { - * select: ["name"] - * }) - * - * // do something with the rule types or return them - * } + * const [ruleTypes, count] = + * await pricingModuleService.listAndCountRuleTypes( + * { + * id: ["rul-typ_123", "rul-typ_321"], + * }, + * { + * relations: ["price_sets"], + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({ - * id: [ - * ruleTypeId - * ] - * }, { - * select: ["name"], - * skip, - * take - * }) - * - * // do something with the rule types or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({ - * $and: [ - * { - * id: ruleTypeId - * }, - * { - * name - * } - * ] - * }, { - * select: ["name"], - * skip, - * take - * }) - * - * // do something with the rule types or return them - * } + * const [ruleTypes, count] = + * await pricingModuleService.listAndCountRuleTypes( + * { + * id: ["rul-typ_123", "rul-typ_321"], + * }, + * { + * relations: ["price_sets"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ listAndCountRuleTypes( @@ -1267,22 +813,16 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The list of created rule types. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createRuleTypes () { - * const pricingService = await initializePricingModule() - * - * const ruleTypes = await pricingService.createRuleTypes([ - * { - * name: "Region", - * rule_attribute: "region_id" - * } - * ]) - * - * // do something with the rule types or return them - * } + * const ruleTypes = await pricingModuleService.createRuleTypes([ + * { + * name: "Region", + * rule_attribute: "region_id", + * }, + * { + * name: "Customer Group", + * rule_attribute: "customer_group_id", + * }, + * ]) */ createRuleTypes( data: CreateRuleTypeDTO[], @@ -1297,22 +837,16 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The list of updated rule types. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function updateRuleTypes (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * const ruleTypes = await pricingService.updateRuleTypes([ - * { - * id: ruleTypeId, - * name: "Region", - * } - * ]) - * - * // do something with the rule types or return them - * } + * const ruleTypes = await pricingModuleService.updateRuleTypes([ + * { + * id: "rul-typ_123", + * name: "Region", + * }, + * { + * id: "rul-typ_321", + * name: "Customer Group", + * }, + * ]) */ updateRuleTypes( data: UpdateRuleTypeDTO[], @@ -1327,15 +861,10 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} Resolves once the rule types are deleted. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function deleteRuleTypes (ruleTypeId: string) { - * const pricingService = await initializePricingModule() - * - * await pricingService.deleteRuleTypes([ruleTypeId]) - * } + * const ruleTypes = await pricingModuleService.deleteRuleTypes([ + * "rul-typ_123", + * "rul-typ_321", + * ]) */ deleteRuleTypes(ruleTypeIds: string[], sharedContext?: Context): Promise @@ -1354,90 +883,37 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of prices using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (id: string) { - * const pricingService = await initializePricingModule() - * - * const prices = await pricingService.listPrices({ - * id: [id] - * }) - * - * // do something with the prices or return them - * } + * const prices = await pricingModuleService.listPrices({ + * id: ["price_123", "price_321"], + * }) * ``` * * To specify relations that should be retrieved within the prices: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (id: string) { - * const pricingService = await initializePricingModule() - * - * const prices = await pricingService.listPrices({ - * id: [id] - * }, { - * relations: ["price_rules"] - * }) - * - * // do something with the prices or return them - * } + * const prices = await pricingModuleService.listPrices( + * { + * id: ["price_123", "price_321"], + * }, + * { + * relations: ["price_rules"], + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (id: string, skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const prices = await pricingService.listPrices({ - * id: [id] - * }, { + * const prices = await pricingModuleService.listPrices( + * { + * id: ["price_123", "price_321"], + * }, + * { * relations: ["price_rules"], - * skip, - * take - * }) - * - * // do something with the prices or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (ids: string[], titles: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const prices = await pricingService.listPrices({ - * $and: [ - * { - * id: ids - * }, - * { - * title: titles - * } - * ] - * }, { - * relations: ["price_rules"], - * skip, - * take - * }) - * - * // do something with the prices or return them - * } + * take: 20, + * skip: 2, + * } + * ) * ``` */ listPrices( @@ -1446,12 +922,50 @@ export interface IPricingModuleService extends IModuleService { sharedContext?: Context ): Promise + /** + * This method soft deletes prices by their IDs. + * + * @param {string[]} priceIds - The IDs of the prices. + * @param {SoftDeleteReturn} config - An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were also soft deleted, such as the ID of the associated price rules. + * The object's keys are the ID attribute names of the price entity's relations, such as `price_rule_id`, and its value is an array of strings, each being the ID of a record associated + * with the price through this relation, such as the IDs of associated price rule. + * + * If there are no related records, the promise resolves to `void`. + * + * @example + * await pricingModuleService.softDeletePrices([ + * "price_123", + * "price_321", + * ]) + */ softDeletePrices( priceIds: string[], config?: SoftDeleteReturn, sharedContext?: Context ): Promise | void> + /** + * This method restores soft deleted prices by their IDs. + * + * @param {string[]} priceIds - The IDs of the prices. + * @param {RestoreReturn} config - Configurations determining which relations to restore along with each of the prices. You can pass to its `returnLinkableKeys` + * property any of the price's relation attribute names, such as price_rules`. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were restored, such as the ID of associated price rules. + * The object's keys are the ID attribute names of the prices entity's relations, such as `price_rule_id`, + * and its value is an array of strings, each being the ID of the record associated with the prices through this relation, + * such as the IDs of associated price rules. + * + * If there are no related records restored, the promise resolves to `void`. + * + * @example + * await pricingModuleService.restorePrices([ + * "price_123", + * "price_321", + * ]) + */ restorePrices( priceIds: string[], config?: RestoreReturn, @@ -1474,90 +988,39 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of prices using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (id: string) { - * const pricingService = await initializePricingModule() - * - * const [prices, count] = await pricingService.listAndCountPrices({ - * id: [id] - * }) - * - * // do something with the prices or return them - * } + * const [prices, count] = await pricingModuleService.listPrices( + * { + * id: ["price_123", "price_321"], + * } + * ) * ``` * * To specify relations that should be retrieved within the prices: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (id: string) { - * const pricingService = await initializePricingModule() - * - * const [prices, count] = await pricingService.listAndCountPrices({ - * id: [id] - * }, { + * const [prices, count] = await pricingModuleService.listPrices( + * { + * id: ["price_123", "price_321"], + * }, + * { * relations: ["price_rules"], - * }) - * - * // do something with the prices or return them - * } + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (id: string, skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [prices, count] = await pricingService.listAndCountPrices({ - * id: [id] - * }, { + * const [prices, count] = await pricingModuleService.listPrices( + * { + * id: ["price_123", "price_321"], + * }, + * { * relations: ["price_rules"], - * skip, - * take - * }) - * - * // do something with the prices or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePrices (ids: string[], titles: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [prices, count] = await pricingService.listAndCountPrices({ - * $and: [ - * { - * id: ids - * }, - * { - * title: titles - * } - * ] - * }, { - * relations: ["price_rules"], - * skip, - * take - * }) - * - * // do something with the prices or return them - * } + * take: 20, + * skip: 2, + * } + * ) * ``` */ listAndCountPrices( @@ -1580,35 +1043,17 @@ export interface IPricingModuleService extends IModuleService { * A simple example that retrieves a price rule by its ID: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRule (id: string) { - * const pricingService = await initializePricingModule() - * - * const priceRule = await pricingService.retrievePriceRule(id) - * - * // do something with the price rule or return it - * } + * const priceRule = + * await pricingModuleService.retrievePriceRule("prule_123") * ``` * * To specify relations that should be retrieved: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRule (id: string) { - * const pricingService = await initializePricingModule() - * - * const priceRule = await pricingService.retrievePriceRule(id, { - * relations: ["price_set"] + * const priceRule = + * await pricingModuleService.retrievePriceRule("prule_123", { + * relations: ["price_set"], * }) - * - * // do something with the price rule or return it - * } * ``` */ retrievePriceRule( @@ -1632,90 +1077,37 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of price rules using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (id: string) { - * const pricingService = await initializePricingModule() - * - * const priceRules = await pricingService.listPriceRules({ - * id: [id] - * }) - * - * // do something with the price rules or return them - * } + * const priceRules = await pricingModuleService.listPriceRules({ + * id: ["prule_123", "prule_321"], + * }) * ``` * * To specify relations that should be retrieved within the price rules: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (id: string) { - * const pricingService = await initializePricingModule() - * - * const priceRules = await pricingService.listPriceRules({ - * id: [id], - * }, { - * relations: ["price_set"] - * }) - * - * // do something with the price rules or return them - * } + * const priceRules = await pricingModuleService.listPriceRules( + * { + * id: ["prule_123", "prule_321"], + * }, + * { + * relations: ["price_set"], + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (id: string, skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceRules = await pricingService.listPriceRules({ - * id: [id], - * }, { + * const priceRules = await pricingModuleService.listPriceRules( + * { + * id: ["prule_123", "prule_321"], + * }, + * { * relations: ["price_set"], - * skip, - * take - * }) - * - * // do something with the price rules or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceRules = await pricingService.listPriceRules({ - * $and: [ - * { - * id: ids - * }, - * { - * name - * } - * ] - * }, { - * relations: ["price_set"], - * skip, - * take - * }) - * - * // do something with the price rules or return them - * } + * take: 20, + * skip: 2, + * } + * ) * ``` */ listPriceRules( @@ -1739,90 +1131,40 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of price rules using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (id: string) { - * const pricingService = await initializePricingModule() - * - * const [priceRules, count] = await pricingService.listAndCountPriceRules({ - * id: [id] + * const [priceRules, count] = + * await pricingModuleService.listAndCountPriceListRules({ + * id: ["prule_123", "prule_321"], * }) - * - * // do something with the price rules or return them - * } * ``` * * To specify relations that should be retrieved within the price rules: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (id: string) { - * const pricingService = await initializePricingModule() - * - * const [priceRules, count] = await pricingService.listAndCountPriceRules({ - * id: [id], - * }, { - * relations: ["price_set"] - * }) - * - * // do something with the price rules or return them - * } + * const [priceRules, count] = + * await pricingModuleService.listAndCountPriceListRules( + * { + * id: ["prule_123", "prule_321"], + * }, + * { + * relations: ["price_set"], + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (id: string, skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceRules, count] = await pricingService.listAndCountPriceRules({ - * id: [id], - * }, { - * relations: ["price_set"], - * skip, - * take - * }) - * - * // do something with the price rules or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceRules, count] = await pricingService.listAndCountPriceRules({ - * $and: [ - * { - * id: ids - * }, - * { - * name - * } - * ] - * }, { - * relations: ["price_set"], - * skip, - * take - * }) - * - * // do something with the price rules or return them - * } + * const [priceRules, count] = + * await pricingModuleService.listAndCountPriceListRules( + * { + * id: ["prule_123", "prule_321"], + * }, + * { + * relations: ["price_set"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ listAndCountPriceRules( @@ -1839,33 +1181,14 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The list of created price rules. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createPriceRules ( - * id: string, - * priceSetId: string, - * ruleTypeId: string, - * value: string, - * priceId: string, - * priceListId: string - * ) { - * const pricingService = await initializePricingModule() - * - * const priceRules = await pricingService.createPriceRules([ + * const priceRules = + * await pricingModuleService.createPriceRules([ * { - * id, - * price_set_id: priceSetId, - * rule_type_id: ruleTypeId, - * value, - * price_id: priceId, - * price_list_id: priceListId - * } + * value: "VIP", + * rule_type_id: "rul-typ_123", + * price_set_id: "pset_123", + * }, * ]) - * - * // do something with the price rules or return them - * } */ createPriceRules( data: CreatePriceRuleDTO[], @@ -1880,25 +1203,13 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The list of updated price rules. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function updatePriceRules ( - * id: string, - * priceSetId: string, - * ) { - * const pricingService = await initializePricingModule() - * - * const priceRules = await pricingService.updatePriceRules([ + * const priceRules = + * await pricingModuleService.updatePriceRules([ * { - * id, - * price_set_id: priceSetId, - * } + * id: "prule_123", + * price_id: "price_123", + * }, * ]) - * - * // do something with the price rules or return them - * } */ updatePriceRules( data: UpdatePriceRuleDTO[], @@ -1913,17 +1224,10 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} Resolves once the price rules are deleted. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function deletePriceRules ( - * id: string, - * ) { - * const pricingService = await initializePricingModule() - * - * await pricingService.deletePriceRules([id]) - * } + * await pricingModuleService.deletePriceRules([ + * "prule_123", + * "prule_321", + * ]) */ deletePriceRules( priceRuleIds: string[], @@ -1944,40 +1248,17 @@ export interface IPricingModuleService extends IModuleService { * A simple example that retrieves a price list by its ID: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceList (priceListId: string) { - * const pricingService = await initializePricingModule() - * - * const priceList = await pricingService.retrievePriceList( - * priceListId - * ) - * - * // do something with the price list or return it - * } + * const priceList = + * await pricingModuleService.retrievePriceList("plist_123") * ``` * * To specify relations that should be retrieved: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceList (priceListId: string) { - * const pricingService = await initializePricingModule() - * - * const priceList = await pricingService.retrievePriceList( - * priceListId, - * { - * relations: ["prices"] - * } - * ) - * - * // do something with the price list or return it - * } + * const priceList = + * await pricingModuleService.retrievePriceList("plist_123", { + * relations: ["prices"], + * }) * ``` */ retrievePriceList( @@ -2001,101 +1282,37 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of price lists using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceLists (priceListIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const priceLists = await pricingService.listPriceLists( - * { - * id: priceListIds - * }, - * ) - * - * // do something with the price lists or return them - * } + * const priceLists = await pricingModuleService.listPriceLists({ + * id: ["plist_123", "plist_321"], + * }) * ``` * * To specify relations that should be retrieved within the price lists: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceLists (priceListIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const priceLists = await pricingService.listPriceLists( - * { - * id: priceListIds - * }, - * { - * relations: ["prices"] - * } - * ) - * - * // do something with the price lists or return them - * } + * const priceLists = await pricingModuleService.listPriceLists( + * { + * id: ["plist_123", "plist_321"], + * }, + * { + * relations: ["prices"], + * } + * ) * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceLists (priceListIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceLists = await pricingService.listPriceLists( - * { - * id: priceListIds - * }, - * { - * relations: ["prices"], - * skip, - * take - * } - * ) - * - * // do something with the price lists or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceLists (priceListIds: string[], titles: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceLists = await pricingService.listPriceLists( - * { - * $and: [ - * { - * id: priceListIds - * }, - * { - * title: titles - * } - * ] - * }, - * { - * relations: ["prices"], - * skip, - * take - * } - * ) - * - * // do something with the price lists or return them - * } + * const priceLists = await pricingModuleService.listPriceLists( + * { + * id: ["plist_123", "plist_321"], + * }, + * { + * relations: ["prices"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ listPriceLists( @@ -2119,101 +1336,40 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of price lists using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceLists (priceListIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const [priceLists, count] = await pricingService.listPriceLists( - * { - * id: priceListIds - * }, - * ) - * - * // do something with the price lists or return them - * } + * const [priceLists, count] = + * await pricingModuleService.listAndCountPriceLists({ + * id: ["plist_123", "plist_321"], + * }) * ``` * * To specify relations that should be retrieved within the price lists: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceLists (priceListIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const [priceLists, count] = await pricingService.listPriceLists( + * const [priceLists, count] = + * await pricingModuleService.listAndCountPriceLists( * { - * id: priceListIds + * id: ["plist_123", "plist_321"], * }, * { - * relations: ["prices"] + * relations: ["prices"], * } * ) - * - * // do something with the price lists or return them - * } * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceLists (priceListIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceLists, count] = await pricingService.listPriceLists( + * const [priceLists, count] = + * await pricingModuleService.listAndCountPriceLists( * { - * id: priceListIds + * id: ["plist_123", "plist_321"], * }, * { * relations: ["prices"], - * skip, - * take + * take: 20, + * skip: 2, * } * ) - * - * // do something with the price lists or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceLists (priceListIds: string[], titles: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceLists, count] = await pricingService.listPriceLists( - * { - * $and: [ - * { - * id: priceListIds - * }, - * { - * title: titles - * } - * ] - * }, - * { - * relations: ["prices"], - * skip, - * take - * } - * ) - * - * // do something with the price lists or return them - * } * ``` */ listAndCountPriceLists( @@ -2230,22 +1386,18 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The created price lists. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createPriceList (items: { - * title: string - * description: string - * starts_at?: string - * ends_at?: string - * }[]) { - * const pricingService = await initializePricingModule() - * - * const priceList = await pricingService.createPriceLists(items) - * - * // do something with the price lists or return them - * } + * const priceLists = + * await pricingModuleService.createPriceLists([ + * { + * title: "Sale 1", + * description: "Summer sale", + * }, + * { + * title: "Sale 2", + * description: "Winter sale", + * starts_at: "2024-12-21", + * }, + * ]) */ createPriceLists( data: CreatePriceListDTO[], @@ -2255,28 +1407,22 @@ export interface IPricingModuleService extends IModuleService { /** * This method is used to update price lists. * - * @param {UpdatePriceListDTO[]} data - The attributes to update in each price list. + * @param {UpdatePriceListDTO[]} data - The attributes to update in each price list. The price list is identifed by the `id` field. * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. * @returns {Promise} The updated price lists. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function updatePriceLists (items: { - * id: string - * title: string - * description: string - * starts_at?: string - * ends_at?: string - * }[]) { - * const pricingService = await initializePricingModule() - * - * const priceList = await pricingService.updatePriceLists(items) - * - * // do something with the price lists or return them - * } + * const priceLists = + * await pricingModuleService.updatePriceLists([ + * { + * id: "plist_123", + * title: "Sale 1", + * }, + * { + * id: "plist_321", + * description: "Winter sale", + * }, + * ]) */ updatePriceLists( data: UpdatePriceListDTO[], @@ -2291,27 +1437,60 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} Resolves when the price lists are deleted successfully. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function deletePriceLists (ids: string[]) { - * const pricingService = await initializePricingModule() - * - * await pricingService.deletePriceLists(ids) - * } + * await pricingModuleService.deletePriceLists([ + * "plist_123", + * "plist_321", + * ]) */ deletePriceLists( priceListIds: string[], sharedContext?: Context ): Promise + /** + * This method soft deletes price lists by their IDs. + * + * @param {string[]} priceListIds - The IDs of the price lists. + * @param {SoftDeleteReturn} config - An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were also soft deleted, such as the ID of the associated price list rules. + * The object's keys are the ID attribute names of the price list entity's relations, such as `price_list_rule_id`, and its value is an array of strings, each being the ID of a record associated + * with the price list through this relation, such as the IDs of associated price list rule. + * + * If there are no related records, the promise resolves to `void`. + * + * @example + * await pricingModuleService.softDeletePriceLists([ + * "plist_123", + * "plist_321", + * ]) + */ softDeletePriceLists( priceListIds: string[], config?: SoftDeleteReturn, sharedContext?: Context ): Promise | void> + /** + * This method restores a soft deleted price lists by its IDs. + * + * @param {string[]} priceListIds - The list of {summary} + * @param {RestoreReturn} config - Configurations determining which relations to restore along with each of the price lists. You can pass to its `returnLinkableKeys` + * property any of the price list's relation attribute names, such as `price_list_rules`. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were restored, such as the ID of associated price list rules. + * The object's keys are the ID attribute names of the price list entity's relations, such as `price_list_rule_id`, + * and its value is an array of strings, each being the ID of the record associated with the price list through this relation, + * such as the IDs of associated price list rules. + * + * If there are no related records restored, the promise resolves to `void`. + * + * @example + * await pricingModuleService.restorePriceLists([ + * "plist_123", + * "plist_321", + * ]) + */ restorePriceLists( priceListIds: string[], config?: RestoreReturn, @@ -2332,40 +1511,22 @@ export interface IPricingModuleService extends IModuleService { * A simple example that retrieves a price list rule by its ID: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceListRule (priceListRuleId: string) { - * const pricingService = await initializePricingModule() - * - * const priceListRule = await pricingService.retrievePriceListRule( - * priceListRuleId + * const priceListRule = + * await pricingModuleService.retrievePriceListRule( + * "plrule_123" * ) - * - * // do something with the price list rule or return it - * } * ``` * * To specify relations that should be retrieved: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function retrievePriceListRule (priceListRuleId: string) { - * const pricingService = await initializePricingModule() - * - * const priceListRule = await pricingService.retrievePriceListRule( - * priceListRuleId, + * const priceListRule = + * await pricingModuleService.retrievePriceListRule( + * "plrule_123", * { - * relations: ["price_list"] + * relations: ["price_list"], * } * ) - * - * // do something with the price list rule or return it - * } * ``` */ retrievePriceListRule( @@ -2389,101 +1550,40 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of price list vs using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceListRules (priceListRuleIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const priceListRules = await pricingService.listPriceListRules( - * { - * id: priceListRuleIds - * }, - * ) - * - * // do something with the price list rules or return them - * } + * const priceListRules = + * await pricingModuleService.listPriceListRules({ + * id: ["plrule_123", "plrule_321"], + * }) * ``` * * To specify relations that should be retrieved within the price list rules: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceListRules (priceListRuleIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const priceListRules = await pricingService.listPriceListRules( + * const priceListRules = + * await pricingModuleService.listPriceListRules( * { - * id: priceListRuleIds + * id: ["plrule_123", "plrule_321"], * }, * { - * relations: ["price_list_rule_values"] + * relations: ["price_list_rule_values"], * } * ) - * - * // do something with the price list rules or return them - * } * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceListRules (priceListRuleIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceListRules = await pricingService.listPriceListRules( + * const priceListRules = + * await pricingModuleService.listPriceListRules( * { - * id: priceListRuleIds + * id: ["plrule_123", "plrule_321"], * }, * { * relations: ["price_list_rule_values"], - * skip, - * take + * take: 20, + * skip: 2, * } * ) - * - * // do something with the price list rules or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listPriceListRules (priceListRuleIds: string[], ruleTypeIDs: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const priceListRules = await pricingService.listPriceListRules( - * { - * $and: [ - * { - * id: priceListRuleIds - * }, - * { - * rule_types: ruleTypeIDs - * } - * ] - * }, - * { - * relations: ["price_list_rule_values"], - * skip, - * take - * } - * ) - * - * // do something with the price list rules or return them - * } * ``` */ listPriceListRules( @@ -2507,101 +1607,40 @@ export interface IPricingModuleService extends IModuleService { * To retrieve a list of price list vs using their IDs: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listAndCountPriceListRules (priceListRuleIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const [priceListRules, count] = await pricingService.listAndCountPriceListRules( - * { - * id: priceListRuleIds - * }, - * ) - * - * // do something with the price list rules or return them - * } + * const [priceListRules, count] = + * await pricingModuleService.listAndCountPriceListRules({ + * id: ["plrule_123", "plrule_321"], + * }) * ``` * * To specify relations that should be retrieved within the price list rules: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listAndCountPriceListRules (priceListRuleIds: string[]) { - * const pricingService = await initializePricingModule() - * - * const [priceListRules, count] = await pricingService.listAndCountPriceListRules( + * const [priceListRules, count] = + * await pricingModuleService.listAndCountPriceListRules( * { - * id: priceListRuleIds + * id: ["plrule_123", "plrule_321"], * }, * { - * relations: ["price_list_rule_values"] + * relations: ["price_list_rule_values"], * } * ) - * - * // do something with the price list rules or return them - * } * ``` * * By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: * * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listAndCountPriceListRules (priceListRuleIds: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceListRules, count] = await pricingService.listAndCountPriceListRules( + * const [priceListRules, count] = + * await pricingModuleService.listAndCountPriceListRules( * { - * id: priceListRuleIds + * id: ["plrule_123", "plrule_321"], * }, * { * relations: ["price_list_rule_values"], - * skip, - * take + * take: 20, + * skip: 2, * } * ) - * - * // do something with the price list rules or return them - * } - * ``` - * - * You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example: - * - * ```ts - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function listAndCountPriceListRules (priceListRuleIds: string[], ruleTypeIDs: string[], skip: number, take: number) { - * const pricingService = await initializePricingModule() - * - * const [priceListRules, count] = await pricingService.listAndCountPriceListRules( - * { - * $and: [ - * { - * id: priceListRuleIds - * }, - * { - * rule_types: ruleTypeIDs - * } - * ] - * }, - * { - * relations: ["price_list_rule_values"], - * skip, - * take - * } - * ) - * - * // do something with the price list rules or return them - * } * ``` */ listAndCountPriceListRules( @@ -2618,20 +1657,13 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The created price list rules. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function createPriceListRules (items: { - * rule_type_id: string - * price_list_id: string - * }[]) { - * const pricingService = await initializePricingModule() - * - * const priceListRules = await pricingService.createPriceListRules(items) - * - * // do something with the price list rule or return them - * } + * const priceListRules = + * await pricingModuleService.createPriceListRules([ + * { + * rule_type_id: "rul-typ_123", + * price_list_id: "plist_123", + * }, + * ]) */ createPriceListRules( data: CreatePriceListRuleDTO[], @@ -2641,26 +1673,18 @@ export interface IPricingModuleService extends IModuleService { /** * This method is used to update price list rules. * - * @param {UpdatePriceListRuleDTO[]} data - The attributes to update for each price list rule. + * @param {UpdatePriceListRuleDTO[]} data - The attributes to update for each price list rule. The price list rule is identified by the `id` property. * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. * @returns {Promise} The updated price list rules. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function updatePriceListRules (items: { - * id: string - * rule_type_id?: string - * price_list_id?: string - * }[]) { - * const pricingService = await initializePricingModule() - * - * const priceListRules = await pricingService.updatePriceListRules(items) - * - * // do something with the price list rule or return them - * } + * const priceListRules = + * await pricingModuleService.updatePriceListRules([ + * { + * id: "plrule_123", + * rule_type_id: "rul-typ_123", + * }, + * ]) */ updatePriceListRules( data: UpdatePriceListRuleDTO[], @@ -2675,15 +1699,10 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} Resolves successfully when the price list rules are deleted. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function deletePriceListRules (priceListRuleIds: string[]) { - * const pricingService = await initializePricingModule() - * - * await pricingService.deletePriceListRules(priceListRuleIds) - * } + * await pricingModuleService.deletePriceListRules([ + * "plrule_123", + * "plrule_321", + * ]) */ deletePriceListRules( priceListRuleIds: string[], @@ -2698,59 +1717,70 @@ export interface IPricingModuleService extends IModuleService { * @returns {Promise} The updated price lists. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function addPriceListPrices (items: { - * priceListId: string, - * prices: { - * currency_code: string, - * amount: number, - * price_set_id: string - * }[] - * }[]) { - * const pricingService = await initializePricingModule() - * - * const priceLists = await pricingService.addPriceListPrices(items) - * - * // do something with the price lists or return them - * } + * const priceLists = + * await pricingModuleService.addPriceListPrices([ + * { + * price_list_id: "plist_123", + * prices: [ + * { + * currency_code: "usd", + * amount: 500, + * price_set_id: "pset_123", + * }, + * ], + * }, + * ]) */ addPriceListPrices( data: AddPriceListPricesDTO[], sharedContext?: Context ): Promise + /** + * This method updates existing price list's prices. + * + * @param {UpdatePriceListPricesDTO[]} data - The attributes to update in a price list's prices. The price list's ID is specified + * in the `price_list_id` field. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The updated price list's prices. + * + * @example + * const priceLists = + * await pricingModuleService.updatePriceListPrices([ + * { + * price_list_id: "plist_123", + * prices: [ + * { + * id: "price_123", + * currency_code: "usd", + * amount: 500, + * price_set_id: "pset_123", + * }, + * ], + * }, + * ]) + */ updatePriceListPrices( data: UpdatePriceListPricesDTO[], sharedContext?: Context ): Promise /** - * This method is used to set the rules of a price list. + * This method is used to set the rules of a price list. Previous rules are removed. * - * @param {SetPriceListRulesDTO} data - The rules to set for a price list. + * @param {SetPriceListRulesDTO} data - The rules to set for a price list. The price list is identified by the + * `price_list_id` property. * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The updated price lists. + * @returns {Promise} The updated price list. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function setPriceListRules (priceListId: string) { - * const pricingService = await initializePricingModule() - * - * const priceList = await pricingService.setPriceListRules({ - * priceListId, + * const priceList = + * await pricingModuleService.setPriceListRules({ + * price_list_id: "plist_123", * rules: { - * region_id: "US" - * } + * region_id: "reg_123", + * }, * }) - * - * // do something with the price list or return it - * } */ setPriceListRules( data: SetPriceListRulesDTO, @@ -2760,30 +1790,35 @@ export interface IPricingModuleService extends IModuleService { /** * This method is used to remove rules from a price list. * - * @param {RemovePriceListRulesDTO} data - The rules to remove from a price list. + * @param {RemovePriceListRulesDTO} data - The rules to remove from a price list. The price list is identified by the + * `price_list_id` property. * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. * @returns {Promise} The updated price lists. * * @example - * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" - * - * async function setPriceListRules (priceListId: string) { - * const pricingService = await initializePricingModule() - * - * const priceList = await pricingService.removePriceListRules({ - * priceListId, - * rules: ["region_id"] + * const priceList = + * await pricingModuleService.removePriceListRules({ + * price_list_id: "plist_123", + * rules: ["region_id"], * }) - * - * // do something with the price list or return it - * } */ removePriceListRules( data: RemovePriceListRulesDTO, sharedContext?: Context ): Promise + /** + * This method deletes prices by their IDs. + * + * @param {string[]} ids - The IDs of the prices. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} Resolves when the prices are deleted successfully. + * + * @example + * await pricingModuleService.removePrices([ + * "price_123", + * "price_321", + * ]) + */ removePrices(ids: string[], sharedContext?: Context): Promise }