Apologies for the giant PR in advance, but most of these are removing of files and migrations from old workflows and routes to new.
What:
- Adds CRUD endpoints for price lists
- Migrate workflows from old sdk to new
- Added missing updatePriceListPrices method to pricing module
**What**
Default ordering. By default, only the top level entity ordering is applied using the primary keys, the relations are default ordered by the foreign keys.
It include tests fixing for deterministic data ordering
What:
- Event Aggregator Util
- Preparation for normalizing event in a new format (backward compatible with the current format)
- GQL Schema to joiner config and some Entities configured
- Link modules emmiting events
**What**
- Remove services that do not have any custom business and replace them with a simple interfaces
- Abstract module service provide the following base implementation
- retrieve
- list
- listAndCount
- delete
- softDelete
- restore
The above methods are created for the main model and also for each other models for which a config is provided
all method such as list, listAndCount, delete, softDelete and restore are pluralized with the model it refers to
**Migration**
- [x] product
- [x] pricing
- [x] promotion
- [x] cart
- [x] auth
- [x] customer
- [x] payment
- [x] Sales channel
- [x] Workflow-*
**Usage**
**Module**
The module service can now extend the ` ModulesSdkUtils.abstractModuleServiceFactory` which returns a class with the default implementation for each method and each model following the standard naming convention mentioned above.
This factory have 3 template arguments being the container, the main model DTO and an object representing the other model with a config object that contains at list the DTO and optionally a singular and plural property in case it needs to be set manually. It looks like the following:
```ts
export default class PricingModuleService</* ... */>
extends ModulesSdkUtils.abstractModuleServiceFactory<
InjectedDependencies,
PricingTypes.PriceSetDTO,
{
Currency: { dto: PricingTypes.CurrencyDTO }
MoneyAmount: { dto: PricingTypes.MoneyAmountDTO }
PriceSetMoneyAmount: { dto: PricingTypes.PriceSetMoneyAmountDTO }
PriceSetMoneyAmountRules: {
dto: PricingTypes.PriceSetMoneyAmountRulesDTO
}
PriceRule: { dto: PricingTypes.PriceRuleDTO }
RuleType: { dto: PricingTypes.RuleTypeDTO }
PriceList: { dto: PricingTypes.PriceListDTO }
PriceListRule: { dto: PricingTypes.PriceListRuleDTO }
}
>(PriceSet, generateMethodForModels, entityNameToLinkableKeysMap)
implements PricingTypes.IPricingModuleService
{
// ...
}
```
In the above, the singular and plural can be inferred as there is no tricky naming. Also, the default implementation does not remove the fact that you need to provides all the overloads etc in your module service interface. The above will provide a default implementation following the interface `AbstractModuleService` which is also auto generated, hence you will have the following methods available:
**for the main model**
- list
- retrieve
- listAndCount
- delete
- softDelete
- restore
**for the other models**
- list**MyModels**
- retrieve**MyModel**
- listAndCount**MyModels**
- delete**MyModels**
- softDelete**MyModels**
- restore**MyModels**
**Internal module service**
The internal module service can now extend `ModulesSdkUtils.internalModuleServiceFactory` which takes only one template argument which is the container type.
All internal services provides a default implementation for all retrieve, list, listAndCount, create, update, delete, softDelete, restore methods which follow the following interface `ModulesSdkTypes.InternalModuleService`:
```ts
export interface InternalModuleService<
TEntity extends {},
TContainer extends object = object
> {
get __container__(): TContainer
retrieve(
idOrObject: string,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<TEntity>
retrieve(
idOrObject: object,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<TEntity>
list(
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<TEntity[]>
listAndCount(
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<[TEntity[], number]>
create(data: any[], sharedContext?: Context): Promise<TEntity[]>
create(data: any, sharedContext?: Context): Promise<TEntity>
update(data: any[], sharedContext?: Context): Promise<TEntity[]>
update(data: any, sharedContext?: Context): Promise<TEntity>
update(
selectorAndData: {
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
data: any
},
sharedContext?: Context
): Promise<TEntity[]>
update(
selectorAndData: {
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
data: any
}[],
sharedContext?: Context
): Promise<TEntity[]>
delete(idOrSelector: string, sharedContext?: Context): Promise<void>
delete(idOrSelector: string[], sharedContext?: Context): Promise<void>
delete(idOrSelector: object, sharedContext?: Context): Promise<void>
delete(idOrSelector: object[], sharedContext?: Context): Promise<void>
delete(
idOrSelector: {
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
},
sharedContext?: Context
): Promise<void>
softDelete(
idsOrFilter: string[] | InternalFilterQuery,
sharedContext?: Context
): Promise<[TEntity[], Record<string, unknown[]>]>
restore(
idsOrFilter: string[] | InternalFilterQuery,
sharedContext?: Context
): Promise<[TEntity[], Record<string, unknown[]>]>
upsert(data: any[], sharedContext?: Context): Promise<TEntity[]>
upsert(data: any, sharedContext?: Context): Promise<TEntity>
}
```
When a service is auto generated you can use that interface to type your class property representing the expected internal service.
**Repositories**
The repositories can now extend `DALUtils.mikroOrmBaseRepositoryFactory` which takes one template argument being the entity or the template entity and provides all the default implementation. If the repository is auto generated you can type it using the `RepositoryService` interface. Here is the new interface typings.
```ts
export interface RepositoryService<T = any> extends BaseRepositoryService<T> {
find(options?: FindOptions<T>, context?: Context): Promise<T[]>
findAndCount(
options?: FindOptions<T>,
context?: Context
): Promise<[T[], number]>
create(data: any[], context?: Context): Promise<T[]>
// Becareful here, if you have a custom internal service, the update data should never be the entity otherwise
// both entity and update will point to the same ref and create issues with mikro orm
update(data: { entity; update }[], context?: Context): Promise<T[]>
delete(
idsOrPKs: FilterQuery<T> & BaseFilterable<FilterQuery<T>>,
context?: Context
): Promise<void>
/**
* Soft delete entities and cascade to related entities if configured.
*
* @param idsOrFilter
* @param context
*
* @returns [T[], Record<string, string[]>] the second value being the map of the entity names and ids that were soft deleted
*/
softDelete(
idsOrFilter: string[] | InternalFilterQuery,
context?: Context
): Promise<[T[], Record<string, unknown[]>]>
restore(
idsOrFilter: string[] | InternalFilterQuery,
context?: Context
): Promise<[T[], Record<string, unknown[]>]>
upsert(data: any[], context?: Context): Promise<T[]>
}
```
What:
- When calling a module's method inside a Local Workflow the MedusaContext is passed as the last argument to the method if not provided
- Add `requestId` to req
- A couple of fixes on Remote Joiner and the data fetcher for internal services
Why:
- The context used to initialize the workflow has to be shared with all modules. properties like transactionId will be used to emit events and requestId to trace logs for example.
**What**
Create a service abstraction for the modules internal service layer. The objective is to reduce the effort of building new modules when the logic is the same or otherwise allow to override the default behavior.
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
**What**
Reduce the work effort to create repositories when building new modules by abstracting the most common cases into the base class default implementation returned by a factory
- [x] Migrate all modules
Co-authored-by: Riqwan Thamir <5105988+riqwan@users.noreply.github.com>
* init
* remove date string validator;
* add transformOptionalDate transformer to api
* move type conversion to the datalayer
* fix final module integration test
* update arrow-function
* make string optional
* move work to utils
* make check for value exists
* move util back to pricng
* change utils
* refactor get-iso-string
* fix build
* flip transform condition
* add null check for isDate
* feat(pricing): Separate Pricing Module internal types from `@medusajs/types` (#5777)
* create types for pricing repositories
* create RepositoryTypes input
* add service types
* use models for repository types
* fix build
* update types to match interface types
* add aliases
* types instead of moduletypes
* move repository to types for pricing module
* add changeset
* fix merge error
* fix conflict
* fix build
* re-add validation of dates in updatePriceLists_
**What**
- Add price-rules for prices in price-lists
- make rules object optional when creating prices
**Why**
- more price granularity
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
* remove defaults
* take 2
* works now
* add changeset
* pricing module and pricing service list take null updates
* update handlers
* update product module service with take:null where relevant
* no spread
* note to self:default offset should be 0, not 15
**what:**
**PriceList Service APIs:**
- createPriceList
- updatePriceList
- addPriceListPrices
- removePriceListRules
- setPriceListRules
- deletePriceList
- listPriceLists
- listAndCountPriceLists
**Price Calculations**
- Returns prices with price list prices
- Returns a new shape with calculated and original prices
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
* chore: remove skipping logic for migrations
* chore: medusa app returns migrations to run for modules
* chore: added migration for feature compatible
* chore: added changelog
* chore: create table only if it does not exist
* chore: update migration to pluck from registered modules
* chore: cleanup
* chore: make product an internal service temp
* chore: added options and deps to module
* chore: added link module options
* chore: remove duplicate
* chore: added missing column names in core + remove from model
* chore: scope migrations to only to create if not exist - money amount, currency
---------
Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
* initial
* initial service
* update pricing module service
* add integration test for rule-type
* update pricing-module integration tests
* update pricing service interface
* feat(pricing): PriceSets as entry point to pricing module
* chore: add price set money amount
* chore: add price set money amount
* chore: change name of test
* chore: added changeset
* chore: use filterable props from money amount in price sets
* chore: update migrations
* test update integration test
* fix weird behavior
* Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* Apply suggestions from code review
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* move rule-type to common
* chore: reset migration
* chore: remove incorrect conflicts
* chore: address review
* chore: remove ghost price list
* Apply suggestions from code review
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
* update id prefix
* use persist not persistAndflush
* rename key_value to rule_attribute
* more renaming
* feat(types,pricing): add price set money amount rules to pricing module
* chore: cleanup + add test cases for relationship update
* chore: revert package json
* chore: cleanup
* initial
* update pricing module service
* update pricing-module integration tests
* update pricing service interface
* chore: update migrations
* fix weird behavior
* Apply suggestions from code review
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* move rule-type to common
* chore: delete duplicate migration files
* fix(link-modules): Fix link module initialization (#4990)
**What**
Add a new configuration on the relationship to specify if the relation is consumed from an internal service (from medusa core). In that case do not check if the service is part of the loaded modules
* initial price rule
* rebase develop
* save here
* final changes to create
* update price rule integration test
* add module integraiton tests for price rules
* fix merge
* redo wierd order change
* pr cleanup
* pr cleanup
* pr cleanup
* update pr
* sort out migrations
* [wip]
* wip
* chore: temporarily emulate mikroorm internals
* currency code hard filtering
* before creating subqueries
* chore: wip
* chore: wip
* chore: add exact match multiple contexts
* chore: add one more test
* chore: add query that works with exact match
* chore: qb the thingy
* chore: add some comments
* chore: removed extra filter
* chore: added some more comments + prettify
* chore: test with carlos
* chore: add fallbacks and exact match tests
* chore: cleanup
* feat(types,pricing): add price set money amount rules to pricing module (#5065)
* initial
* initial service
* update pricing module service
* add integration test for rule-type
* update pricing-module integration tests
* update pricing service interface
* feat(pricing): PriceSets as entry point to pricing module
* chore: add price set money amount
* chore: add price set money amount
* chore: change name of test
* chore: added changeset
* chore: use filterable props from money amount in price sets
* chore: update migrations
* test update integration test
* fix weird behavior
* Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* Apply suggestions from code review
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* move rule-type to common
* chore: reset migration
* chore: remove incorrect conflicts
* chore: address review
* chore: remove ghost price list
* Apply suggestions from code review
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
* update id prefix
* use persist not persistAndflush
* rename key_value to rule_attribute
* more renaming
* feat(types,pricing): add price set money amount rules to pricing module
* chore: cleanup + add test cases for relationship update
* chore: revert package json
* chore: cleanup
---------
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
* chore: minor cleanup
* chore: added money amount scoping
* chore: added review comments
* chore: update changset and undo test scoping
* add migration for price_set_rule_type table
* update types
* initial add
* update tests
* working create with rule-types
* initial testing for money amount creation
* add price set money amount repo and service
* fix broken build
* create price list with prices and rule types
* create price set with info not being rules and money amounts
* create price set initial working implementation
* chore: introduce group by util + no queries on empty context
* addPrices
* remove comments
* Feat/pricing module methods (#5218)
chore: add removePrices to pricing module
* fix broken integration test
* Revert "Feat/pricing module methods (#5218)" (#5236)
This reverts commit 95c8aaa66423d290a35b6e736e5b187e12d44a36.
* feat(types,pricing): remove prices from a price set (#5235)
feat(types,pricing): remove prices from a price set
* add addRules
* typing
* add validation of price set ids for addRules
* add rule_attribute check for addRules method
* chore: review changes
* chore: update schema
* chore: first part of reviews
* chore: reset migration
* remove unnecessary init
* update interface
* use persist not persistAndflush
* chore: added money amount scoping
* chore: update schema
* fix
* fix 2
* add default pricing
* addPrices
* create
* update pricing service interface
* chore: rename money amounts to prices
* chore: cleanup + changelog
* chore: update package.json
* chore: cleanup persistAndFlushes from services
* jsdoc
* chore: add js docs for price rules
* chore: added js doc for psma and rule types
* chore: added jsdoc for currencies
* more jsdocs
* jsdoc money amounts
* chore: move jsdoc to interface
* chore: remove persist and flush to persist
* change overload
---------
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
* initial
* initial service
* update pricing module service
* add integration test for rule-type
* update pricing-module integration tests
* update pricing service interface
* feat(pricing): PriceSets as entry point to pricing module
* chore: add price set money amount
* chore: add price set money amount
* chore: change name of test
* chore: added changeset
* chore: use filterable props from money amount in price sets
* chore: update migrations
* test update integration test
* fix weird behavior
* Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* Apply suggestions from code review
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* move rule-type to common
* chore: reset migration
* chore: remove incorrect conflicts
* chore: address review
* chore: remove ghost price list
* Apply suggestions from code review
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
* update id prefix
* use persist not persistAndflush
* rename key_value to rule_attribute
* more renaming
* feat(types,pricing): add price set money amount rules to pricing module
* chore: cleanup + add test cases for relationship update
* chore: revert package json
* chore: cleanup
* initial
* update pricing module service
* update pricing-module integration tests
* update pricing service interface
* chore: update migrations
* fix weird behavior
* Apply suggestions from code review
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* move rule-type to common
* chore: delete duplicate migration files
* fix(link-modules): Fix link module initialization (#4990)
**What**
Add a new configuration on the relationship to specify if the relation is consumed from an internal service (from medusa core). In that case do not check if the service is part of the loaded modules
* initial price rule
* rebase develop
* save here
* final changes to create
* update price rule integration test
* add module integraiton tests for price rules
* fix merge
* redo wierd order change
* pr cleanup
* pr cleanup
* pr cleanup
* update pr
* sort out migrations
* [wip]
* wip
* chore: temporarily emulate mikroorm internals
* currency code hard filtering
* before creating subqueries
* chore: wip
* chore: wip
* chore: add exact match multiple contexts
* chore: add one more test
* chore: add query that works with exact match
* chore: qb the thingy
* chore: add some comments
* chore: removed extra filter
* chore: added some more comments + prettify
* chore: test with carlos
* chore: add fallbacks and exact match tests
* chore: cleanup
* feat(types,pricing): add price set money amount rules to pricing module (#5065)
* initial
* initial service
* update pricing module service
* add integration test for rule-type
* update pricing-module integration tests
* update pricing service interface
* feat(pricing): PriceSets as entry point to pricing module
* chore: add price set money amount
* chore: add price set money amount
* chore: change name of test
* chore: added changeset
* chore: use filterable props from money amount in price sets
* chore: update migrations
* test update integration test
* fix weird behavior
* Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* Apply suggestions from code review
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
* move rule-type to common
* chore: reset migration
* chore: remove incorrect conflicts
* chore: address review
* chore: remove ghost price list
* Apply suggestions from code review
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
* update id prefix
* use persist not persistAndflush
* rename key_value to rule_attribute
* more renaming
* feat(types,pricing): add price set money amount rules to pricing module
* chore: cleanup + add test cases for relationship update
* chore: revert package json
* chore: cleanup
---------
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
* chore: minor cleanup
* chore: added money amount scoping
* chore: added review comments
* chore: update changset and undo test scoping
* chore: introduce group by util + no queries on empty context
* Feat/pricing module methods (#5218)
chore: add removePrices to pricing module
* Revert "Feat/pricing module methods (#5218)" (#5236)
This reverts commit 95c8aaa66423d290a35b6e736e5b187e12d44a36.
* chore: review changes
* chore: update schema
* chore: reset migration
---------
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
**What**
- includes some type fixes in the DAL layer
- List products including their prices and filtered by the sales channel as well as q parameter and category scope and all other filters
- Assign shipping profile
- ordering
- Add missing columns in the product module
- update product module migrations
**Comment**
- In regards to the fields, we can pass whatever we want the module will only return the one that exists (default behavior), but on the other hand, that is not possible for the relations.
**question**
- To simplify usage, should we expose the fields/relations available from the module to simplify building a query for the user and be aware of what the module provides
**todo**
- Add back the support for the user to ask for fields/relations
What:
- Setups the skeleton for pricing module
- Creates service/model/repository for currency model
- Setups types
- Setups DB
- Moved some utils to a common place
RESOLVES CORE-1477
RESOLVES CORE-1476