Commit Graph

40 Commits

Author SHA1 Message Date
Stevche Radevski
68d869607f chore: Use module test runner in all modules (#6706)
I replaced the custom test setup with the test runner. This should make migrating to mikroorm 6 a lot easier once we do it.

There are few more modules to be done, but I thought the PR is super big already so we can tackle them separately.

Note that there are no or very little test changes, it is mostly the setup around the tests.
2024-03-14 21:01:50 +00:00
Riqwan Thamir
e5945479e0 feat(medusa,core-flows,types): adds update promotion rule endpoint + workflow (#6702)
what:

- adds endpoint + workflow to update promotion rule
- adds method in promotion to update promotion rules
2024-03-14 20:04:53 +00:00
Riqwan Thamir
04a532e5ef feat(core-flows,medusa,types): remove rules from promotion endpoints + workflows (#6696) 2024-03-14 09:19:05 +01:00
Riqwan Thamir
640eccd5dd feat(core-flows,medusa,types,utils): add rules to promotion endpoints + workflow (#6692)
* feat(core-flows,medusa,types,utils): add rules to promotion endpoints + workflow

* chore: fix specs

* chore: move input type to types package
2024-03-13 21:19:24 +01:00
Sebastian Rindom
a838ebae1b fix: make v2 with modules run (#6636) 2024-03-09 15:09:06 +00:00
Adrien de Peretti
e501e9effa chore: Run packages integration tests concurrently and not in band (#6576) 2024-03-04 14:17:07 +01:00
Riqwan Thamir
8dad2b51a2 feat(medusa-react,medusa,utils): add users/me endpoint + add missing specs (#6441)
**what:**

- adds /me endpoint
- adds fixes to routes
- adds specs for auth endpoint
- updates dotenv package versions


Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
2024-03-04 09:07:47 +00:00
Carlos R. L. Rodrigues
03ca5c814e feat(order): order change actions engine (#6467) 2024-02-29 16:22:14 -03:00
Riqwan Thamir
0b9fcb6324 feat(utils): consolidate promotion utils + refactor + fixes (#6531) 2024-02-29 12:52:46 +00:00
Riqwan Thamir
0d46abf0ff feat(types): promotion module uses big number (#6522)
what: 

- promotion modules (application method and campaign budget) uses big number fields instead of numeric fields
- refreshes the migrations to include new fields for big numbers
- adds a promotion_ prefix to promotion models
- uses `take: null` within the module to prevent the default pagination on performing actions within the module
2024-02-28 11:57:43 +00:00
Riqwan Thamir
ac86362e81 feat(workflows-sdk,core-flows,medusa,types): add workflow to update promotions to cart (#6474)
what:

- adds API + workflow to add/remove promotions in a cart
- minor fixes in promotions module
- minor type fixes in cart module
- typing fix in workflows-sdk (Thanks @adrien2p)
- fix step result in workflows-sdk (Thanks @adrien2p)

RESOLVES CORE-1768

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-02-26 12:43:57 +00:00
Adrien de Peretti
1d91b7429b feat(fulfillment): implementation part 2 (#6408)
**What**

> [!NOTE]  
> I can see this pr becoming huge, so I d like to get this partial one merged 👍 


- Fixes shared connection usage (mikro orm compare the instance to its own package and therefore was resulting in not trully reusing the provided connection leading to exhausting the connection pool as multiple connections was created and end up not being all destroyed properly under the hood, discovered in my integration tests)
- Create shipping options method implementation
- DTO's definition and service interface update
- integration tests 
- Re work of the indexes with new util update
- Test runner utils to remove a big chunk of the boilerplate of the packages integrations

FIXES CORE-1742
2024-02-19 12:33:46 +00:00
Adrien de Peretti
b91a1ca5b8 chore: cleanup inspection (#6358) 2024-02-09 14:40:09 +01:00
Carlos R. L. Rodrigues
884428a1b5 feat: event aggregator (#6218)
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
2024-02-05 11:59:10 +00:00
Adrien de Peretti
a7be5d7b6d chore: Abstract module service (#6188)
**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[]>
}
```
2024-02-02 14:20:32 +00:00
Riqwan Thamir
abc30517cb feat(): added percentage calculations for all cases (#6300)
what:

- adds missing percentage calculations for items and shipping methods
2024-02-02 11:39:34 +00:00
Carlos R. L. Rodrigues
45134e4d11 chore: local workflow proxying methods to pass context (#6263)
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.
2024-02-01 13:37:26 +00:00
Riqwan Thamir
e749dd653c feat(types): added computed actions for automatic promotions (#6272)
what:

- compute actions account for automatic promotions (RESOLVES CORE-1701)

RESOLVES CORE-1689
2024-01-31 12:30:33 +00:00
Riqwan Thamir
328eb85a8b feat(): added compute actions for buyget promotions (#6255)
what:

- computes actions for buyget promotion (RESOLVES CORE-1700)
2024-01-30 10:32:16 +00:00
Philip Korsholm
efd9204e26 Feat(medusa-test-utils, authentication, customer, cart, payment, pricing, product, promotion): Add initModule util (#6200)
* use initModules instead of initialize when runnning auth module integration tests

* rm unused module-config

* correct db schema fix

* update authentication integration tests w/ initModule

* update cart integration tests w/ initModule

* update customer integration tests w/ initModule

* update payment integration tests w/ initModule

* update pricing integration tests w/ initModule

* update product integration tests w/ initModule

* update promotion integration tests w/ initModule

* add initModule to more product tests and return medusaApp from initModule

* align moduleOptions naming

* update dependencies
2024-01-25 10:37:38 +08:00
Riqwan Thamir
68d8daccd2 feat(medusa,types): added buyget support for modules (#6159) 2024-01-23 21:01:44 +01:00
Carlos R. L. Rodrigues
d85fee42ee chore: use loaded module reference (#5763) 2024-01-23 08:31:02 -03:00
Riqwan Thamir
daecd82a7c feat(utils): update joiner config for campaigns (#6161) 2024-01-22 20:39:26 +01:00
Riqwan Thamir
99045848fd feat(medusa,types,core-flows,utils): added delete endpoints for campaigns and promotions (#6152)
what:

adds delete endpoints for:
- campaigns (RESOLVES CORE-1686)
- promotions (RESOLVES CORE-1680)
2024-01-22 13:06:49 +00:00
Riqwan Thamir
da5cc4cf7f feat(core-flows,medusa,utils): promotion and campaign create/update endpoint (#6130)
what:

- adds create endpoint for promotions including workflows and endpoint (RESOLVES CORE-1678)
- adds update endpoint for promotions including workflows and endpoint (RESOLVES CORE-1679)
- adds create endpoint for campaigns including workflows and endpoint (RESOLVES CORE-1684)
- adds update endpoint for campaigns including workflows and endpoint (RESOLVES CORE-1685)
2024-01-22 11:54:17 +00:00
Riqwan Thamir
af7af73745 feat(medusa,utils): added campaign get endpoints (#6125)
what:

adds endpoints for the following:

- list endpoint (RESOLVES CORE-1682)
- retrieve endpoint (RESOLVES CORE-1683)
2024-01-19 14:54:40 +00:00
Adrien de Peretti
5e655dd59b chore: Hide repository creation if they are not custom + add upsert support by default (#6127) 2024-01-19 15:09:38 +01:00
Riqwan Thamir
a12c28b7d5 feat(medusa,types): add promotion list/get endpoint (#6110)
what:

- adds get promotion endpoint (RESOLVES CORE-1677)
- adds list promotions endpoint (RESOLVES CORE-1676)
- uses new API routes
2024-01-18 16:01:19 +00:00
Adrien de Peretti
130c641e5c chore: Abstract module services (#6087)
**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>
2024-01-18 09:20:08 +00:00
Riqwan Thamir
68ddd866a5 feat(utils,types): add registerUsages for promotions + computeActions consider usage (#6094)
RESOLVES CORE-1639
RESOLVES CORE-1640
RESOLVES CORE-1634
2024-01-16 20:06:06 +00:00
Riqwan Thamir
e28fa7fbdf feat(utils): add campaign + promotion create / update (#6077)
* chore: add campaign + promotion operations

* chore: update type

* chore: added validation for campaign_id and campaign

* chore: added update promotions for campaigns

* chore: update campaign on promotion

* chore: fix lint

* chore: add test to remove promotions
2024-01-16 09:37:57 +01:00
Adrien de Peretti
72bc52231c chore(utils): Update base repository to infer primary keys and support composite (#6062) 2024-01-14 17:13:25 +01:00
Riqwan Thamir
fade8ea7bf feat(utils,types): campaigns and campaign budgets + services CRUD (#6063)
* chore: added item/shipping adjustments for order/items/shipping_methods

* chore: add validation for order type and target rules

* chore: add comment for applied promotions

* chore: add shipping method and item adjustments

* chore: include applied promotions to items/shipping_method for each case

* chore: handle case for items across and order to consider existing applications

* chore: handle case for applied promo values to shipping => across

* chore: added changeset

* chore: update return of function

* chore: campaigns and campaign budgets + services CRUD

* Apply suggestions from code review

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

* chore: minor refactor

* chore: added single/bulk interfaces

* Apply suggestions from code review

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>

* chore: use DAL date entity

* chore: align nullable

* Update packages/promotion/src/models/promotion-rule.ts

* chore: fix types

* chore: review changes

* Update packages/promotion/src/utils/compute-actions/shipping-methods.ts

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
2024-01-12 14:14:34 +01:00
Riqwan Thamir
b782d3bcb7 feat(utils,types): added item/shipping adjustments for order/items/shipping_methods (#6050)
what:

- adds compute actions for the following cases:
  - items => each & across
  - shipping_method => each & across
  - order
- adds a remove compute actions when code is no longer present in adjustments array

RESOLVES CORE-1625
RESOLVES CORE-1626
RESOLVES CORE-1627
RESOLVES CORE-1628
RESOLVES CORE-1585
2024-01-12 13:00:06 +00:00
Adrien de Peretti
b6ac768698 chore: abstract the modules repository (#6035)
**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>
2024-01-10 13:12:02 +00:00
Riqwan Thamir
dc46ee1189 feat(types): promotion delete / update / retrieve / add/remove-rules (#5988) 2024-01-05 16:17:22 +01:00
Riqwan Thamir
42cc8ae3f8 feat(types,utils): added promotion create with rules and application target rules (#5957)
* feat(types,utils): added promotion create with rules

* chore: add rules to promotion and application method

* chore: use common code for rule and values

* chore: address pr reviews

* chore: fix test
2024-01-03 09:54:48 +01:00
Philip Korsholm
d16d10619d Feat(medusa-test-utils, utils, pricing, product, link-modules): upgrade mikro orm version to latest (#5985)
* update mikro-orm version

* add changeset

* update product tests

* add optional number serializer util

* upgrade cart mikro-orm versions

* clean up test
2024-01-02 17:11:55 +01:00
Riqwan Thamir
890e76a5c5 feat(types,utils): add promotions create with application method (#5945)
What:

- Promotions can be created with its bare attributes
- Promotions one to one relationship with ApplicationMethod can be created with its attributes + validation

RESOLVES CORE-1592
RESOLVES CORE-1595
2023-12-21 11:04:50 +00:00
Riqwan Thamir
3f6d79961d feat(types,modules-sdk): basic module setup for promotions (#5920)
RESOLVES CORE-1580
2023-12-20 12:21:13 +00:00