From e78362c0007d2cd451f9fce1df973e5d0130890d Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Thu, 2 May 2024 20:07:42 +0200 Subject: [PATCH] chore: Remove legacy MWH modules (#7213) * chore: Remove legacy MWH modules * chore: Add stock-location deps --- .eslintrc.js | 1 + integration-tests/api/package.json | 2 +- integration-tests/plugins/package.json | 3 +- packages/inventory/CHANGELOG.md | 424 ---------- packages/inventory/jest.config.js | 13 - packages/inventory/package.json | 42 - packages/inventory/src/index.ts | 6 - packages/inventory/src/initialize/index.ts | 30 - packages/inventory/src/joiner-config.ts | 42 - packages/inventory/src/loaders/connection.ts | 51 -- packages/inventory/src/loaders/container.ts | 20 - packages/inventory/src/migrations/index.ts | 5 - .../inventory/src/migrations/run-migration.ts | 63 -- .../1665748086258-inventory_setup.ts | 83 -- ...75761451145-add_reservation_external_id.ts | 17 - ...7363119-item_descriptions_and_thumbnail.ts | 33 - .../1697708391459-scope-level-unique.ts | 19 - packages/inventory/src/models/index.ts | 3 - .../inventory/src/models/inventory-item.ts | 82 -- .../inventory/src/models/inventory-level.ts | 59 -- .../inventory/src/models/reservation-item.ts | 58 -- packages/inventory/src/module-definition.ts | 20 - packages/inventory/src/schema/index.ts | 55 -- packages/inventory/src/services/index.ts | 4 - .../inventory/src/services/inventory-item.ts | 240 ------ .../inventory/src/services/inventory-level.ts | 398 --------- packages/inventory/src/services/inventory.ts | 754 ------------------ .../src/services/reservation-item.ts | 340 -------- packages/inventory/src/types/index.ts | 12 - packages/inventory/src/utils/build-query.ts | 166 ---- packages/inventory/src/utils/query.ts | 92 --- packages/inventory/tsconfig.json | 27 - packages/inventory/tsconfig.spec.json | 5 - packages/modules-sdk/src/definitions.ts | 4 +- .../{inventory => modules/user}/.gitignore | 0 packages/{ => modules}/user/CHANGELOG.md | 0 packages/{ => modules}/user/README.md | 0 .../integration-tests/__fixtures__/invite.ts | 0 .../integration-tests/__fixtures__/user.ts | 0 .../__tests__/services/module/invite.spec.ts | 0 .../__tests__/services/module/user.spec.ts | 0 packages/{ => modules}/user/jest.config.js | 0 .../user/mikro-orm.config.dev.ts | 0 packages/{ => modules}/user/package.json | 0 packages/{ => modules}/user/src/index.ts | 0 .../user/src/initialize/index.ts | 0 .../{ => modules}/user/src/joiner-config.ts | 0 .../user/src/loaders/connection.ts | 0 .../user/src/loaders/container.ts | 0 .../user}/src/loaders/index.ts | 0 .../src/migrations/.snapshot-medusa-user.json | 0 .../src/migrations/Migration20240214033943.ts | 0 .../{ => modules}/user/src/models/index.ts | 0 .../{ => modules}/user/src/models/invite.ts | 0 .../{ => modules}/user/src/models/user.ts | 0 .../user/src/module-definition.ts | 0 .../user/src/repositories/index.ts | 0 .../user/src/scripts/bin/run-seed.ts | 0 .../{ => modules}/user/src/scripts/seed.ts | 0 .../{ => modules}/user/src/services/index.ts | 0 .../{ => modules}/user/src/services/invite.ts | 0 .../user/src/services/user-module.ts | 0 .../{ => modules}/user/src/types/index.ts | 0 .../user/src/types/services/index.ts | 0 .../user/src/types/services/invite.ts | 0 packages/{ => modules}/user/tsconfig.json | 0 .../{ => modules}/user/tsconfig.spec.json | 0 packages/stock-location/.gitignore | 6 - packages/stock-location/CHANGELOG.md | 263 ------ packages/stock-location/jest.config.js | 13 - packages/stock-location/package.json | 42 - packages/stock-location/src/index.ts | 6 - .../stock-location/src/initialize/index.ts | 30 - packages/stock-location/src/joiner-config.ts | 22 - .../stock-location/src/loaders/connection.ts | 50 -- .../stock-location/src/migrations/index.ts | 3 - .../src/migrations/run-migration.ts | 65 -- .../schema-migrations/1665749860179-setup.ts | 53 -- packages/stock-location/src/models/index.ts | 2 - .../src/models/stock-location-address.ts | 65 -- .../src/models/stock-location.ts | 50 -- .../stock-location/src/module-definition.ts | 19 - packages/stock-location/src/schema/index.ts | 29 - packages/stock-location/src/services/index.ts | 1 - .../src/services/stock-location.ts | 313 -------- packages/stock-location/src/types/index.ts | 12 - .../stock-location/src/utils/build-query.ts | 166 ---- packages/stock-location/tsconfig.json | 27 - packages/stock-location/tsconfig.spec.json | 5 - packages/user/.gitignore | 6 - packages/user/src/loaders/index.ts | 2 - yarn.lock | 43 +- 92 files changed, 23 insertions(+), 4443 deletions(-) delete mode 100644 packages/inventory/CHANGELOG.md delete mode 100644 packages/inventory/jest.config.js delete mode 100644 packages/inventory/package.json delete mode 100644 packages/inventory/src/index.ts delete mode 100644 packages/inventory/src/initialize/index.ts delete mode 100644 packages/inventory/src/joiner-config.ts delete mode 100644 packages/inventory/src/loaders/connection.ts delete mode 100644 packages/inventory/src/loaders/container.ts delete mode 100644 packages/inventory/src/migrations/index.ts delete mode 100644 packages/inventory/src/migrations/run-migration.ts delete mode 100644 packages/inventory/src/migrations/schema-migrations/1665748086258-inventory_setup.ts delete mode 100644 packages/inventory/src/migrations/schema-migrations/1675761451145-add_reservation_external_id.ts delete mode 100644 packages/inventory/src/migrations/schema-migrations/1682927363119-item_descriptions_and_thumbnail.ts delete mode 100644 packages/inventory/src/migrations/schema-migrations/1697708391459-scope-level-unique.ts delete mode 100644 packages/inventory/src/models/index.ts delete mode 100644 packages/inventory/src/models/inventory-item.ts delete mode 100644 packages/inventory/src/models/inventory-level.ts delete mode 100644 packages/inventory/src/models/reservation-item.ts delete mode 100644 packages/inventory/src/module-definition.ts delete mode 100644 packages/inventory/src/schema/index.ts delete mode 100644 packages/inventory/src/services/index.ts delete mode 100644 packages/inventory/src/services/inventory-item.ts delete mode 100644 packages/inventory/src/services/inventory-level.ts delete mode 100644 packages/inventory/src/services/inventory.ts delete mode 100644 packages/inventory/src/services/reservation-item.ts delete mode 100644 packages/inventory/src/types/index.ts delete mode 100644 packages/inventory/src/utils/build-query.ts delete mode 100644 packages/inventory/src/utils/query.ts delete mode 100644 packages/inventory/tsconfig.json delete mode 100644 packages/inventory/tsconfig.spec.json rename packages/{inventory => modules/user}/.gitignore (100%) rename packages/{ => modules}/user/CHANGELOG.md (100%) rename packages/{ => modules}/user/README.md (100%) rename packages/{ => modules}/user/integration-tests/__fixtures__/invite.ts (100%) rename packages/{ => modules}/user/integration-tests/__fixtures__/user.ts (100%) rename packages/{ => modules}/user/integration-tests/__tests__/services/module/invite.spec.ts (100%) rename packages/{ => modules}/user/integration-tests/__tests__/services/module/user.spec.ts (100%) rename packages/{ => modules}/user/jest.config.js (100%) rename packages/{ => modules}/user/mikro-orm.config.dev.ts (100%) rename packages/{ => modules}/user/package.json (100%) rename packages/{ => modules}/user/src/index.ts (100%) rename packages/{ => modules}/user/src/initialize/index.ts (100%) rename packages/{ => modules}/user/src/joiner-config.ts (100%) rename packages/{ => modules}/user/src/loaders/connection.ts (100%) rename packages/{ => modules}/user/src/loaders/container.ts (100%) rename packages/{inventory => modules/user}/src/loaders/index.ts (100%) rename packages/{ => modules}/user/src/migrations/.snapshot-medusa-user.json (100%) rename packages/{ => modules}/user/src/migrations/Migration20240214033943.ts (100%) rename packages/{ => modules}/user/src/models/index.ts (100%) rename packages/{ => modules}/user/src/models/invite.ts (100%) rename packages/{ => modules}/user/src/models/user.ts (100%) rename packages/{ => modules}/user/src/module-definition.ts (100%) rename packages/{ => modules}/user/src/repositories/index.ts (100%) rename packages/{ => modules}/user/src/scripts/bin/run-seed.ts (100%) rename packages/{ => modules}/user/src/scripts/seed.ts (100%) rename packages/{ => modules}/user/src/services/index.ts (100%) rename packages/{ => modules}/user/src/services/invite.ts (100%) rename packages/{ => modules}/user/src/services/user-module.ts (100%) rename packages/{ => modules}/user/src/types/index.ts (100%) rename packages/{ => modules}/user/src/types/services/index.ts (100%) rename packages/{ => modules}/user/src/types/services/invite.ts (100%) rename packages/{ => modules}/user/tsconfig.json (100%) rename packages/{ => modules}/user/tsconfig.spec.json (100%) delete mode 100644 packages/stock-location/.gitignore delete mode 100644 packages/stock-location/CHANGELOG.md delete mode 100644 packages/stock-location/jest.config.js delete mode 100644 packages/stock-location/package.json delete mode 100644 packages/stock-location/src/index.ts delete mode 100644 packages/stock-location/src/initialize/index.ts delete mode 100644 packages/stock-location/src/joiner-config.ts delete mode 100644 packages/stock-location/src/loaders/connection.ts delete mode 100644 packages/stock-location/src/migrations/index.ts delete mode 100644 packages/stock-location/src/migrations/run-migration.ts delete mode 100644 packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts delete mode 100644 packages/stock-location/src/models/index.ts delete mode 100644 packages/stock-location/src/models/stock-location-address.ts delete mode 100644 packages/stock-location/src/models/stock-location.ts delete mode 100644 packages/stock-location/src/module-definition.ts delete mode 100644 packages/stock-location/src/schema/index.ts delete mode 100644 packages/stock-location/src/services/index.ts delete mode 100644 packages/stock-location/src/services/stock-location.ts delete mode 100644 packages/stock-location/src/types/index.ts delete mode 100644 packages/stock-location/src/utils/build-query.ts delete mode 100644 packages/stock-location/tsconfig.json delete mode 100644 packages/stock-location/tsconfig.spec.json delete mode 100644 packages/user/.gitignore delete mode 100644 packages/user/src/loaders/index.ts diff --git a/.eslintrc.js b/.eslintrc.js index c202abdbf7..1c94190c22 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -132,6 +132,7 @@ module.exports = { "./packages/modules/workflow-engine-inmemory/tsconfig.spec.json", "./packages/modules/workflow-engine-redis/tsconfig.spec.json", "./packages/modules/link-modules/tsconfig.spec.json", + "./packages/modules/user/tsconfig.spec.json", ], }, rules: { diff --git a/integration-tests/api/package.json b/integration-tests/api/package.json index 79d19202f3..b80a9e1843 100644 --- a/integration-tests/api/package.json +++ b/integration-tests/api/package.json @@ -15,7 +15,7 @@ "@medusajs/cache-inmemory": "workspace:*", "@medusajs/customer": "workspace:^", "@medusajs/event-bus-local": "workspace:*", - "@medusajs/inventory": "workspace:^", + "@medusajs/inventory": "latest", "@medusajs/medusa": "workspace:*", "@medusajs/modules-sdk": "workspace:^", "@medusajs/pricing": "workspace:^", diff --git a/integration-tests/plugins/package.json b/integration-tests/plugins/package.json index 8b978a934c..d73a2741c5 100644 --- a/integration-tests/plugins/package.json +++ b/integration-tests/plugins/package.json @@ -15,7 +15,7 @@ "@medusajs/currency": "workspace:^", "@medusajs/customer": "workspace:^", "@medusajs/event-bus-local": "workspace:*", - "@medusajs/inventory": "workspace:^", + "@medusajs/inventory": "latest", "@medusajs/inventory-next": "workspace:^", "@medusajs/medusa": "workspace:*", "@medusajs/modules-sdk": "workspace:^", @@ -23,6 +23,7 @@ "@medusajs/product": "workspace:^", "@medusajs/promotion": "workspace:^", "@medusajs/region": "workspace:^", + "@medusajs/stock-location": "latest", "@medusajs/store": "workspace:^", "@medusajs/tax": "workspace:^", "@medusajs/user": "workspace:^", diff --git a/packages/inventory/CHANGELOG.md b/packages/inventory/CHANGELOG.md deleted file mode 100644 index 076ec4a09c..0000000000 --- a/packages/inventory/CHANGELOG.md +++ /dev/null @@ -1,424 +0,0 @@ -# @medusajs/inventory - -## 1.11.6 - -### Patch Changes - -- [#6263](https://github.com/medusajs/medusa/pull/6263) [`45134e4d1`](https://github.com/medusajs/medusa/commit/45134e4d11cfcdc08dbd10aae687bfbe9e848ab9) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Workflows passing MedusaContext as argument - -- [#6218](https://github.com/medusajs/medusa/pull/6218) [`884428a1b`](https://github.com/medusajs/medusa/commit/884428a1b573e499d7659aefed639bf797147428) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Feat: Event Aggregator - -- Updated dependencies [[`12054f5c0`](https://github.com/medusajs/medusa/commit/12054f5c01915899223ddc6da734151b31fbb23b), [`3db2f95e65`](https://github.com/medusajs/medusa/commit/3db2f95e65909f4fff432990b48be74509052e83), [`96ba49329`](https://github.com/medusajs/medusa/commit/96ba49329b6b05922c90f0c55f16455cb40aa5ca), [`45134e4d1`](https://github.com/medusajs/medusa/commit/45134e4d11cfcdc08dbd10aae687bfbe9e848ab9), [`884428a1b`](https://github.com/medusajs/medusa/commit/884428a1b573e499d7659aefed639bf797147428), [`882aa549b`](https://github.com/medusajs/medusa/commit/882aa549bdcc6f378934eab2a7c485df354f46aa)]: - - @medusajs/utils@1.11.5 - - @medusajs/modules-sdk@1.12.8 - -## 1.11.5 - -### Patch Changes - -- [#5763](https://github.com/medusajs/medusa/pull/5763) [`d85fee42e`](https://github.com/medusajs/medusa/commit/d85fee42ee7f661310584dfee5741d6c53b989bb) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Medusa App loading modules reference - -- [#6012](https://github.com/medusajs/medusa/pull/6012) [`192bc336cc`](https://github.com/medusajs/medusa/commit/192bc336cc2b6ec3820d94524c046dcd3c4ac7d9) Thanks [@olivermrbl](https://github.com/olivermrbl)! - feat(cart): Partial module service implementation - -- Updated dependencies [[`68ddd866a5`](https://github.com/medusajs/medusa/commit/68ddd866a5ff9414e2db5b80d75acc5e81948540), [`72bc52231c`](https://github.com/medusajs/medusa/commit/72bc52231ca3a72fa6d197a248fe07a938ed0d85), [`99045848f`](https://github.com/medusajs/medusa/commit/99045848fd3e863359c7878d9bc05271ed083a0e), [`a9b4214503`](https://github.com/medusajs/medusa/commit/a9b42145032ee88aa922a11fe03e777b140c68f4), [`d85fee42e`](https://github.com/medusajs/medusa/commit/d85fee42ee7f661310584dfee5741d6c53b989bb), [`5e655dd59`](https://github.com/medusajs/medusa/commit/5e655dd59bda4ffface28db38021ba71cae6de10), [`b782d3bcb7`](https://github.com/medusajs/medusa/commit/b782d3bcb7e8088a962584b9a55200dd29c2161c), [`2b9f98895e`](https://github.com/medusajs/medusa/commit/2b9f98895eaca255e01278674b11cd7cb69b388f), [`302323916`](https://github.com/medusajs/medusa/commit/302323916b6d8eaf571cd59b5fc92a913af207de), [`da5cc4cf7`](https://github.com/medusajs/medusa/commit/da5cc4cf7f7f0ef40d409704a95b025ce95477f4), [`daecd82a7`](https://github.com/medusajs/medusa/commit/daecd82a7cdf7315599f464999690414c20d6748), [`06b33a9b4`](https://github.com/medusajs/medusa/commit/06b33a9b4525b77b1b14b35b973209700945654e), [`b6ac768698`](https://github.com/medusajs/medusa/commit/b6ac768698a3b49d0162cb49e628386f3352d034), [`130c641e5c`](https://github.com/medusajs/medusa/commit/130c641e5c91cf831de64fb87aebbfdc4d23530d), [`fade8ea7bf`](https://github.com/medusajs/medusa/commit/fade8ea7bf560343ecbde116d226ac44053cdb8e), [`8472460f53`](https://github.com/medusajs/medusa/commit/8472460f533322cc4535199aa768ac163021bc79)]: - - @medusajs/utils@1.11.4 - - @medusajs/modules-sdk@1.12.7 - -## 1.11.4 - -### Patch Changes - -- [#5713](https://github.com/medusajs/medusa/pull/5713) [`18afe0b9a`](https://github.com/medusajs/medusa/commit/18afe0b9addb33ec2e3b285651b4eb1ef8065845) Thanks [@pKorsholm](https://github.com/pKorsholm)! - fix(stock-location, inventory, medusa, types, utils): allow buildQuery to take null as an argument in order to prevent default pagination - -- Updated dependencies [[`18afe0b9a`](https://github.com/medusajs/medusa/commit/18afe0b9addb33ec2e3b285651b4eb1ef8065845), [`de8f74867`](https://github.com/medusajs/medusa/commit/de8f748674bfd19b3dbadb9695d9080aa91940de), [`dc5750dd6`](https://github.com/medusajs/medusa/commit/dc5750dd665a91d35c0246ba83c7f90ec74907f4)]: - - @medusajs/utils@1.11.1 - - @medusajs/modules-sdk@1.12.4 - -# @medusajs/inventory - -## 1.11.3 - -### Patch Changes - -- [`c39bf69a5`](https://github.com/medusajs/medusa/commit/c39bf69a5e5cae75d7fa12aa6022b10903557a32) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Add missing version bumps - -- [#5543](https://github.com/medusajs/medusa/pull/5543) [`f90ba0208`](https://github.com/medusajs/medusa/commit/f90ba02087778d8131aed3a59a6dc9c8ca3c95f4) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(utils): Introduce promiseAll util - -- Updated dependencies [[`c39bf69a5`](https://github.com/medusajs/medusa/commit/c39bf69a5e5cae75d7fa12aa6022b10903557a32), [`154c9b43b`](https://github.com/medusajs/medusa/commit/154c9b43bde1fdff562aba9da8a79af2660b29b3)]: - - @medusajs/modules-sdk@1.12.3 - - @medusajs/utils@1.10.5 - -## 1.11.2 - -### Patch Changes - -- [#5468](https://github.com/medusajs/medusa/pull/5468) [`a45da9215`](https://github.com/medusajs/medusa/commit/a45da9215d2a7834c368037726aaa3961caadaf9) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(medusa, modules-sdk, modules): Module loading was missing the expected dependencies and remote query reference fix - -- Updated dependencies [[`a45da9215`](https://github.com/medusajs/medusa/commit/a45da9215d2a7834c368037726aaa3961caadaf9)]: - - @medusajs/modules-sdk@1.12.2 - -## 1.11.1 - -### Patch Changes - -- [#5301](https://github.com/medusajs/medusa/pull/5301) [`66413d094`](https://github.com/medusajs/medusa/commit/66413d094e916debbdb74b68800c96ca2c9302c9) Thanks [@srindom](https://github.com/srindom)! - fix: move create inventory workflow to @medusajs/workflows - -- Updated dependencies [[`378ca1b36`](https://github.com/medusajs/medusa/commit/378ca1b36e909a67e39c69ea5ca94ec58a345878), [`b62af612c`](https://github.com/medusajs/medusa/commit/b62af612c7baa244075e546c949b89c4589bd2cf), [`e47461d95`](https://github.com/medusajs/medusa/commit/e47461d95caecf3a447ee9fa0b0950340b93f282), [`66413d094`](https://github.com/medusajs/medusa/commit/66413d094e916debbdb74b68800c96ca2c9302c9)]: - - @medusajs/utils@1.10.4 - - @medusajs/modules-sdk@1.12.1 - -## 1.11.0 - -### Minor Changes - -- [#5242](https://github.com/medusajs/medusa/pull/5242) [`130cbc1f4`](https://github.com/medusajs/medusa/commit/130cbc1f437af211b6d05f80128d90138abcd38d) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Modules exporting schema with entities and fields - -### Patch Changes - -- Updated dependencies [[`eeceec791`](https://github.com/medusajs/medusa/commit/eeceec791c141996cf7fd06555afb6e738b52840), [`130cbc1f4`](https://github.com/medusajs/medusa/commit/130cbc1f437af211b6d05f80128d90138abcd38d), [`cb569c2df`](https://github.com/medusajs/medusa/commit/cb569c2dfe2d83e1ff72a49f2331450a83b73325)]: - - @medusajs/utils@1.10.3 - - @medusajs/modules-sdk@1.12.0 - -## 1.10.0 - -### Minor Changes - -- [#4695](https://github.com/medusajs/medusa/pull/4695) [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - introduce @medusajs/link-modules - -### Patch Changes - -- Updated dependencies [[`c3dba0694`](https://github.com/medusajs/medusa/commit/c3dba069488952945150117a30b1306a2e0bb3ce), [`460161a69`](https://github.com/medusajs/medusa/commit/460161a69f22cf6d561952e92e7d9b56912113e6), [`fcb6b4f51`](https://github.com/medusajs/medusa/commit/fcb6b4f510dba2757570625acb5da9476b7544fd), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`87bade096`](https://github.com/medusajs/medusa/commit/87bade096e3d536f29ddc57dbc4c04e5d7a46e4b), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`a4906d0ac`](https://github.com/medusajs/medusa/commit/a4906d0ac0af36b1382d3befe64281b404387bd7)]: - - @medusajs/modules-sdk@1.10.0 - - @medusajs/utils@1.10.0 - -## 1.9.2 - -### Patch Changes - -- [#4503](https://github.com/medusajs/medusa/pull/4503) [`d184d23c6`](https://github.com/medusajs/medusa/commit/d184d23c6384d5f8bf52827826b62c6bef37f884) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(medusa,inventory,types,brightpearl): update some inventory methods to be bulk-operation enabled - -## 1.9.1 - -### Patch Changes - -- [#4211](https://github.com/medusajs/medusa/pull/4211) [`d76ba0cd2`](https://github.com/medusajs/medusa/commit/d76ba0cd29694c2e31f9f89992a9fbc14659c1ae) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(medusa): Order edit missing transaction when consuming the inventory module - -- [#4232](https://github.com/medusajs/medusa/pull/4232) [`af2dc4f75`](https://github.com/medusajs/medusa/commit/af2dc4f75a2ed109495ca83b1bc6ae6941c2f716) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(medusa, inventory, stock-location): Remove unnecessary transaction usage in the modules and list products end points - -- [#4276](https://github.com/medusajs/medusa/pull/4276) [`afd1b67f1`](https://github.com/medusajs/medusa/commit/afd1b67f1c7de8cf07fd9fcbdde599a37914e9b5) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Use caret range - -- Updated dependencies [[`f98ba5bde`](https://github.com/medusajs/medusa/commit/f98ba5bde83ba785eead31b0c9eb9f135d664178), [`14c0f62f8`](https://github.com/medusajs/medusa/commit/14c0f62f84704a4c87beff3daaff60a52f5c88b8)]: - - @medusajs/utils@1.9.1 - - @medusajs/modules-sdk@1.8.8 - -## 1.9.0 - -### Minor Changes - -- [#4146](https://github.com/medusajs/medusa/pull/4146) [`db4199530`](https://github.com/medusajs/medusa/commit/db419953075e0907b8c4d27ab5188e9bd3e3d72b) Thanks [@fPolic](https://github.com/fPolic)! - chore(medusa, utils, inventory, stock-location): clear deps in the utils package - -### Patch Changes - -- [#4154](https://github.com/medusajs/medusa/pull/4154) [`0a35f21af`](https://github.com/medusajs/medusa/commit/0a35f21af7ac8b6cdc1af12a403e95f9bf6142fe) Thanks [@pKorsholm](https://github.com/pKorsholm)! - Feat(medusa,inventory): search inventory items based on title and description - -- [#3979](https://github.com/medusajs/medusa/pull/3979) [`3a38c84f8`](https://github.com/medusajs/medusa/commit/3a38c84f88b05f74ee0a172af3e3f78b2ec8c2d2) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(client-types, inventory, medusa, types): add additional filtering capabilities to list-reservations - -- [#4155](https://github.com/medusajs/medusa/pull/4155) [`5c01b4e6b`](https://github.com/medusajs/medusa/commit/5c01b4e6b66f2e6d6be12fc1e75940236ebbcb08) Thanks [@pKorsholm](https://github.com/pKorsholm)! - fix(inventory): update revert migration - -- Updated dependencies [[`a91987fab`](https://github.com/medusajs/medusa/commit/a91987fab33745f9864eab21bd1c27e8e3e24571), [`e73c3e51c`](https://github.com/medusajs/medusa/commit/e73c3e51c9cd192eeae7a57b24b07bd466214145), [`db4199530`](https://github.com/medusajs/medusa/commit/db419953075e0907b8c4d27ab5188e9bd3e3d72b), [`c0e527d6e`](https://github.com/medusajs/medusa/commit/c0e527d6e0a67d0c53577a0b9c3d16ee8dc5740f)]: - - @medusajs/utils@1.9.0 - - @medusajs/modules-sdk@1.8.7 - -## 1.8.6 - -### Patch Changes - -- [#4072](https://github.com/medusajs/medusa/pull/4072) [`6511959e2`](https://github.com/medusajs/medusa/commit/6511959e23177f3b4831915db0e8e788bc9047fa) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Revert to official Typeorm package - -- Updated dependencies [[`cdbac2c84`](https://github.com/medusajs/medusa/commit/cdbac2c8403a3c15c0e11993f6b7dab268fa5c08), [`6511959e2`](https://github.com/medusajs/medusa/commit/6511959e23177f3b4831915db0e8e788bc9047fa)]: - - @medusajs/utils@1.8.5 - - @medusajs/modules-sdk@1.8.6 - -## 1.8.5 - -### Patch Changes - -- [#3971](https://github.com/medusajs/medusa/pull/3971) [`7fd22ecb4`](https://github.com/medusajs/medusa/commit/7fd22ecb4d5190e92c6750a9fbf2d8534bb9f4ab) Thanks [@pKorsholm](https://github.com/pKorsholm)! - Feat(client-types, inventory, medusa, types): add `title`, `thumbnail` and `description to inventory item and `description` to reservation item. - -- Updated dependencies [[`1ea57c3a6`](https://github.com/medusajs/medusa/commit/1ea57c3a69a5377a8dd0821df819743ded4a222b)]: - - @medusajs/utils@1.8.4 - - @medusajs/modules-sdk@1.8.5 - -## 1.8.4 - -### Patch Changes - -- [#3981](https://github.com/medusajs/medusa/pull/3981) [`d539c6fee`](https://github.com/medusajs/medusa/commit/d539c6feeba8ee431f9a655b6cd4e9102cba2b25) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Bump Typeorm to Medusa fork - -- Updated dependencies [[`0e488e71b`](https://github.com/medusajs/medusa/commit/0e488e71b186f7d08b18c4c6ba409ef3cadb8152), [`d539c6fee`](https://github.com/medusajs/medusa/commit/d539c6feeba8ee431f9a655b6cd4e9102cba2b25)]: - - @medusajs/utils@1.8.3 - - @medusajs/modules-sdk@1.8.4 - -## 1.8.3 - -### Patch Changes - -- [#3863](https://github.com/medusajs/medusa/pull/3863) [`cd2d4f645`](https://github.com/medusajs/medusa/commit/cd2d4f6455e7db2f9aa4f7aec72baa25fad786ff) Thanks [@olivermrbl](https://github.com/olivermrbl)! - fix(inventory): Add missing context arguments - -- [#3835](https://github.com/medusajs/medusa/pull/3835) [`af710f1b4`](https://github.com/medusajs/medusa/commit/af710f1b48a4545a5064029a557013af34c4c100) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(medusa): Bulk create variant and pass transaction to the inventory service context methods - -- [#3192](https://github.com/medusajs/medusa/pull/3192) [`4a8562743`](https://github.com/medusajs/medusa/commit/4a8562743569f5bbb7bd0894b025a74725726529) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(medusa-plugin-brightpearl, inventory, medusa): Multiwarehouse integration for brightpearl - -- Updated dependencies [[`af710f1b4`](https://github.com/medusajs/medusa/commit/af710f1b48a4545a5064029a557013af34c4c100), [`491566df6`](https://github.com/medusajs/medusa/commit/491566df6b7ced35f655f810961422945e10ecd0)]: - - @medusajs/utils@1.8.2 - - @medusajs/modules-sdk@1.8.3 - -## 1.8.2 - -### Patch Changes - -- Updated dependencies []: - - @medusajs/modules-sdk@1.8.2 - -## 1.8.1 - -### Patch Changes - -- [#3778](https://github.com/medusajs/medusa/pull/3778) [`654a54622`](https://github.com/medusajs/medusa/commit/654a54622303139e7180538bd686630ad9a46cfd) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Bump Typeorm - -- Updated dependencies [[`654a54622`](https://github.com/medusajs/medusa/commit/654a54622303139e7180538bd686630ad9a46cfd), [`abdb74d99`](https://github.com/medusajs/medusa/commit/abdb74d997f49f994bff49787a396179982843b0)]: - - @medusajs/utils@1.8.1 - - @medusajs/modules-sdk@1.8.1 - -## 1.8.0 - -### Minor Changes - -- [#3329](https://github.com/medusajs/medusa/pull/3329) [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Inventory and Stock location modules supporting isolated connection - -### Patch Changes - -- [#3319](https://github.com/medusajs/medusa/pull/3319) [`08c8aa46c`](https://github.com/medusajs/medusa/commit/08c8aa46c55453cf741a97d06547ae85fee6e985) Thanks [@pKorsholm](https://github.com/pKorsholm)! - List inventory items based on locations - -- [#3041](https://github.com/medusajs/medusa/pull/3041) [`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724) Thanks [@riqwan](https://github.com/riqwan)! - chore(medusa): Typeorm fixes / enhancements - - - upgrade typeorm from 0.2.51 to 0.3.11 - - Plugin repository loader to work with Typeorm update - -- [#3685](https://github.com/medusajs/medusa/pull/3685) [`8ddb3952c`](https://github.com/medusajs/medusa/commit/8ddb3952c045e6c05c8d0f6922f0d4ba30cf3bd4) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Fix RC package versions - -- [#3352](https://github.com/medusajs/medusa/pull/3352) [`aa690beed`](https://github.com/medusajs/medusa/commit/aa690beed775646cbc86b445fb5dc90dcac087d5) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - feat(medusa): Modules initializer - - ### Loading modules in a project - - Example - - ```typescript - import { - InventoryServiceInitializeOptions, - initialize, - } from "@medusajs/inventory" - - const options: InventoryServiceInitializeOptions = { - database: { - type: "postgres", - url: DB_URL, - }, - } - - const inventoryService = await initialize(options) - const newInventoryItem = await inventoryService.createInventoryItem({ - sku: "sku_123", - }) - ``` - -- [#3460](https://github.com/medusajs/medusa/pull/3460) [`10bf05c14`](https://github.com/medusajs/medusa/commit/10bf05c147cb65a263465129790edd44a6d8948b) Thanks [@pKorsholm](https://github.com/pKorsholm)! - Fix(inventory, medusa): ensure no orphaned reservations and invenotry levels on location removal - -- [#3649](https://github.com/medusajs/medusa/pull/3649) [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Export initialize method for all modules - -- [#3531](https://github.com/medusajs/medusa/pull/3531) [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Remove dependency on @medusajs/medusa from Inventory and Stock-Location Modules - -- Updated dependencies [[`8ddb3952c`](https://github.com/medusajs/medusa/commit/8ddb3952c045e6c05c8d0f6922f0d4ba30cf3bd4), [`a0c919a8d`](https://github.com/medusajs/medusa/commit/a0c919a8d01ca5edf62336de48e9a112e3822f38), [`55e94d0b4`](https://github.com/medusajs/medusa/commit/55e94d0b45776776639d3970d4264b8f5c5385dd), [`74bc4b16a`](https://github.com/medusajs/medusa/commit/74bc4b16a07f78668003ca930bf2a0d928897ceb), [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b), [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73), [`bca1f80dd`](https://github.com/medusajs/medusa/commit/bca1f80dd501d878455e1ad4f5091cf20ef900ea), [`271844aed`](https://github.com/medusajs/medusa/commit/271844aedbe45c369e188b5d06458dbd6984cd39), [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def)]: - - @medusajs/modules-sdk@1.8.0 - - @medusajs/utils@1.8.0 - -## 1.8.0-rc.4 - -### Patch Changes - -- [#3649](https://github.com/medusajs/medusa/pull/3649) [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Export initialize method for all modules - -- Updated dependencies [[`a0c919a8d`](https://github.com/medusajs/medusa/commit/a0c919a8d01ca5edf62336de48e9a112e3822f38), [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b)]: - - @medusajs/utils@0.0.2-rc.2 - - @medusajs/modules-sdk@0.1.0-rc.4 - -## 1.8.0-rc.3 - -### Patch Changes - -- Updated dependencies [[`55e94d0b4`](https://github.com/medusajs/medusa/commit/55e94d0b45776776639d3970d4264b8f5c5385dd)]: - - @medusajs/modules-sdk@0.1.0-rc.3 - -## 1.8.0-rc.2 - -### Patch Changes - -- chore: Fix RC package versions - -- Updated dependencies []: - - @medusajs/modules-sdk@0.1.0-rc.2 - - @medusajs/utils@0.0.2-rc.1 - -## 1.8.0-rc.1 - -### Patch Changes - -- Updated dependencies [[`bca1f80dd`](https://github.com/medusajs/medusa/commit/bca1f80dd501d878455e1ad4f5091cf20ef900ea)]: - - @medusajs/modules-sdk@0.1.0-rc.1 - -## 1.8.0-rc.0 - -### Minor Changes - -- [#3329](https://github.com/medusajs/medusa/pull/3329) [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Inventory and Stock location modules supporting isolated connection - -### Patch Changes - -- [#3319](https://github.com/medusajs/medusa/pull/3319) [`08c8aa46c`](https://github.com/medusajs/medusa/commit/08c8aa46c55453cf741a97d06547ae85fee6e985) Thanks [@pKorsholm](https://github.com/pKorsholm)! - List inventory items based on locations - -- [#3041](https://github.com/medusajs/medusa/pull/3041) [`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724) Thanks [@riqwan](https://github.com/riqwan)! - chore(medusa): Typeorm fixes / enhancements - - - upgrade typeorm from 0.2.51 to 0.3.11 - - Plugin repository loader to work with Typeorm update - -- [#3352](https://github.com/medusajs/medusa/pull/3352) [`aa690beed`](https://github.com/medusajs/medusa/commit/aa690beed775646cbc86b445fb5dc90dcac087d5) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - feat(medusa): Modules initializer - - ### Loading modules in a project - - Example - - ```typescript - import { - InventoryServiceInitializeOptions, - initialize, - } from "@medusajs/inventory" - - const options: InventoryServiceInitializeOptions = { - database: { - type: "postgres", - url: DB_URL, - }, - } - - const inventoryService = await initialize(options) - const newInventoryItem = await inventoryService.createInventoryItem({ - sku: "sku_123", - }) - ``` - -- [#3460](https://github.com/medusajs/medusa/pull/3460) [`10bf05c14`](https://github.com/medusajs/medusa/commit/10bf05c147cb65a263465129790edd44a6d8948b) Thanks [@pKorsholm](https://github.com/pKorsholm)! - Fix(inventory, medusa): ensure no orphaned reservations and invenotry levels on location removal - -- [#3531](https://github.com/medusajs/medusa/pull/3531) [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Remove dependency on @medusajs/medusa from Inventory and Stock-Location Modules - -- Updated dependencies [[`74bc4b16a`](https://github.com/medusajs/medusa/commit/74bc4b16a07f78668003ca930bf2a0d928897ceb), [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73), [`271844aed`](https://github.com/medusajs/medusa/commit/271844aedbe45c369e188b5d06458dbd6984cd39), [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def)]: - - @medusajs/utils@0.0.2-rc.0 - - @medusajs/modules-sdk@0.1.0-rc.0 - -## 1.0.12 - -### Patch Changes - -- Updated dependencies [[`98fe8fd00`](https://github.com/medusajs/medusa/commit/98fe8fd00a1912fde1d2a93b434bda500a213c14), [`2869763ea`](https://github.com/medusajs/medusa/commit/2869763ea9673cf5c5a3aa10b58f61b8e830ce21)]: - - @medusajs/medusa@1.7.15 - -## 1.0.11 - -### Patch Changes - -- Updated dependencies [[`902ed3c0b`](https://github.com/medusajs/medusa/commit/902ed3c0b21cd525d9975e59b7a8120ae5f7a895), [`fa4049cb5`](https://github.com/medusajs/medusa/commit/fa4049cb51232b2ed7091b1322c3fc14cd23e451)]: - - @medusajs/medusa@1.7.14 - -## 1.0.10 - -### Patch Changes - -- [#3407](https://github.com/medusajs/medusa/pull/3407) [`f0a1355fe`](https://github.com/medusajs/medusa/commit/f0a1355feb5160ff7de1f3d3da769efe29d0d8ed) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(medusa): Bulk emit events - -- Updated dependencies [[`601d20e7a`](https://github.com/medusajs/medusa/commit/601d20e7ab293728cd81f0723805841016812120), [`f0a1355fe`](https://github.com/medusajs/medusa/commit/f0a1355feb5160ff7de1f3d3da769efe29d0d8ed)]: - - @medusajs/medusa@1.7.13 - -## 1.0.9 - -### Patch Changes - -- Updated dependencies [[`ce577f269`](https://github.com/medusajs/medusa/commit/ce577f2696aa2181bef8f3096b1a639feabe2714), [`aa0d1f321`](https://github.com/medusajs/medusa/commit/aa0d1f32153f82c6219efe5cfc08862db5e5a129), [`9f508c8bd`](https://github.com/medusajs/medusa/commit/9f508c8bd8bee63677504cc8b86f1643579945d8)]: - - @medusajs/medusa@1.7.12 - -## 1.0.8 - -### Patch Changes - -- Updated dependencies [[`c43248131`](https://github.com/medusajs/medusa/commit/c432481319cc205938081c3fcf60e75053b659ca)]: - - @medusajs/medusa@1.7.11 - -## 1.0.7 - -### Patch Changes - -- Updated dependencies [[`b458615ed`](https://github.com/medusajs/medusa/commit/b458615ed50a7c637e9e77f29f21c7ab300ed5d8), [`4b114cc41`](https://github.com/medusajs/medusa/commit/4b114cc4191ba20832b66072ec82386b22a3533c)]: - - @medusajs/medusa@1.7.10 - -## 1.0.6 - -### Patch Changes - -- Updated dependencies [[`370bd472e`](https://github.com/medusajs/medusa/commit/370bd472ed8c9038f66defd012a886e0f83c32cf)]: - - @medusajs/medusa@1.7.9 - -## 1.0.5 - -### Patch Changes - -- Updated dependencies [[`9690f07bc`](https://github.com/medusajs/medusa/commit/9690f07bc062c85fcf8b7f0f35a162b930944183), [`5301a1e9d`](https://github.com/medusajs/medusa/commit/5301a1e9d632ddac94e7864fecfdc860a4c2a66d), [`d11ab924b`](https://github.com/medusajs/medusa/commit/d11ab924b88211bc18ed019ca300f6d452972167), [`f88af0c28`](https://github.com/medusajs/medusa/commit/f88af0c28d3fa574cdeea3694607d4df563cb88d)]: - - @medusajs/medusa@1.7.8 - -## 1.0.4 - -### Patch Changes - -- [#3217](https://github.com/medusajs/medusa/pull/3217) [`8c5219a31`](https://github.com/medusajs/medusa/commit/8c5219a31ef76ee571fbce84d7d57a63abe56eb0) Thanks [@adrien2p](https://github.com/adrien2p)! - chore: Fix npm packages files included - -- Updated dependencies [[`507ad00be`](https://github.com/medusajs/medusa/commit/507ad00bec74bb63b17eae8a4a3313eb6e0d2503), [`6e443dc70`](https://github.com/medusajs/medusa/commit/6e443dc708ffe20bf96d45ddc207ed274c28e344), [`eee928381`](https://github.com/medusajs/medusa/commit/eee9283818b1717f37f084c319201ea7144fdf8a), [`4cb44a3a2`](https://github.com/medusajs/medusa/commit/4cb44a3a2ec5bcf3d90e3b6a0e1f6bb9ff45e2b6), [`472f96d7f`](https://github.com/medusajs/medusa/commit/472f96d7fb8668a15df6e6f9ea31291891b3e688), [`61b0b2f3a`](https://github.com/medusajs/medusa/commit/61b0b2f3aa1d54d539b216a99032549485136a82), [`80452332d`](https://github.com/medusajs/medusa/commit/80452332d852ad7d33d74e1f08f12f45d7a35503), [`bbbb3d888`](https://github.com/medusajs/medusa/commit/bbbb3d888292391976355c88ecb0fcf8a7c115bc), [`10ff72c30`](https://github.com/medusajs/medusa/commit/10ff72c30ae59d2174d876b0c4141aad135d9a1c), [`968eb8fc6`](https://github.com/medusajs/medusa/commit/968eb8fc6b7ccd7221f88f42d75717f3a0547861), [`a59bd84e4`](https://github.com/medusajs/medusa/commit/a59bd84e41fb5d8fc2edc7bdc43d3cbf74d9d7dc), [`8c5219a31`](https://github.com/medusajs/medusa/commit/8c5219a31ef76ee571fbce84d7d57a63abe56eb0), [`cac13a88d`](https://github.com/medusajs/medusa/commit/cac13a88da42fa986bd7352fbc12a318b566d98f), [`a2cc084db`](https://github.com/medusajs/medusa/commit/a2cc084db817f8f7699e9b0daceda274b5f0e0c0), [`8194d19b0`](https://github.com/medusajs/medusa/commit/8194d19b0e933310fdc65af25300da5dd185e669)]: - - @medusajs/medusa@1.7.7 - - medusa-interfaces@1.3.6 - -## 1.0.3 - -### Patch Changes - -- [#2971](https://github.com/medusajs/medusa/pull/2971) [`f65f590a2`](https://github.com/medusajs/medusa/commit/f65f590a2771d6e526d7dfc7ca721be74c8f79a9) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Adding inventory items api - -- [#3185](https://github.com/medusajs/medusa/pull/3185) [`08324355a`](https://github.com/medusajs/medusa/commit/08324355a4466b017a0bc7ab1d333ee3cd27b8c4) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Patches all dependencies + minor bumps `winston` to include a [fix for a significant memory leak](https://github.com/winstonjs/winston/pull/2057) - -- Updated dependencies [[`ce866475b`](https://github.com/medusajs/medusa/commit/ce866475b4b6c8b453638000f7b1df7a27daf45d), [`53532df8d`](https://github.com/medusajs/medusa/commit/53532df8d597ed5471c07296981b6959cba4ddc3), [`d8ffbe25b`](https://github.com/medusajs/medusa/commit/d8ffbe25b047fda0f644240c9f518f95e74f03cb), [`2d525237b`](https://github.com/medusajs/medusa/commit/2d525237b682e89495b6cc8e3aa677bfad4d0726), [`5b63533c7`](https://github.com/medusajs/medusa/commit/5b63533c77528cab31755cedab9e768f7461f373), [`09dc9c667`](https://github.com/medusajs/medusa/commit/09dc9c6677c0d64cf765b27290e707ea75edd4aa), [`4105405f2`](https://github.com/medusajs/medusa/commit/4105405f28c3f3e54a6077c95a575a268fb5569f), [`ee42b60a2`](https://github.com/medusajs/medusa/commit/ee42b60a20db2afc5e9b6b958502f9e86ec37d80), [`d0adaf57e`](https://github.com/medusajs/medusa/commit/d0adaf57ed1018f29bebf01e5cffde5f7192f89f), [`f65f590a2`](https://github.com/medusajs/medusa/commit/f65f590a2771d6e526d7dfc7ca721be74c8f79a9), [`5ec6d438f`](https://github.com/medusajs/medusa/commit/5ec6d438fb1f909be925461c788f3a3a958528e4), [`5c1d2a5e8`](https://github.com/medusajs/medusa/commit/5c1d2a5e83c3654ae468d17c900892c32ef76060), [`8e41c6996`](https://github.com/medusajs/medusa/commit/8e41c6996601142661bde877b9ee1d80b8325f5f), [`d50db84a3`](https://github.com/medusajs/medusa/commit/d50db84a336da2de9c06a59aa79f2a5e9aa558f1), [`82da3605f`](https://github.com/medusajs/medusa/commit/82da3605fb50cef182699900552109ad654f0df2), [`b242e2232`](https://github.com/medusajs/medusa/commit/b242e22326ce74d5437d0da6863f22facbb5964c), [`4339d47e1`](https://github.com/medusajs/medusa/commit/4339d47e1f6c9f6c8f100b3ac72c8a394b6dd44d), [`2e7e16b91`](https://github.com/medusajs/medusa/commit/2e7e16b9173e2779946776b9b07ce7232c683f36), [`9ebb50104`](https://github.com/medusajs/medusa/commit/9ebb50104cc1f6c8ef1cea446ae595fb2eb532a2), [`08324355a`](https://github.com/medusajs/medusa/commit/08324355a4466b017a0bc7ab1d333ee3cd27b8c4), [`e22a383f4`](https://github.com/medusajs/medusa/commit/e22a383f4738e8bc80394ccaba3ac9a4ae678955), [`dc156861d`](https://github.com/medusajs/medusa/commit/dc156861d413ecfe3fd264bcd5ad736d83d8a08e), [`8f4c84121`](https://github.com/medusajs/medusa/commit/8f4c84121bd9b8c7067d72f03125e13afe4d2571), [`bfa33f444`](https://github.com/medusajs/medusa/commit/bfa33f444cd225906149777c5c6e842685f3dd7c), [`f776ed234`](https://github.com/medusajs/medusa/commit/f776ed234fcfccf23041ffebecbae6c9a8b7e922), [`4d6e63d68`](https://github.com/medusajs/medusa/commit/4d6e63d68f4e64c365ecbba133876d95e6528763), [`fcba70570`](https://github.com/medusajs/medusa/commit/fcba705701b8013183fafb39e8dda4a85718080a), [`4f0d8992a`](https://github.com/medusajs/medusa/commit/4f0d8992a091a05e93dd5be3762dfa47f074610e), [`d25a53104`](https://github.com/medusajs/medusa/commit/d25a531045143d3be68d3cd3b5764bbbc792ee3a), [`86c87c7b1`](https://github.com/medusajs/medusa/commit/86c87c7b1020ab6bb02f931e1ee113f2857cf527), [`78650ea66`](https://github.com/medusajs/medusa/commit/78650ea66517b0a77100228615d8122f84ad235b), [`b9bda3bf4`](https://github.com/medusajs/medusa/commit/b9bda3bf4e0f95675041085cea5008268c37edd5), [`e581d3bd9`](https://github.com/medusajs/medusa/commit/e581d3bd90f9bc40105e7eaf34e0c94d4f657f7a), [`4d3210bfb`](https://github.com/medusajs/medusa/commit/4d3210bfbb84877d951f7319d2e87c1acbdd6aad)]: - - @medusajs/medusa@1.7.6 - - medusa-interfaces@1.3.5 - -## 1.0.2 - -### Patch Changes - -- Updated dependencies [[`9c2169422`](https://github.com/medusajs/medusa/commit/9c2169422dd51be727118fa4830dadc58c24568a), [`9427bc7f2`](https://github.com/medusajs/medusa/commit/9427bc7f256c563befe3035bc3d67380066f304b)]: - - @medusajs/medusa@1.7.5 - -## 1.0.1 - -### Patch Changes - -- [#2997](https://github.com/medusajs/medusa/pull/2997) [`9dbccd9ca`](https://github.com/medusajs/medusa/commit/9dbccd9ca78b8b66f9a21947bb863622e7ff326b) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - feat(medusa, stock-location, inventory): Allow modules to integrate with core - -- [#3033](https://github.com/medusajs/medusa/pull/3033) [`1547dd814`](https://github.com/medusajs/medusa/commit/1547dd8143889fc30045fc3d0241de8e69acb76e) Thanks [@olivermrbl](https://github.com/olivermrbl)! - fix(medusa): Add module options to transaction base service to use in modules - -- Updated dependencies [[`9dbccd9ca`](https://github.com/medusajs/medusa/commit/9dbccd9ca78b8b66f9a21947bb863622e7ff326b), [`542daeead`](https://github.com/medusajs/medusa/commit/542daeeadd78d939f5144c690e8907374da6d085), [`8c08d0031`](https://github.com/medusajs/medusa/commit/8c08d003198b94c00f8428a51c0e79d2ca9d1dc7), [`017538883`](https://github.com/medusajs/medusa/commit/017538883588792e1ff37abcab0fd2872c9af932), [`b2839e2e4`](https://github.com/medusajs/medusa/commit/b2839e2e4dc0d9344fa2ac8d4d16b796def4c56d), [`76d175231`](https://github.com/medusajs/medusa/commit/76d17523105d3860028a90a45b6038a64040e5ce), [`9e3beaf53`](https://github.com/medusajs/medusa/commit/9e3beaf5319dc785cf84b856cfcc8193df90c3a4), [`7d4b8b9cc`](https://github.com/medusajs/medusa/commit/7d4b8b9cc59672d01cdf0c6f331bc3d1eeec9bee), [`aab163bab`](https://github.com/medusajs/medusa/commit/aab163babb91759a05b852d34c299cdfac96d800), [`a0c4cfe0f`](https://github.com/medusajs/medusa/commit/a0c4cfe0f74cf30c45956c32c2fb22bf833bea68), [`27a29ef24`](https://github.com/medusajs/medusa/commit/27a29ef24e5ea1ba2bc0be8ecb7dd747d4c7c65b), [`aef842123`](https://github.com/medusajs/medusa/commit/aef8421235d8fff68d7d4f8b73f77484073311a5), [`1dc79590b`](https://github.com/medusajs/medusa/commit/1dc79590b3539af09dbc8fbf931d9b5ee225fb0d), [`9c4647383`](https://github.com/medusajs/medusa/commit/9c4647383ebf0a183ccc566636bcf7af06409060), [`a0c4cfe0f`](https://github.com/medusajs/medusa/commit/a0c4cfe0f74cf30c45956c32c2fb22bf833bea68), [`b80124d32`](https://github.com/medusajs/medusa/commit/b80124d32d950790c2a01b49e8c34d562b1d57f4), [`cb1ec0076`](https://github.com/medusajs/medusa/commit/cb1ec0076b4fd932c686d6027e8b060ceded3a64), [`142c8aa70`](https://github.com/medusajs/medusa/commit/142c8aa70f583d9b11a6add2b8f988e9ba4cf979), [`1547dd814`](https://github.com/medusajs/medusa/commit/1547dd8143889fc30045fc3d0241de8e69acb76e), [`d2c692aa9`](https://github.com/medusajs/medusa/commit/d2c692aa96ea89c053f9a694a9ae6dba77e89b14), [`150696de9`](https://github.com/medusajs/medusa/commit/150696de99fc852c5d72a746f168b6f62b2086ed), [`93d0dc1bd`](https://github.com/medusajs/medusa/commit/93d0dc1bdcb54cf6e87428a7bb9b0dac196b4de2), [`b3e4be720`](https://github.com/medusajs/medusa/commit/b3e4be72087d0b528c3cce322edf9325b855c8ae)]: - - @medusajs/medusa@1.7.4 - - medusa-interfaces@1.3.4 diff --git a/packages/inventory/jest.config.js b/packages/inventory/jest.config.js deleted file mode 100644 index bddd3c8819..0000000000 --- a/packages/inventory/jest.config.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - transform: { - "^.+\\.[jt]s?$": [ - "ts-jest", - { - tsconfig: "tsconfig.json", - isolatedModules: true, - }, - ], - }, - testEnvironment: `node`, - moduleFileExtensions: [`js`, `ts`], -} diff --git a/packages/inventory/package.json b/packages/inventory/package.json deleted file mode 100644 index 7b9428b19e..0000000000 --- a/packages/inventory/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "@medusajs/inventory", - "version": "1.11.6", - "description": "Inventory Module for Medusa", - "main": "dist/index.js", - "repository": { - "type": "git", - "url": "https://github.com/medusajs/medusa", - "directory": "packages/inventory" - }, - "publishConfig": { - "access": "public" - }, - "files": [ - "dist" - ], - "engines": { - "node": ">=16" - }, - "author": "Medusa", - "license": "MIT", - "devDependencies": { - "@medusajs/types": "^1.11.12", - "cross-env": "^5.2.1", - "jest": "^29.6.3", - "rimraf": "^5.0.1", - "ts-jest": "^29.1.1", - "typescript": "^5.1.6" - }, - "dependencies": { - "@medusajs/modules-sdk": "^1.12.8", - "@medusajs/utils": "^1.11.5", - "awilix": "^8.0.0", - "typeorm": "^0.3.16" - }, - "scripts": { - "watch": "tsc --build --watch", - "prepublishOnly": "cross-env NODE_ENV=production tsc --build", - "build": "rimraf dist && tsc --build", - "test": "jest --passWithNoTests" - } -} diff --git a/packages/inventory/src/index.ts b/packages/inventory/src/index.ts deleted file mode 100644 index 1cb6f68e0b..0000000000 --- a/packages/inventory/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { moduleDefinition } from "./module-definition" - -export default moduleDefinition - -export * from "./initialize" -export { revertMigration, runMigrations } from "./migrations/run-migration" diff --git a/packages/inventory/src/initialize/index.ts b/packages/inventory/src/initialize/index.ts deleted file mode 100644 index fa8b1b72c0..0000000000 --- a/packages/inventory/src/initialize/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - ExternalModuleDeclaration, - InternalModuleDeclaration, - MedusaModule, - MODULE_PACKAGE_NAMES, - Modules, -} from "@medusajs/modules-sdk" -import { IEventBusService, IInventoryService } from "@medusajs/types" -import { moduleDefinition } from "../module-definition" -import { InventoryServiceInitializeOptions } from "../types" - -export const initialize = async ( - options: InventoryServiceInitializeOptions | ExternalModuleDeclaration, - injectedDependencies?: { - eventBusService: IEventBusService - } -): Promise => { - const serviceKey = Modules.INVENTORY - const loaded = await MedusaModule.bootstrap({ - moduleKey: serviceKey, - defaultPath: MODULE_PACKAGE_NAMES[Modules.INVENTORY], - declaration: options as - | InternalModuleDeclaration - | ExternalModuleDeclaration, - injectedDependencies, - moduleExports: moduleDefinition, - }) - - return loaded[serviceKey] -} diff --git a/packages/inventory/src/joiner-config.ts b/packages/inventory/src/joiner-config.ts deleted file mode 100644 index df2bc97484..0000000000 --- a/packages/inventory/src/joiner-config.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Modules } from "@medusajs/modules-sdk" -import { ModuleJoinerConfig } from "@medusajs/types" -import { InventoryItem, InventoryLevel, ReservationItem } from "./models" -import moduleSchema from "./schema" - -export const joinerConfig: ModuleJoinerConfig = { - serviceName: Modules.INVENTORY, - primaryKeys: ["id"], - linkableKeys: { - inventory_item_id: InventoryItem.name, - inventory_level_id: InventoryLevel.name, - reservation_item_id: ReservationItem.name, - }, - schema: moduleSchema, - alias: [ - { - name: ["inventory_items", "inventory"], - args: { - entity: "InventoryItem", - }, - }, - { - name: ["inventory_level", "inventory_levels"], - args: { - entity: "InventoryLevel", - methodSuffix: "InventoryLevels", - }, - }, - { - name: [ - "reservation", - "reservations", - "reservation_item", - "reservation_items", - ], - args: { - entity: "ReservationItem", - methodSuffix: "ReservationItems", - }, - }, - ], -} diff --git a/packages/inventory/src/loaders/connection.ts b/packages/inventory/src/loaders/connection.ts deleted file mode 100644 index f53fa84817..0000000000 --- a/packages/inventory/src/loaders/connection.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - InternalModuleDeclaration, - LoaderOptions, - MODULE_RESOURCE_TYPE, - MODULE_SCOPE, -} from "@medusajs/modules-sdk" -import { DataSource, DataSourceOptions } from "typeorm" - -import { MedusaError } from "@medusajs/utils" -import { asValue } from "awilix" -import * as InventoryModels from "../models" -import { InventoryServiceInitializeOptions } from "../types" - -export default async ( - { options, container }: LoaderOptions, - moduleDeclaration?: InternalModuleDeclaration -): Promise => { - if ( - moduleDeclaration?.scope === MODULE_SCOPE.INTERNAL && - moduleDeclaration.resources === MODULE_RESOURCE_TYPE.SHARED - ) { - return - } - - const dbData = - options?.database as InventoryServiceInitializeOptions["database"] - - if (!dbData) { - throw new MedusaError( - MedusaError.Types.INVALID_ARGUMENT, - `Database config is not present at module config "options.database"` - ) - } - - const entities = Object.values(InventoryModels) - const dataSource = new DataSource({ - type: dbData.type, - url: dbData.url, - database: dbData.database, - extra: dbData.extra || {}, - schema: dbData.schema, - entities, - logging: dbData.logging, - } as DataSourceOptions) - - await dataSource.initialize() - - container.register({ - manager: asValue(dataSource.manager), - }) -} diff --git a/packages/inventory/src/loaders/container.ts b/packages/inventory/src/loaders/container.ts deleted file mode 100644 index 4b4bef1cb3..0000000000 --- a/packages/inventory/src/loaders/container.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk" - -import { - InventoryItemService, - InventoryLevelService, - ReservationItemService, -} from "../services" - -import { asClass } from "awilix" - -export default async ( - { container }: LoaderOptions, - moduleDeclaration?: InternalModuleDeclaration -): Promise => { - container.register({ - inventoryItemService: asClass(InventoryItemService).singleton(), - inventoryLevelService: asClass(InventoryLevelService).singleton(), - reservationItemService: asClass(ReservationItemService).singleton(), - }) -} diff --git a/packages/inventory/src/migrations/index.ts b/packages/inventory/src/migrations/index.ts deleted file mode 100644 index 67c160391f..0000000000 --- a/packages/inventory/src/migrations/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as addExternalId from "./schema-migrations/1675761451145-add_reservation_external_id" -import * as descriptionsAndThumbnail from "./schema-migrations/1682927363119-item_descriptions_and_thumbnail" -import * as setup from "./schema-migrations/1665748086258-inventory_setup" - -export default [setup, addExternalId, descriptionsAndThumbnail] diff --git a/packages/inventory/src/migrations/run-migration.ts b/packages/inventory/src/migrations/run-migration.ts deleted file mode 100644 index e6d2ffcd83..0000000000 --- a/packages/inventory/src/migrations/run-migration.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk" -import { DataSource, DataSourceOptions } from "typeorm" -import { InventoryServiceInitializeOptions } from "../types" - -import migrations from "./index" - -function getDataSource( - dbData: InventoryServiceInitializeOptions["database"] -): DataSource { - return new DataSource({ - type: dbData!.type, - url: dbData!.url, - database: dbData!.database, - extra: dbData!.extra || {}, - migrations: migrations - .map((migration: any): Function[] => { - return Object.values(migration).filter( - (fn) => typeof fn === "function" - ) as Function[] - }) - .flat(), - schema: dbData!.schema, - logging: dbData!.logging, - } as DataSourceOptions) -} - -export async function runMigrations( - { options, logger }: Omit, - moduleDeclaration?: InternalModuleDeclaration -) { - const dbData = - options?.database as InventoryServiceInitializeOptions["database"] - - try { - const dataSource = getDataSource(dbData) - await dataSource.initialize() - await dataSource.runMigrations() - - logger?.info("Inventory module migration executed") - } catch (error) { - logger?.error(`Inventory module migration failed to run - Error: ${error}`) - } -} - -export async function revertMigration( - { options, logger }: Omit, - moduleDeclaration?: InternalModuleDeclaration -) { - const dbData = - options?.database as InventoryServiceInitializeOptions["database"] - - try { - const dataSource = getDataSource(dbData) - await dataSource.initialize() - await dataSource.undoLastMigration() - - logger?.info("Inventory module migration reverted") - } catch (error) { - logger?.error( - `Inventory module migration failed to revert - Error: ${error}` - ) - } -} diff --git a/packages/inventory/src/migrations/schema-migrations/1665748086258-inventory_setup.ts b/packages/inventory/src/migrations/schema-migrations/1665748086258-inventory_setup.ts deleted file mode 100644 index 0d9213c382..0000000000 --- a/packages/inventory/src/migrations/schema-migrations/1665748086258-inventory_setup.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class inventorySetup1665748086258 implements MigrationInterface { - name = "inventorySetup1665748086258" - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - CREATE TABLE "inventory_item" ( - "id" character varying NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), - "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), - "deleted_at" TIMESTAMP WITH TIME ZONE, - "sku" text, - "origin_country" text, - "hs_code" text, - "mid_code" text, - "material" text, - "weight" integer, - "length" integer, - "height" integer, - "width" integer, - "requires_shipping" boolean NOT NULL DEFAULT true, - "metadata" jsonb, - CONSTRAINT "PK_inventory_item_id" PRIMARY KEY ("id") - ); - - CREATE UNIQUE INDEX "IDX_inventory_item_sku" ON "inventory_item" ("sku") WHERE deleted_at IS NULL; - - CREATE TABLE "reservation_item" ( - "id" character varying NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), - "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), - "deleted_at" TIMESTAMP WITH TIME ZONE, - "line_item_id" text, - "inventory_item_id" text NOT NULL, - "location_id" text NOT NULL, - "quantity" integer NOT NULL, - "metadata" jsonb, - CONSTRAINT "PK_reservation_item_id" PRIMARY KEY ("id") - ); - - CREATE INDEX "IDX_reservation_item_line_item_id" ON "reservation_item" ("line_item_id") WHERE deleted_at IS NULL; - CREATE INDEX "IDX_reservation_item_inventory_item_id" ON "reservation_item" ("inventory_item_id") WHERE deleted_at IS NULL; - CREATE INDEX "IDX_reservation_item_location_id" ON "reservation_item" ("location_id") WHERE deleted_at IS NULL; - - - CREATE TABLE "inventory_level" ( - "id" character varying NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), - "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), - "deleted_at" TIMESTAMP WITH TIME ZONE, - "inventory_item_id" text NOT NULL, - "location_id" text NOT NULL, - "stocked_quantity" integer NOT NULL DEFAULT 0, - "reserved_quantity" integer NOT NULL DEFAULT 0, - "incoming_quantity" integer NOT NULL DEFAULT 0, - "metadata" jsonb, - CONSTRAINT "PK_inventory_level_id" PRIMARY KEY ("id") - ); - - CREATE UNIQUE INDEX "UQ_inventory_level_inventory_item_id_location_id" ON "inventory_level" ("inventory_item_id", "location_id"); - CREATE INDEX "IDX_inventory_level_inventory_item_id" ON "inventory_level" ("inventory_item_id"); - CREATE INDEX "IDX_inventory_level_location_id" ON "inventory_level" ("location_id"); - `) - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - DROP INDEX "IDX_inventory_level_location_id"; - DROP INDEX "IDX_inventory_level_inventory_item_id"; - DROP INDEX "UQ_inventory_level_inventory_item_id_location_id"; - DROP TABLE "inventory_level"; - - DROP INDEX "IDX_reservation_item_location_id"; - DROP INDEX "IDX_reservation_item_inventory_item_id"; - DROP INDEX "IDX_reservation_item_line_item_id"; - DROP TABLE "reservation_item"; - - DROP INDEX "IDX_inventory_item_sku"; - DROP TABLE "inventory_item"; - `) - } -} diff --git a/packages/inventory/src/migrations/schema-migrations/1675761451145-add_reservation_external_id.ts b/packages/inventory/src/migrations/schema-migrations/1675761451145-add_reservation_external_id.ts deleted file mode 100644 index bc42c8fbd8..0000000000 --- a/packages/inventory/src/migrations/schema-migrations/1675761451145-add_reservation_external_id.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class addReservationType1675761451145 implements MigrationInterface { - name = "addReservationType1675761451145" - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - ALTER TABLE "reservation_item" ADD "external_id" character varying - `) - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - ALTER TABLE "reservation_item" DROP COLUMN "external_id"; - `) - } -} diff --git a/packages/inventory/src/migrations/schema-migrations/1682927363119-item_descriptions_and_thumbnail.ts b/packages/inventory/src/migrations/schema-migrations/1682927363119-item_descriptions_and_thumbnail.ts deleted file mode 100644 index 03f330f58f..0000000000 --- a/packages/inventory/src/migrations/schema-migrations/1682927363119-item_descriptions_and_thumbnail.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class itemDescriptionsAndThumbnail1682927363119 - implements MigrationInterface -{ - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - ALTER TABLE inventory_item - ADD "title" character varying, - ADD "description" character varying, - ADD "thumbnail" character varying; - `) - await queryRunner.query(` - ALTER TABLE "reservation_item" - ADD "description" character varying, - ADD "created_by" character varying; - `) - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - ALTER TABLE inventory_item - DROP COLUMN "title", - DROP COLUMN "description", - DROP COLUMN "thumbnail"; - `) - await queryRunner.query(` - ALTER TABLE "reservation_item" - DROP COLUMN "description", - DROP COLUMN "created_by"; - `) - } -} diff --git a/packages/inventory/src/migrations/schema-migrations/1697708391459-scope-level-unique.ts b/packages/inventory/src/migrations/schema-migrations/1697708391459-scope-level-unique.ts deleted file mode 100644 index fdc6167319..0000000000 --- a/packages/inventory/src/migrations/schema-migrations/1697708391459-scope-level-unique.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class ScopeLevelUnique1697708391459 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `DROP INDEX "UQ_inventory_level_inventory_item_id_location_id"` - ) - - await queryRunner.query(` - CREATE UNIQUE INDEX "UQ_inventory_level_inventory_item_id_location_id" ON "inventory_level" ("inventory_item_id", "location_id") WHERE deleted_at IS NULL; - `) - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - CREATE UNIQUE INDEX "UQ_inventory_level_inventory_item_id_location_id" ON "inventory_level" ("inventory_item_id", "location_id"); - `) - } -} diff --git a/packages/inventory/src/models/index.ts b/packages/inventory/src/models/index.ts deleted file mode 100644 index 79daaa78ee..0000000000 --- a/packages/inventory/src/models/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export {ReservationItem} from "./reservation-item" -export * from "./inventory-item" -export * from "./inventory-level" diff --git a/packages/inventory/src/models/inventory-item.ts b/packages/inventory/src/models/inventory-item.ts deleted file mode 100644 index 418cbcbd88..0000000000 --- a/packages/inventory/src/models/inventory-item.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { generateEntityId } from "@medusajs/utils" -import { - BeforeInsert, - Column, - CreateDateColumn, - DeleteDateColumn, - Entity, - Index, - OneToMany, - PrimaryColumn, - UpdateDateColumn, -} from "typeorm" -import { InventoryLevel } from "./inventory-level" - -@Entity() -export class InventoryItem { - @PrimaryColumn() - id: string - - @CreateDateColumn({ type: "timestamptz" }) - created_at: Date - - @UpdateDateColumn({ type: "timestamptz" }) - updated_at: Date - - @DeleteDateColumn({ type: "timestamptz" }) - deleted_at: Date | null - - @Index({ unique: true }) - @Column({ type: "text", nullable: true }) - sku: string | null - - @Column({ type: "text", nullable: true }) - origin_country: string | null - - @Column({ type: "text", nullable: true }) - hs_code: string | null - - @Column({ type: "text", nullable: true }) - mid_code: string | null - - @Column({ type: "text", nullable: true }) - material: string | null - - @Column({ type: "int", nullable: true }) - weight: number | null - - @Column({ type: "int", nullable: true }) - length: number | null - - @Column({ type: "int", nullable: true }) - height: number | null - - @Column({ type: "int", nullable: true }) - width: number | null - - @Column({ default: true }) - requires_shipping: boolean - - @Column({ type: "text", nullable: true }) - description: string | null - - @Column({ type: "text", nullable: true }) - title: string | null - - @Column({ type: "text", nullable: true }) - thumbnail: string | null - - @Column({ type: "jsonb", nullable: true }) - metadata: Record | null - - @OneToMany( - () => InventoryLevel, - (inventoryLevel) => inventoryLevel.inventory_item - ) - inventory_levels!: InventoryLevel[] - - @BeforeInsert() - private beforeInsert(): void { - this.id = generateEntityId(this.id, "iitem") - } -} diff --git a/packages/inventory/src/models/inventory-level.ts b/packages/inventory/src/models/inventory-level.ts deleted file mode 100644 index 62a19e7970..0000000000 --- a/packages/inventory/src/models/inventory-level.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { generateEntityId } from "@medusajs/utils" -import { - BeforeInsert, - Column, - CreateDateColumn, - DeleteDateColumn, - Entity, - Index, - JoinColumn, - ManyToOne, - PrimaryColumn, - UpdateDateColumn, -} from "typeorm" -import { InventoryItem } from "./inventory-item" - -@Entity() -@Index(["inventory_item_id", "location_id"], { unique: true }) -export class InventoryLevel { - @PrimaryColumn() - id: string - - @CreateDateColumn({ type: "timestamptz" }) - created_at: Date - - @UpdateDateColumn({ type: "timestamptz" }) - updated_at: Date - - @DeleteDateColumn({ type: "timestamptz" }) - deleted_at: Date | null - - @Index() - @Column({ type: "text" }) - inventory_item_id: string - - @Index() - @Column({ type: "text" }) - location_id: string - - @Column({ default: 0 }) - stocked_quantity: number - - @Column({ default: 0 }) - reserved_quantity: number - - @Column({ default: 0 }) - incoming_quantity: number - - @Column({ type: "jsonb", nullable: true }) - metadata: Record | null - - @ManyToOne(() => InventoryItem) - @JoinColumn({ name: "inventory_item_id" }) - inventory_item: InventoryItem - - @BeforeInsert() - private beforeInsert(): void { - this.id = generateEntityId(this.id, "ilev") - } -} diff --git a/packages/inventory/src/models/reservation-item.ts b/packages/inventory/src/models/reservation-item.ts deleted file mode 100644 index 569806286d..0000000000 --- a/packages/inventory/src/models/reservation-item.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { generateEntityId } from "@medusajs/utils" -import { - BeforeInsert, - Column, - CreateDateColumn, - DeleteDateColumn, - Entity, - Index, - PrimaryColumn, - UpdateDateColumn, -} from "typeorm" - -@Entity() -export class ReservationItem { - @PrimaryColumn() - id: string - - @CreateDateColumn({ type: "timestamptz" }) - created_at: Date - - @UpdateDateColumn({ type: "timestamptz" }) - updated_at: Date - - @DeleteDateColumn({ type: "timestamptz" }) - deleted_at: Date | null - - @Index() - @Column({ type: "text", nullable: true }) - line_item_id: string | null - - @Index() - @Column({ type: "text" }) - inventory_item_id: string - - @Index() - @Column({ type: "text" }) - location_id: string - - @Column() - quantity: number - - @Column({ type: "text", nullable: true }) - external_id: string | null - - @Column({ type: "text", nullable: true }) - description: string | null - - @Column({ type: "text", nullable: true }) - created_by: string | null - - @Column({ type: "jsonb", nullable: true }) - metadata: Record | null - - @BeforeInsert() - private beforeInsert(): void { - this.id = generateEntityId(this.id, "resitem") - } -} diff --git a/packages/inventory/src/module-definition.ts b/packages/inventory/src/module-definition.ts deleted file mode 100644 index 40912d71d5..0000000000 --- a/packages/inventory/src/module-definition.ts +++ /dev/null @@ -1,20 +0,0 @@ -import InventoryService from "./services/inventory" -import loadContainer from "./loaders/container" -import loadConnection from "./loaders/connection" -import * as InventoryModels from "./models" -import { ModuleExports } from "@medusajs/types" -import migrations from "./migrations" -import { revertMigration, runMigrations } from "./migrations/run-migration" - -const service = InventoryService -const loaders = [loadContainer, loadConnection] -const models = Object.values(InventoryModels) - -export const moduleDefinition: ModuleExports = { - service, - migrations, - loaders, - models, - runMigrations, - revertMigration, -} diff --git a/packages/inventory/src/schema/index.ts b/packages/inventory/src/schema/index.ts deleted file mode 100644 index 859d6efca7..0000000000 --- a/packages/inventory/src/schema/index.ts +++ /dev/null @@ -1,55 +0,0 @@ -export default ` -scalar DateTime -scalar JSON - -type InventoryItem { - id: ID! - created_at: DateTime! - updated_at: DateTime! - deleted_at: DateTime - sku: String - origin_country: String - hs_code: String - mid_code: String - material: String - weight: Int - length: Int - height: Int - width: Int - requires_shipping: Boolean! - description: String - title: String - thumbnail: String - metadata: JSON - - inventory_levels: [InventoryLevel] -} - -type InventoryLevel { - id: ID! - created_at: DateTime! - updated_at: DateTime! - deleted_at: DateTime - inventory_item_id: String! - location_id: String! - stocked_quantity: Int! - reserved_quantity: Int! - incoming_quantity: Int! - metadata: JSON -} - -type ReservationItem { - id: ID! - created_at: DateTime! - updated_at: DateTime! - deleted_at: DateTime - line_item_id: String - inventory_item_id: String! - location_id: String! - quantity: Int! - external_id: String - description: String - created_by: String - metadata: JSON -} -` diff --git a/packages/inventory/src/services/index.ts b/packages/inventory/src/services/index.ts deleted file mode 100644 index cad75521c3..0000000000 --- a/packages/inventory/src/services/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as InventoryLevelService } from "./inventory-level" -export { default as InventoryItemService } from "./inventory-item" -export { default as ReservationItemService } from "./reservation-item" -export { default as InventoryService } from "./inventory" diff --git a/packages/inventory/src/services/inventory-item.ts b/packages/inventory/src/services/inventory-item.ts deleted file mode 100644 index 207a8c6624..0000000000 --- a/packages/inventory/src/services/inventory-item.ts +++ /dev/null @@ -1,240 +0,0 @@ -import { - CreateInventoryItemInput, - FilterableInventoryItemProps, - FindConfig, - IEventBusService, - InventoryItemDTO, - SharedContext, -} from "@medusajs/types" -import { - InjectEntityManager, - MedusaContext, - MedusaError, - isDefined, -} from "@medusajs/utils" -import { DeepPartial, EntityManager, FindManyOptions, In } from "typeorm" -import { InventoryItem } from "../models" -import { buildQuery } from "../utils/build-query" -import { getListQuery } from "../utils/query" - -type InjectedDependencies = { - eventBusService: IEventBusService - manager: EntityManager -} - -export default class InventoryItemService { - static Events = { - CREATED: "inventory-item.created", - UPDATED: "inventory-item.updated", - DELETED: "inventory-item.deleted", - RESTORED: "inventory-item.restored", - } - - protected readonly manager_: EntityManager - protected readonly eventBusService_: IEventBusService | undefined - - constructor({ eventBusService, manager }: InjectedDependencies) { - this.manager_ = manager - this.eventBusService_ = eventBusService - } - - /** - * @param selector - Filter options for inventory items. - * @param config - Configuration for query. - * @param context - * @return Resolves to the list of inventory items that match the filter. - */ - async list( - selector: FilterableInventoryItemProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise { - const queryBuilder = getListQuery( - context.transactionManager ?? this.manager_, - selector, - config - ) - return await queryBuilder.getMany() - } - - /** - * Retrieves an inventory item by its id. - * @param inventoryItemId - the id of the inventory item to retrieve. - * @param config - the configuration options for the find operation. - * @param context - * @return The retrieved inventory item. - * @throws If the inventory item id is not defined or if the inventory item is not found. - */ - async retrieve( - inventoryItemId: string, - config: FindConfig = {}, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!isDefined(inventoryItemId)) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `"inventoryItemId" must be defined` - ) - } - - const manager = context.transactionManager ?? this.manager_ - const itemRepository = manager.getRepository(InventoryItem) - - const query = buildQuery({ id: inventoryItemId }, config) as FindManyOptions - const [inventoryItem] = await itemRepository.find(query) - - if (!inventoryItem) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `InventoryItem with id ${inventoryItemId} was not found` - ) - } - - return inventoryItem - } - - /** - * @param selector - Filter options for inventory items. - * @param config - Configuration for query. - * @param context - * @return - Resolves to the list of inventory items that match the filter and the count of all matching items. - */ - async listAndCount( - selector: FilterableInventoryItemProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise<[InventoryItemDTO[], number]> { - const queryBuilder = getListQuery( - context.transactionManager ?? this.manager_, - selector, - config - ) - - return await queryBuilder.getManyAndCount() - } - - /** - * @param data - * @param context - * @param data - * @param context - */ - @InjectEntityManager() - async create( - data: CreateInventoryItemInput[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const itemRepository = manager.getRepository(InventoryItem) - - const inventoryItem = itemRepository.create( - data.map((tc) => ({ - sku: tc.sku, - origin_country: tc.origin_country, - metadata: tc.metadata, - hs_code: tc.hs_code, - mid_code: tc.mid_code, - material: tc.material, - weight: tc.weight, - length: tc.length, - height: tc.height, - width: tc.width, - requires_shipping: tc.requires_shipping, - description: tc.description, - thumbnail: tc.thumbnail, - title: tc.title, - })) - ) - - const result = await itemRepository.save(inventoryItem) - - await this.eventBusService_?.emit?.(InventoryItemService.Events.CREATED, { - ids: result.map((i) => i.id), - }) - - return result - } - - /** - * @param inventoryItemId - The id of the inventory item to update. - * @param data - * @param context - * @param context - * @return The updated inventory item. - */ - @InjectEntityManager() - async update( - inventoryItemId: string, - data: Omit< - DeepPartial, - "id" | "created_at" | "metadata" | "deleted_at" - >, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const itemRepository = manager.getRepository(InventoryItem) - - const item = await this.retrieve(inventoryItemId, undefined, context) - - const shouldUpdate = Object.keys(data).some((key) => { - return item[key] !== data[key] - }) - - if (shouldUpdate) { - itemRepository.merge(item, data) - await itemRepository.save(item) - - await this.eventBusService_?.emit?.(InventoryItemService.Events.UPDATED, { - id: item.id, - }) - } - - return item - } - - /** - * @param inventoryItemId - The id of the inventory item to delete. - * @param context - */ - @InjectEntityManager() - async delete( - inventoryItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const itemRepository = manager.getRepository(InventoryItem) - - const ids = Array.isArray(inventoryItemId) - ? inventoryItemId - : [inventoryItemId] - - await itemRepository.softDelete({ id: In(ids) }) - - await this.eventBusService_?.emit?.(InventoryItemService.Events.DELETED, { - ids: inventoryItemId, - }) - } - - /** - * @param inventoryItemId - The id of the inventory item to restore. - * @param context - */ - @InjectEntityManager() - async restore( - inventoryItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const itemRepository = manager.getRepository(InventoryItem) - - const ids = Array.isArray(inventoryItemId) - ? inventoryItemId - : [inventoryItemId] - - await itemRepository.restore({ id: In(ids) }) - - await this.eventBusService_?.emit?.(InventoryItemService.Events.RESTORED, { - ids: inventoryItemId, - }) - } -} diff --git a/packages/inventory/src/services/inventory-level.ts b/packages/inventory/src/services/inventory-level.ts deleted file mode 100644 index 38ddff8462..0000000000 --- a/packages/inventory/src/services/inventory-level.ts +++ /dev/null @@ -1,398 +0,0 @@ -import { - CreateInventoryLevelInput, - FilterableInventoryLevelProps, - FindConfig, - IEventBusService, - SharedContext, -} from "@medusajs/types" -import { - InjectEntityManager, - MedusaContext, - MedusaError, - isDefined, -} from "@medusajs/utils" -import { DeepPartial, EntityManager, FindManyOptions, In } from "typeorm" -import { InventoryLevel } from "../models" -import { buildQuery } from "../utils/build-query" - -type InjectedDependencies = { - eventBusService: IEventBusService - manager: EntityManager -} - -export default class InventoryLevelService { - static Events = { - CREATED: "inventory-level.created", - UPDATED: "inventory-level.updated", - DELETED: "inventory-level.deleted", - RESTORED: "inventory-level.restored", - } - - protected readonly manager_: EntityManager - protected readonly eventBusService_: IEventBusService | undefined - - constructor({ eventBusService, manager }: InjectedDependencies) { - this.manager_ = manager - this.eventBusService_ = eventBusService - } - - /** - * Retrieves a list of inventory levels based on the provided selector and configuration. - * @param selector - An object containing filterable properties for inventory levels. - * @param config - An object containing configuration options for the query. - * @param context - * @return Array of inventory levels. - */ - async list( - selector: FilterableInventoryLevelProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager ?? this.manager_ - const levelRepository = manager.getRepository(InventoryLevel) - - const query = buildQuery(selector, config) as FindManyOptions - return await levelRepository.find(query) - } - - /** - * Retrieves a list of inventory levels and a count based on the provided selector and configuration. - * @param selector - An object containing filterable properties for inventory levels. - * @param config - An object containing configuration options for the query. - * @param context - * @return An array of inventory levels and a count. - */ - async listAndCount( - selector: FilterableInventoryLevelProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise<[InventoryLevel[], number]> { - const manager = context.transactionManager ?? this.manager_ - const levelRepository = manager.getRepository(InventoryLevel) - - const query = buildQuery(selector, config) as FindManyOptions - return await levelRepository.findAndCount(query) - } - - /** - * Retrieves a single inventory level by its ID. - * @param inventoryLevelId - The ID of the inventory level to retrieve. - * @param config - An object containing configuration options for the query. - * @param context - * @return A inventory level. - * @throws If the inventory level ID is not defined or the given ID was not found. - */ - async retrieve( - inventoryLevelId: string, - config: FindConfig = {}, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!isDefined(inventoryLevelId)) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `"inventoryLevelId" must be defined` - ) - } - - const manager = context.transactionManager ?? this.manager_ - const levelRepository = manager.getRepository(InventoryLevel) - - const query = buildQuery( - { id: inventoryLevelId }, - config - ) as FindManyOptions - const [inventoryLevel] = await levelRepository.find(query) - - if (!inventoryLevel) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `InventoryLevel with id ${inventoryLevelId} was not found` - ) - } - - return inventoryLevel - } - - /** - * Creates a new inventory level. - * @param data - An object containing the properties for the new inventory level. - * @param context - * @return The created inventory level. - */ - @InjectEntityManager() - async create( - data: CreateInventoryLevelInput[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - - const toCreate = data.map((d) => { - return { - location_id: d.location_id, - inventory_item_id: d.inventory_item_id, - stocked_quantity: d.stocked_quantity, - reserved_quantity: d.reserved_quantity, - incoming_quantity: d.incoming_quantity, - } - }) - - const levelRepository = manager.getRepository(InventoryLevel) - - const inventoryLevels = levelRepository.create(toCreate) - - const saved = await levelRepository.save(inventoryLevels) - await this.eventBusService_?.emit?.(InventoryLevelService.Events.CREATED, { - ids: saved.map((i) => i.id), - }) - - return saved - } - - /** - * Updates an existing inventory level. - * @param inventoryLevelId - The ID of the inventory level to update. - * @param data - An object containing the properties to update on the inventory level. - * @param context - * @return The updated inventory level. - * @throws If the inventory level ID is not defined or the given ID was not found. - */ - @InjectEntityManager() - async update( - inventoryLevelId: string, - data: Omit< - DeepPartial, - "id" | "created_at" | "metadata" | "deleted_at" - >, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const levelRepository = manager.getRepository(InventoryLevel) - - const item = await this.retrieve(inventoryLevelId, undefined, context) - - const shouldUpdate = Object.keys(data).some((key) => { - return item[key] !== data[key] - }) - - if (shouldUpdate) { - levelRepository.merge(item, data) - await levelRepository.save(item) - - await this.eventBusService_?.emit?.( - InventoryLevelService.Events.UPDATED, - { - id: item.id, - } - ) - } - - return item - } - - /** - * Adjust the reserved quantity for an inventory item at a specific location. - * @param inventoryItemId - The ID of the inventory item. - * @param locationId - The ID of the location. - * @param quantity - The quantity to adjust from the reserved quantity. - * @param context - */ - @InjectEntityManager() - async adjustReservedQuantity( - inventoryItemId: string, - locationId: string, - quantity: number, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - await manager - .createQueryBuilder() - .update(InventoryLevel) - .set({ reserved_quantity: () => `reserved_quantity + ${quantity}` }) - .where( - "inventory_item_id = :inventoryItemId AND location_id = :locationId", - { inventoryItemId, locationId } - ) - .execute() - } - - /** - * Deletes inventory levels by inventory Item ID. - * @param inventoryItemId - The ID or IDs of the inventory item to delete inventory levels for. - * @param context - */ - @InjectEntityManager() - async deleteByInventoryItemId( - inventoryItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const ids = Array.isArray(inventoryItemId) - ? inventoryItemId - : [inventoryItemId] - - const manager = context.transactionManager! - const levelRepository = manager.getRepository(InventoryLevel) - - await levelRepository.softDelete({ inventory_item_id: In(ids) }) - - await this.eventBusService_?.emit?.(InventoryLevelService.Events.DELETED, { - inventory_item_id: inventoryItemId, - }) - } - - /** - * Restores inventory levels by inventory Item ID. - * @param inventoryItemId - The ID or IDs of the inventory item to restore inventory levels for. - * @param context - */ - @InjectEntityManager() - async restoreByInventoryItemId( - inventoryItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const ids = Array.isArray(inventoryItemId) - ? inventoryItemId - : [inventoryItemId] - - const manager = context.transactionManager! - const levelRepository = manager.getRepository(InventoryLevel) - - await levelRepository.restore({ inventory_item_id: In(ids) }) - - await this.eventBusService_?.emit?.(InventoryLevelService.Events.RESTORED, { - inventory_item_id: inventoryItemId, - }) - } - - /** - * Deletes an inventory level by ID. - * @param inventoryLevelId - The ID or IDs of the inventory level to delete. - * @param context - */ - @InjectEntityManager() - async delete( - inventoryLevelId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const ids = Array.isArray(inventoryLevelId) - ? inventoryLevelId - : [inventoryLevelId] - - const manager = context.transactionManager! - const levelRepository = manager.getRepository(InventoryLevel) - - await levelRepository.softDelete({ id: In(ids) }) - - await this.eventBusService_?.emit?.(InventoryLevelService.Events.DELETED, { - ids: inventoryLevelId, - }) - } - - /** - * Deletes inventory levels by location ID. - * @param locationId - The ID of the location to delete inventory levels for. - * @param context - */ - @InjectEntityManager() - async deleteByLocationId( - locationId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const levelRepository = manager.getRepository(InventoryLevel) - - const ids = Array.isArray(locationId) ? locationId : [locationId] - - await levelRepository.softDelete({ location_id: In(ids) }) - - await this.eventBusService_?.emit?.(InventoryLevelService.Events.DELETED, { - location_ids: ids, - }) - } - - /** - * Gets the total stocked quantity for a specific inventory item at multiple locations. - * @param inventoryItemId - The ID of the inventory item. - * @param locationIds - The IDs of the locations. - * @param context - * @return The total stocked quantity. - */ - async getStockedQuantity( - inventoryItemId: string, - locationIds: string[] | string, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!Array.isArray(locationIds)) { - locationIds = [locationIds] - } - - const manager = context.transactionManager ?? this.manager_ - const levelRepository = manager.getRepository(InventoryLevel) - - const result = await levelRepository - .createQueryBuilder() - .select("SUM(stocked_quantity)", "quantity") - .where("inventory_item_id = :inventoryItemId", { inventoryItemId }) - .andWhere("location_id IN (:...locationIds)", { locationIds }) - .getRawOne() - - return parseFloat(result.quantity) - } - - /** - * Gets the total available quantity for a specific inventory item at multiple locations. - * @param inventoryItemId - The ID of the inventory item. - * @param locationIds - The IDs of the locations. - * @param context - * @return The total available quantity. - */ - async getAvailableQuantity( - inventoryItemId: string, - locationIds: string[] | string, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!Array.isArray(locationIds)) { - locationIds = [locationIds] - } - - const manager = context.transactionManager ?? this.manager_ - const levelRepository = manager.getRepository(InventoryLevel) - - const result = await levelRepository - .createQueryBuilder() - .select("SUM(stocked_quantity - reserved_quantity)", "quantity") - .where("inventory_item_id = :inventoryItemId", { inventoryItemId }) - .andWhere("location_id IN (:...locationIds)", { locationIds }) - .getRawOne() - - return parseFloat(result.quantity) - } - - /** - * Gets the total reserved quantity for a specific inventory item at multiple locations. - * @param inventoryItemId - The ID of the inventory item. - * @param locationIds - The IDs of the locations. - * @param context - * @return The total reserved quantity. - */ - async getReservedQuantity( - inventoryItemId: string, - locationIds: string[] | string, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!Array.isArray(locationIds)) { - locationIds = [locationIds] - } - - const manager = context.transactionManager ?? this.manager_ - const levelRepository = manager.getRepository(InventoryLevel) - - const result = await levelRepository - .createQueryBuilder() - .select("SUM(reserved_quantity)", "quantity") - .where("inventory_item_id = :inventoryItemId", { inventoryItemId }) - .andWhere("location_id IN (:...locationIds)", { locationIds }) - .getRawOne() - - return parseFloat(result.quantity) - } -} diff --git a/packages/inventory/src/services/inventory.ts b/packages/inventory/src/services/inventory.ts deleted file mode 100644 index 2294c21f4e..0000000000 --- a/packages/inventory/src/services/inventory.ts +++ /dev/null @@ -1,754 +0,0 @@ -import { InternalModuleDeclaration } from "@medusajs/modules-sdk" -import { - BulkUpdateInventoryLevelInput, - CreateInventoryItemInput, - CreateInventoryLevelInput, - CreateReservationItemInput, - FilterableInventoryItemProps, - FilterableInventoryLevelProps, - FilterableReservationItemProps, - FindConfig, - IInventoryService, - InventoryItemDTO, - InventoryLevelDTO, - MODULE_RESOURCE_TYPE, - ModuleJoinerConfig, - ReservationItemDTO, - SharedContext, - UpdateInventoryLevelInput, - UpdateReservationItemInput, -} from "@medusajs/types" -import { - InjectEntityManager, - MedusaContext, - MedusaError, - promiseAll, -} from "@medusajs/utils" -import { EntityManager } from "typeorm" -import { joinerConfig } from "../joiner-config" -import InventoryItemService from "./inventory-item" -import InventoryLevelService from "./inventory-level" -import ReservationItemService from "./reservation-item" - -type InjectedDependencies = { - manager: EntityManager - inventoryItemService: InventoryItemService - inventoryLevelService: InventoryLevelService - reservationItemService: ReservationItemService -} - -export default class InventoryService implements IInventoryService { - protected readonly manager_: EntityManager - - protected readonly inventoryItemService_: InventoryItemService - protected readonly reservationItemService_: ReservationItemService - protected readonly inventoryLevelService_: InventoryLevelService - - constructor( - { - manager, - inventoryItemService, - inventoryLevelService, - reservationItemService, - }: InjectedDependencies, - options?: unknown, - protected readonly moduleDeclaration?: InternalModuleDeclaration - ) { - this.manager_ = manager - this.inventoryItemService_ = inventoryItemService - this.inventoryLevelService_ = inventoryLevelService - this.reservationItemService_ = reservationItemService - } - - __joinerConfig(): ModuleJoinerConfig { - return joinerConfig - } - - /** - * Lists inventory items that match the given selector - * @param selector - the selector to filter inventory items by - * @param config - the find configuration to use - * @param context - * @return A tuple of inventory items and their total count - */ - async listInventoryItems( - selector: FilterableInventoryItemProps, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise<[InventoryItemDTO[], number]> { - return await this.inventoryItemService_.listAndCount( - selector, - config, - context - ) - } - async list( - selector: FilterableInventoryItemProps, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.inventoryItemService_.list(selector, config, context) - } - - /** - * Lists inventory levels that match the given selector - * @param selector - the selector to filter inventory levels by - * @param config - the find configuration to use - * @param context - * @return A tuple of inventory levels and their total count - */ - async listInventoryLevels( - selector: FilterableInventoryLevelProps, - config: FindConfig = { - relations: [], - skip: 0, - take: 10, - }, - @MedusaContext() context: SharedContext = {} - ): Promise<[InventoryLevelDTO[], number]> { - return await this.inventoryLevelService_.listAndCount( - selector, - config, - context - ) - } - - /** - * Lists reservation items that match the given selector - * @param selector - the selector to filter reservation items by - * @param config - the find configuration to use - * @param context - * @return A tuple of reservation items and their total count - */ - async listReservationItems( - selector: FilterableReservationItemProps, - config: FindConfig = { - relations: [], - skip: 0, - take: 10, - }, - @MedusaContext() context: SharedContext = {} - ): Promise<[ReservationItemDTO[], number]> { - return await this.reservationItemService_.listAndCount( - selector, - config, - context - ) - } - - /** - * Retrieves an inventory item with the given id - * @param inventoryItemId - the id of the inventory item to retrieve - * @param config - the find configuration to use - * @param context - * @return The retrieved inventory item - */ - async retrieveInventoryItem( - inventoryItemId: string, - config?: FindConfig, - @MedusaContext() context: SharedContext = {} - ): Promise { - const inventoryItem = await this.inventoryItemService_.retrieve( - inventoryItemId, - config, - context - ) - return { ...inventoryItem } - } - - /** - * Retrieves an inventory level for a given inventory item and location - * @param inventoryItemId - the id of the inventory item - * @param locationId - the id of the location - * @param context - * @return the retrieved inventory level - */ - async retrieveInventoryLevel( - inventoryItemId: string, - locationId: string, - @MedusaContext() context: SharedContext = {} - ): Promise { - const [inventoryLevel] = await this.inventoryLevelService_.list( - { inventory_item_id: inventoryItemId, location_id: locationId }, - { take: 1 }, - context - ) - if (!inventoryLevel) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `Inventory level for item ${inventoryItemId} and location ${locationId} not found` - ) - } - return inventoryLevel - } - - /** - * Retrieves a reservation item - * @param reservationId - * @param context - * @param reservationId - * @param context - */ - async retrieveReservationItem( - reservationId: string, - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.reservationItemService_.retrieve( - reservationId, - undefined, - context - ) - } - - private async ensureInventoryLevels( - data: { location_id: string; inventory_item_id: string }[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const inventoryLevels = await this.inventoryLevelService_.list( - { - inventory_item_id: data.map((e) => e.inventory_item_id), - location_id: data.map((e) => e.location_id), - }, - {}, - context - ) - - const inventoryLevelMap: Map< - string, - Map - > = inventoryLevels.reduce((acc, curr) => { - const inventoryLevelMap = acc.get(curr.inventory_item_id) ?? new Map() - inventoryLevelMap.set(curr.location_id, curr) - acc.set(curr.inventory_item_id, inventoryLevelMap) - return acc - }, new Map()) - - const missing = data.filter( - (i) => !inventoryLevelMap.get(i.inventory_item_id)?.get(i.location_id) - ) - - if (missing.length) { - const error = missing - .map((missing) => { - return `Item ${missing.inventory_item_id} is not stocked at location ${missing.location_id}` - }) - .join(", ") - throw new MedusaError(MedusaError.Types.NOT_FOUND, error) - } - - return inventoryLevels.map( - (i) => inventoryLevelMap.get(i.inventory_item_id)!.get(i.location_id)! - ) - } - - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async createReservationItems( - input: CreateReservationItemInput[], - @MedusaContext() context: SharedContext = {} - ): Promise { - await this.ensureInventoryLevels(input, context) - - return await this.reservationItemService_.create(input, context) - } - - /** - * Creates a reservation item - * @param input - the input object - * @return The created reservation item - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async createReservationItem( - input: CreateReservationItemInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - const [result] = await this.createReservationItems([input], context) - - return result - } - - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async createInventoryItems( - input: CreateInventoryItemInput[], - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.inventoryItemService_.create(input, context) - } - - /** - * Creates an inventory item - * @param input - the input object - * @param context - * @return The created inventory item - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async createInventoryItem( - input: CreateInventoryItemInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - const [result] = await this.createInventoryItems([input], context) - - return result - } - - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async createInventoryLevels( - input: CreateInventoryLevelInput[], - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.inventoryLevelService_.create(input, context) - } - - /** - * Creates an inventory item - * @param input - the input object - * @param context - * @return The created inventory level - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async createInventoryLevel( - input: CreateInventoryLevelInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - const [result] = await this.createInventoryLevels([input], context) - - return result - } - - /** - * Updates an inventory item - * @param inventoryItemId - the id of the inventory item to update - * @param input - the input object - * @param context - * @return The updated inventory item - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async updateInventoryItem( - inventoryItemId: string, - input: Partial, - @MedusaContext() context: SharedContext = {} - ): Promise { - const inventoryItem = await this.inventoryItemService_.update( - inventoryItemId, - input, - context - ) - return { ...inventoryItem } - } - - /** - * Deletes an inventory item - * @param inventoryItemId - the id of the inventory item to delete - * @param context - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async deleteInventoryItem( - inventoryItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - await this.inventoryLevelService_.deleteByInventoryItemId( - inventoryItemId, - context - ) - - return await this.inventoryItemService_.delete(inventoryItemId, context) - } - - /** - * Restore an inventory item and levels - * @param inventoryItemId - the id of the inventory item to delete - * @param context - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async restoreInventoryItem( - inventoryItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - await this.inventoryLevelService_.restoreByInventoryItemId( - inventoryItemId, - context - ) - - return await this.inventoryItemService_.restore(inventoryItemId, context) - } - - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async deleteInventoryItemLevelByLocationId( - locationId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.inventoryLevelService_.deleteByLocationId( - locationId, - context - ) - } - - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async deleteReservationItemByLocationId( - locationId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.reservationItemService_.deleteByLocationId( - locationId, - context - ) - } - - /** - * Deletes an inventory level - * @param inventoryItemId - the id of the inventory item associated with the level - * @param locationId - the id of the location associated with the level - * @param context - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async deleteInventoryLevel( - inventoryItemId: string, - locationId: string, - @MedusaContext() context: SharedContext = {} - ): Promise { - const [inventoryLevel] = await this.inventoryLevelService_.list( - { inventory_item_id: inventoryItemId, location_id: locationId }, - { take: 1 }, - context - ) - - if (!inventoryLevel) { - return - } - - return await this.inventoryLevelService_.delete(inventoryLevel.id, context) - } - - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async updateInventoryLevels( - updates: ({ - inventory_item_id: string - location_id: string - } & UpdateInventoryLevelInput)[], - context?: SharedContext - ): Promise { - const inventoryLevels = await this.ensureInventoryLevels(updates) - - const levelMap = inventoryLevels.reduce((acc, curr) => { - const inventoryLevelMap = acc.get(curr.inventory_item_id) ?? new Map() - inventoryLevelMap.set(curr.location_id, curr.id) - acc.set(curr.inventory_item_id, inventoryLevelMap) - return acc - }, new Map()) - - return await promiseAll( - updates.map(async (update) => { - const levelId = levelMap - .get(update.inventory_item_id) - .get(update.location_id) - - // TODO make this bulk - return this.inventoryLevelService_.update(levelId, update, context) - }) - ) - } - - /** - * Updates an inventory level - * @param inventoryItemId - the id of the inventory item associated with the level - * @param locationId - the id of the location associated with the level - * @param input - the input object - * @param context - * @return The updated inventory level - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async updateInventoryLevel( - inventoryItemId: string, - locationIdOrContext?: string, - input?: UpdateInventoryLevelInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - const updates: BulkUpdateInventoryLevelInput[] = [ - { - inventory_item_id: inventoryItemId, - location_id: locationIdOrContext as string, - ...input, - }, - ] - - const [result] = await this.updateInventoryLevels(updates, context) - - return result - } - - /** - * Updates a reservation item - * @param reservationItemId - * @param input - the input object - * @param context - * @param context - * @return The updated inventory level - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async updateReservationItem( - reservationItemId: string, - input: UpdateReservationItemInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.reservationItemService_.update( - reservationItemId, - input, - context - ) - } - - /** - * Deletes reservation items by line item - * @param lineItemId - the id of the line item associated with the reservation item - * @param context - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async deleteReservationItemsByLineItem( - lineItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.reservationItemService_.deleteByLineItem( - lineItemId, - context - ) - } - - /** - * Deletes a reservation item - * @param reservationItemId - the id of the reservation item to delete - * @param context - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async deleteReservationItem( - reservationItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - return await this.reservationItemService_.delete(reservationItemId, context) - } - - /** - * Adjusts the inventory level for a given inventory item and location. - * @param inventoryItemId - the id of the inventory item - * @param locationId - the id of the location - * @param adjustment - the number to adjust the inventory by (can be positive or negative) - * @param context - * @return The updated inventory level - * @throws when the inventory level is not found - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async adjustInventory( - inventoryItemId: string, - locationId: string, - adjustment: number, - @MedusaContext() context: SharedContext = {} - ): Promise { - const [inventoryLevel] = await this.inventoryLevelService_.list( - { inventory_item_id: inventoryItemId, location_id: locationId }, - { take: 1 }, - context - ) - if (!inventoryLevel) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `Inventory level for inventory item ${inventoryItemId} and location ${locationId} not found` - ) - } - - const updatedInventoryLevel = await this.inventoryLevelService_.update( - inventoryLevel.id, - { - stocked_quantity: inventoryLevel.stocked_quantity + adjustment, - }, - context - ) - - return { ...updatedInventoryLevel } - } - - /** - * Retrieves the available quantity of a given inventory item in a given location. - * @param inventoryItemId - the id of the inventory item - * @param locationIds - the ids of the locations to check - * @param context - * @return The available quantity - * @throws when the inventory item is not found - */ - async retrieveAvailableQuantity( - inventoryItemId: string, - locationIds: string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - // Throws if item does not exist - await this.inventoryItemService_.retrieve( - inventoryItemId, - { - select: ["id"], - }, - context - ) - - if (locationIds.length === 0) { - return 0 - } - - const availableQuantity = - await this.inventoryLevelService_.getAvailableQuantity( - inventoryItemId, - locationIds, - context - ) - - return availableQuantity - } - - /** - * Retrieves the stocked quantity of a given inventory item in a given location. - * @param inventoryItemId - the id of the inventory item - * @param locationIds - the ids of the locations to check - * @param context - * @return The stocked quantity - * @throws when the inventory item is not found - */ - async retrieveStockedQuantity( - inventoryItemId: string, - locationIds: string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - // Throws if item does not exist - await this.inventoryItemService_.retrieve( - inventoryItemId, - { - select: ["id"], - }, - context - ) - - if (locationIds.length === 0) { - return 0 - } - - const stockedQuantity = - await this.inventoryLevelService_.getStockedQuantity( - inventoryItemId, - locationIds, - context - ) - - return stockedQuantity - } - - /** - * Retrieves the reserved quantity of a given inventory item in a given location. - * @param inventoryItemId - the id of the inventory item - * @param locationIds - the ids of the locations to check - * @param context - * @return The reserved quantity - * @throws when the inventory item is not found - */ - async retrieveReservedQuantity( - inventoryItemId: string, - locationIds: string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - // Throws if item does not exist - await this.inventoryItemService_.retrieve( - inventoryItemId, - { - select: ["id"], - }, - context - ) - - if (locationIds.length === 0) { - return 0 - } - - const reservedQuantity = - await this.inventoryLevelService_.getReservedQuantity( - inventoryItemId, - locationIds, - context - ) - - return reservedQuantity - } - - /** - * Confirms whether there is sufficient inventory for a given quantity of a given inventory item in a given location. - * @param inventoryItemId - the id of the inventory item - * @param locationIds - the ids of the locations to check - * @param quantity - the quantity to check - * @param context - * @return Whether there is sufficient inventory - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async confirmInventory( - inventoryItemId: string, - locationIds: string[], - quantity: number, - @MedusaContext() context: SharedContext = {} - ): Promise { - const availableQuantity = await this.retrieveAvailableQuantity( - inventoryItemId, - locationIds, - context - ) - return availableQuantity >= quantity - } -} diff --git a/packages/inventory/src/services/reservation-item.ts b/packages/inventory/src/services/reservation-item.ts deleted file mode 100644 index a45675c28f..0000000000 --- a/packages/inventory/src/services/reservation-item.ts +++ /dev/null @@ -1,340 +0,0 @@ -import { - CreateReservationItemInput, - FilterableReservationItemProps, - FindConfig, - IEventBusService, - SharedContext, - UpdateReservationItemInput, -} from "@medusajs/types" -import { - InjectEntityManager, - MedusaContext, - MedusaError, - isDefined, - promiseAll, -} from "@medusajs/utils" -import { EntityManager, FindManyOptions, In } from "typeorm" -import { InventoryLevelService } from "." -import { ReservationItem } from "../models" -import { buildQuery } from "../utils/build-query" - -type InjectedDependencies = { - eventBusService: IEventBusService - manager: EntityManager - inventoryLevelService: InventoryLevelService -} - -export default class ReservationItemService { - static Events = { - CREATED: "reservation-item.created", - UPDATED: "reservation-item.updated", - DELETED: "reservation-item.deleted", - } - - protected readonly manager_: EntityManager - protected readonly eventBusService_: IEventBusService | undefined - protected readonly inventoryLevelService_: InventoryLevelService - - constructor({ - eventBusService, - inventoryLevelService, - manager, - }: InjectedDependencies) { - this.manager_ = manager - this.eventBusService_ = eventBusService - this.inventoryLevelService_ = inventoryLevelService - } - - /** - * Lists reservation items that match the provided filter. - * @param selector - Filters to apply to the reservation items. - * @param config - Configuration for the query. - * @param context - * @return Array of reservation items that match the selector. - */ - async list( - selector: FilterableReservationItemProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager ?? this.manager_ - const itemRepository = manager.getRepository(ReservationItem) - - const query = buildQuery(selector, config) as FindManyOptions - - return await itemRepository.find(query) - } - - /** - * Lists reservation items that match the provided filter and returns the total count. - * @param selector - Filters to apply to the reservation items. - * @param config - Configuration for the query. - * @param context - * @return Array of reservation items that match the selector and the total count. - */ - async listAndCount( - selector: FilterableReservationItemProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise<[ReservationItem[], number]> { - const manager = context.transactionManager ?? this.manager_ - const itemRepository = manager.getRepository(ReservationItem) - - const query = buildQuery(selector, config) as FindManyOptions - - return await itemRepository.findAndCount(query) - } - - /** - * Retrieves a reservation item by its id. - * @param reservationItemId - The id of the reservation item to retrieve. - * @param config - Configuration for the query. - * @param context - * @return The reservation item with the provided id. - * @throws If reservationItemId is not defined or if the reservation item was not found. - */ - async retrieve( - reservationItemId: string, - config: FindConfig = {}, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!isDefined(reservationItemId)) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `"reservationItemId" must be defined` - ) - } - - const manager = context.transactionManager ?? this.manager_ - const reservationItemRepository = manager.getRepository(ReservationItem) - - const query = buildQuery( - { id: reservationItemId }, - config - ) as FindManyOptions - const [reservationItem] = await reservationItemRepository.find(query) - - if (!reservationItem) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `ReservationItem with id ${reservationItemId} was not found` - ) - } - - return reservationItem - } - - /** - * Create a new reservation item. - * @param data - The reservation item data. - * @param context - * @return The created reservation item. - */ - @InjectEntityManager() - async create( - data: CreateReservationItemInput[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const reservationItemRepository = manager.getRepository(ReservationItem) - - const reservationItems = reservationItemRepository.create( - data.map((tc) => ({ - inventory_item_id: tc.inventory_item_id, - line_item_id: tc.line_item_id, - location_id: tc.location_id, - quantity: tc.quantity, - metadata: tc.metadata, - external_id: tc.external_id, - description: tc.description, - created_by: tc.created_by, - })) - ) - - const [newReservationItems] = await promiseAll([ - reservationItemRepository.save(reservationItems), - ...data.map( - async (data) => - // TODO make bulk - await this.inventoryLevelService_.adjustReservedQuantity( - data.inventory_item_id, - data.location_id, - data.quantity, - context - ) - ), - ]) - - await this.eventBusService_?.emit?.(ReservationItemService.Events.CREATED, { - ids: newReservationItems.map((i) => i.id), - }) - - return newReservationItems - } - - /** - * Update a reservation item. - * @param reservationItemId - The reservation item's id. - * @param data - The reservation item data to update. - * @param context - * @return The updated reservation item. - */ - @InjectEntityManager() - async update( - reservationItemId: string, - data: UpdateReservationItemInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const itemRepository = manager.getRepository(ReservationItem) - - const item = await this.retrieve(reservationItemId, undefined, context) - - const shouldUpdateQuantity = - isDefined(data.quantity) && data.quantity !== item.quantity - - const shouldUpdateLocation = - isDefined(data.location_id) && data.location_id !== item.location_id - - const ops: Promise[] = [] - - if (shouldUpdateLocation) { - ops.push( - this.inventoryLevelService_.adjustReservedQuantity( - item.inventory_item_id, - item.location_id, - item.quantity * -1, - context - ), - this.inventoryLevelService_.adjustReservedQuantity( - item.inventory_item_id, - data.location_id!, - data.quantity || item.quantity!, - context - ) - ) - } else if (shouldUpdateQuantity) { - const quantityDiff = data.quantity! - item.quantity - ops.push( - this.inventoryLevelService_.adjustReservedQuantity( - item.inventory_item_id, - item.location_id, - quantityDiff, - context - ) - ) - } - - const mergedItem = itemRepository.merge(item, data) - - ops.push(itemRepository.save(item)) - - await promiseAll(ops) - - await this.eventBusService_?.emit?.(ReservationItemService.Events.UPDATED, { - id: mergedItem.id, - }) - - return mergedItem - } - - /** - * Deletes a reservation item by line item id. - * @param lineItemId - the id of the line item to delete. - * @param context - */ - @InjectEntityManager() - async deleteByLineItem( - lineItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const itemRepository = manager.getRepository(ReservationItem) - - const lineItemIds = Array.isArray(lineItemId) ? lineItemId : [lineItemId] - - const reservationItems = await this.list( - { line_item_id: lineItemIds }, - undefined, - context - ) - - const ops: Promise[] = [ - itemRepository.softDelete({ line_item_id: In(lineItemIds) }), - ] - - for (const reservation of reservationItems) { - ops.push( - this.inventoryLevelService_.adjustReservedQuantity( - reservation.inventory_item_id, - reservation.location_id, - reservation.quantity * -1, - context - ) - ) - } - - await promiseAll(ops) - - await this.eventBusService_?.emit?.(ReservationItemService.Events.DELETED, { - line_item_id: lineItemId, - }) - } - - /** - * Deletes reservation items by location ID. - * @param locationId - The ID of the location to delete reservations for. - * @param context - */ - @InjectEntityManager() - async deleteByLocationId( - locationId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const itemRepository = manager.getRepository(ReservationItem) - - const ids = Array.isArray(locationId) ? locationId : [locationId] - - await itemRepository.softDelete({ location_id: In(ids) }) - - await this.eventBusService_?.emit?.(ReservationItemService.Events.DELETED, { - location_id: locationId, - }) - } - - /** - * Deletes a reservation item by id. - * @param reservationItemId - the id of the reservation item to delete. - * @param context - */ - @InjectEntityManager() - async delete( - reservationItemId: string | string[], - @MedusaContext() context: SharedContext = {} - ): Promise { - const ids = Array.isArray(reservationItemId) - ? reservationItemId - : [reservationItemId] - const manager = context.transactionManager! - const itemRepository = manager.getRepository(ReservationItem) - const items = await this.list({ id: ids }, undefined, context) - - const promises: Promise[] = items.map(async (item) => { - await this.inventoryLevelService_.adjustReservedQuantity( - item.inventory_item_id, - item.location_id, - item.quantity * -1, - context - ) - }) - - promises.push(itemRepository.softRemove(items)) - - await promiseAll(promises) - - await this.eventBusService_?.emit?.(ReservationItemService.Events.DELETED, { - ids: reservationItemId, - }) - } -} diff --git a/packages/inventory/src/types/index.ts b/packages/inventory/src/types/index.ts deleted file mode 100644 index adaa82e6d6..0000000000 --- a/packages/inventory/src/types/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { DatabaseType } from "typeorm" - -export type InventoryServiceInitializeOptions = { - database?: { - type?: DatabaseType | string - url?: string - database?: string - extra?: Record - schema?: string - logging?: boolean - } -} diff --git a/packages/inventory/src/utils/build-query.ts b/packages/inventory/src/utils/build-query.ts deleted file mode 100644 index ee59ece03d..0000000000 --- a/packages/inventory/src/utils/build-query.ts +++ /dev/null @@ -1,166 +0,0 @@ -import { ExtendedFindConfig, FindConfig } from "@medusajs/types" -import { - And, - FindManyOptions, - FindOperator, - FindOptionsOrder, - FindOptionsRelations, - FindOptionsSelect, - FindOptionsWhere, - ILike, - In, - IsNull, - LessThan, - LessThanOrEqual, - MoreThan, - MoreThanOrEqual, -} from "typeorm" -import { buildOrder, buildRelations, buildSelects } from "@medusajs/utils" - -const operatorsMap = { - lt: (value) => LessThan(value), - gt: (value) => MoreThan(value), - lte: (value) => LessThanOrEqual(value), - gte: (value) => MoreThanOrEqual(value), - contains: (value) => ILike(`%${value}%`), - starts_with: (value) => ILike(`${value}%`), - ends_with: (value) => ILike(`%${value}`), -} - -/** - * Used to build TypeORM queries. - * @param selector The selector - * @param config The config - * @return The QueryBuilderConfig - */ -export function buildQuery( - selector: TWhereKeys, - config: FindConfig = {} -) { - const query: ExtendedFindConfig = { - where: buildWhere(selector), - } - - if ("deleted_at" in selector || config.withDeleted) { - query.withDeleted = true - } - - if ("skip" in config) { - ;(query as FindManyOptions).skip = config.skip ?? undefined - } - - if ("take" in config) { - ;(query as FindManyOptions).take = config.take ?? undefined - } - - if (config.relations) { - query.relations = buildRelations( - config.relations - ) as FindOptionsRelations - } - - if (config.select) { - query.select = buildSelects( - config.select as string[] - ) as FindOptionsSelect - } - - if (config.order) { - query.order = buildOrder(config.order) as FindOptionsOrder - } - - return query -} - -/** - * @param constraints - * - * @example - * const q = buildWhere( - * { - * id: "1234", - * test1: ["123", "12", "1"], - * test2: Not("this"), - * date: { gt: date }, - * amount: { gt: 10 }, - * }, - *) - * - * // Output - * { - * id: "1234", - * test1: In(["123", "12", "1"]), - * test2: Not("this"), - * date: MoreThan(date), - * amount: MoreThan(10) - * } - */ -function buildWhere( - constraints: TWhereKeys -): FindOptionsWhere | FindOptionsWhere[] { - let where: FindOptionsWhere | FindOptionsWhere[] = {} - - if (Array.isArray(constraints)) { - where = [] - constraints.forEach((constraint) => { - ;(where as FindOptionsWhere[]).push( - buildWhere(constraint) as FindOptionsWhere - ) - }) - - return where - } - - for (const [key, value] of Object.entries(constraints)) { - if (value === undefined) { - continue - } - - if (value === null) { - where[key] = IsNull() - continue - } - - if (value instanceof FindOperator) { - where[key] = value - continue - } - - if (Array.isArray(value)) { - where[key] = In(value) - continue - } - - if (typeof value === "object") { - Object.entries(value).forEach(([objectKey, objectValue]) => { - where[key] = where[key] || [] - if (operatorsMap[objectKey]) { - where[key].push(operatorsMap[objectKey](objectValue)) - } else { - if (objectValue != undefined && typeof objectValue === "object") { - where[key] = buildWhere(objectValue) - return - } - where[key] = value - } - return - }) - - if (!Array.isArray(where[key])) { - continue - } - - if (where[key].length === 1) { - where[key] = where[key][0] - } else { - where[key] = And(...where[key]) - } - - continue - } - - where[key] = value - } - - return where -} diff --git a/packages/inventory/src/utils/query.ts b/packages/inventory/src/utils/query.ts deleted file mode 100644 index 386628d242..0000000000 --- a/packages/inventory/src/utils/query.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { - ExtendedFindConfig, - FilterableInventoryItemProps, - FindConfig, -} from "@medusajs/types" -import { objectToStringPath } from "@medusajs/utils" -import { EntityManager, FindOptionsWhere, Brackets } from "typeorm" - -import { InventoryItem } from "../models" -import { buildQuery } from "./build-query" - -export function getListQuery( - manager: EntityManager, - selector: FilterableInventoryItemProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 } -) { - const inventoryItemRepository = manager.getRepository(InventoryItem) - - const { q, ...selectorRest } = selector - const query = buildQuery( - selectorRest, - config - ) as ExtendedFindConfig & { - where: FindOptionsWhere< - InventoryItem & { - location_id?: string - } - > - } - - const queryBuilder = inventoryItemRepository.createQueryBuilder("inv_item") - - if ("location_id" in query.where) { - const locationIds = Array.isArray(selector.location_id) - ? selector.location_id - : [selector.location_id] - - queryBuilder.innerJoin( - "inventory_level", - "level", - "level.inventory_item_id = inv_item.id AND level.location_id IN (:...locationIds)", - { locationIds } - ) - - delete query.where.location_id - } - - if (q) { - queryBuilder.where(query.where).andWhere( - new Brackets((qb) => { - qb.where("inv_item.sku ILike :q", { q: `%${q}%` }) - .orWhere("inv_item.description ILike :q", { q: `%${q}%` }) - .orWhere("inv_item.title ILike :q", { q: `%${q}%` }) - }) - ) - } else { - queryBuilder.where(query.where) - } - - if (query.take) { - queryBuilder.take(query.take) - } - - if (query.skip) { - queryBuilder.skip(query.skip) - } - - if (query.select) { - const legacySelect = objectToStringPath(query.select) - queryBuilder.select(legacySelect.map((s) => "inv_item." + s)) - } - - if (query.withDeleted) { - queryBuilder.withDeleted() - } - - if (query.order) { - const toSelect: string[] = [] - const parsed = Object.entries(query.order).reduce((acc, [k, v]) => { - const key = `inv_item.${k}` - if (!query.select?.[k]) { - toSelect.push(key) - } - acc[key] = v - return acc - }, {}) - queryBuilder.addSelect(toSelect) - queryBuilder.orderBy(parsed) - } - - return queryBuilder -} diff --git a/packages/inventory/tsconfig.json b/packages/inventory/tsconfig.json deleted file mode 100644 index c92a3d6ed2..0000000000 --- a/packages/inventory/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "lib": ["es2020"], - "target": "ES2020", - "outDir": "./dist", - "esModuleInterop": true, - "declaration": true, - "module": "commonjs", - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "sourceMap": true, - "noImplicitReturns": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "noImplicitThis": true, - "allowJs": true, - "skipLibCheck": true - }, - "include": ["src"], - "exclude": [ - "dist", - "./src/**/__tests__", - "./src/**/__mocks__", - "node_modules" - ] -} diff --git a/packages/inventory/tsconfig.spec.json b/packages/inventory/tsconfig.spec.json deleted file mode 100644 index 9b62409191..0000000000 --- a/packages/inventory/tsconfig.spec.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["src"], - "exclude": ["node_modules"] -} diff --git a/packages/modules-sdk/src/definitions.ts b/packages/modules-sdk/src/definitions.ts index 062b636c99..7f8e63d673 100644 --- a/packages/modules-sdk/src/definitions.ts +++ b/packages/modules-sdk/src/definitions.ts @@ -69,7 +69,7 @@ export const MODULE_PACKAGE_NAMES = { [Modules.CART]: "@medusajs/cart", [Modules.CUSTOMER]: "@medusajs/customer", [Modules.EVENT_BUS]: "@medusajs/event-bus-local", - [Modules.INVENTORY]: "@medusajs/inventory", + [Modules.INVENTORY]: "@medusajs/inventory-next", // TODO: To be replaced when current `@medusajs/inventory` is deprecated [Modules.LINK]: "@medusajs/link-modules", [Modules.PAYMENT]: "@medusajs/payment", [Modules.PRICING]: "@medusajs/pricing", @@ -77,7 +77,7 @@ export const MODULE_PACKAGE_NAMES = { [Modules.PROMOTION]: "@medusajs/promotion", [Modules.SALES_CHANNEL]: "@medusajs/sales-channel", [Modules.FULFILLMENT]: "@medusajs/fulfillment", - [Modules.STOCK_LOCATION]: "@medusajs/stock-location", + [Modules.STOCK_LOCATION]: "@medusajs/stock-location-next", // TODO: To be replaced when current `@medusajs/stock-location` is deprecated [Modules.TAX]: "@medusajs/tax", [Modules.USER]: "@medusajs/user", [Modules.WORKFLOW_ENGINE]: "@medusajs/workflow-engine-inmemory", diff --git a/packages/inventory/.gitignore b/packages/modules/user/.gitignore similarity index 100% rename from packages/inventory/.gitignore rename to packages/modules/user/.gitignore diff --git a/packages/user/CHANGELOG.md b/packages/modules/user/CHANGELOG.md similarity index 100% rename from packages/user/CHANGELOG.md rename to packages/modules/user/CHANGELOG.md diff --git a/packages/user/README.md b/packages/modules/user/README.md similarity index 100% rename from packages/user/README.md rename to packages/modules/user/README.md diff --git a/packages/user/integration-tests/__fixtures__/invite.ts b/packages/modules/user/integration-tests/__fixtures__/invite.ts similarity index 100% rename from packages/user/integration-tests/__fixtures__/invite.ts rename to packages/modules/user/integration-tests/__fixtures__/invite.ts diff --git a/packages/user/integration-tests/__fixtures__/user.ts b/packages/modules/user/integration-tests/__fixtures__/user.ts similarity index 100% rename from packages/user/integration-tests/__fixtures__/user.ts rename to packages/modules/user/integration-tests/__fixtures__/user.ts diff --git a/packages/user/integration-tests/__tests__/services/module/invite.spec.ts b/packages/modules/user/integration-tests/__tests__/services/module/invite.spec.ts similarity index 100% rename from packages/user/integration-tests/__tests__/services/module/invite.spec.ts rename to packages/modules/user/integration-tests/__tests__/services/module/invite.spec.ts diff --git a/packages/user/integration-tests/__tests__/services/module/user.spec.ts b/packages/modules/user/integration-tests/__tests__/services/module/user.spec.ts similarity index 100% rename from packages/user/integration-tests/__tests__/services/module/user.spec.ts rename to packages/modules/user/integration-tests/__tests__/services/module/user.spec.ts diff --git a/packages/user/jest.config.js b/packages/modules/user/jest.config.js similarity index 100% rename from packages/user/jest.config.js rename to packages/modules/user/jest.config.js diff --git a/packages/user/mikro-orm.config.dev.ts b/packages/modules/user/mikro-orm.config.dev.ts similarity index 100% rename from packages/user/mikro-orm.config.dev.ts rename to packages/modules/user/mikro-orm.config.dev.ts diff --git a/packages/user/package.json b/packages/modules/user/package.json similarity index 100% rename from packages/user/package.json rename to packages/modules/user/package.json diff --git a/packages/user/src/index.ts b/packages/modules/user/src/index.ts similarity index 100% rename from packages/user/src/index.ts rename to packages/modules/user/src/index.ts diff --git a/packages/user/src/initialize/index.ts b/packages/modules/user/src/initialize/index.ts similarity index 100% rename from packages/user/src/initialize/index.ts rename to packages/modules/user/src/initialize/index.ts diff --git a/packages/user/src/joiner-config.ts b/packages/modules/user/src/joiner-config.ts similarity index 100% rename from packages/user/src/joiner-config.ts rename to packages/modules/user/src/joiner-config.ts diff --git a/packages/user/src/loaders/connection.ts b/packages/modules/user/src/loaders/connection.ts similarity index 100% rename from packages/user/src/loaders/connection.ts rename to packages/modules/user/src/loaders/connection.ts diff --git a/packages/user/src/loaders/container.ts b/packages/modules/user/src/loaders/container.ts similarity index 100% rename from packages/user/src/loaders/container.ts rename to packages/modules/user/src/loaders/container.ts diff --git a/packages/inventory/src/loaders/index.ts b/packages/modules/user/src/loaders/index.ts similarity index 100% rename from packages/inventory/src/loaders/index.ts rename to packages/modules/user/src/loaders/index.ts diff --git a/packages/user/src/migrations/.snapshot-medusa-user.json b/packages/modules/user/src/migrations/.snapshot-medusa-user.json similarity index 100% rename from packages/user/src/migrations/.snapshot-medusa-user.json rename to packages/modules/user/src/migrations/.snapshot-medusa-user.json diff --git a/packages/user/src/migrations/Migration20240214033943.ts b/packages/modules/user/src/migrations/Migration20240214033943.ts similarity index 100% rename from packages/user/src/migrations/Migration20240214033943.ts rename to packages/modules/user/src/migrations/Migration20240214033943.ts diff --git a/packages/user/src/models/index.ts b/packages/modules/user/src/models/index.ts similarity index 100% rename from packages/user/src/models/index.ts rename to packages/modules/user/src/models/index.ts diff --git a/packages/user/src/models/invite.ts b/packages/modules/user/src/models/invite.ts similarity index 100% rename from packages/user/src/models/invite.ts rename to packages/modules/user/src/models/invite.ts diff --git a/packages/user/src/models/user.ts b/packages/modules/user/src/models/user.ts similarity index 100% rename from packages/user/src/models/user.ts rename to packages/modules/user/src/models/user.ts diff --git a/packages/user/src/module-definition.ts b/packages/modules/user/src/module-definition.ts similarity index 100% rename from packages/user/src/module-definition.ts rename to packages/modules/user/src/module-definition.ts diff --git a/packages/user/src/repositories/index.ts b/packages/modules/user/src/repositories/index.ts similarity index 100% rename from packages/user/src/repositories/index.ts rename to packages/modules/user/src/repositories/index.ts diff --git a/packages/user/src/scripts/bin/run-seed.ts b/packages/modules/user/src/scripts/bin/run-seed.ts similarity index 100% rename from packages/user/src/scripts/bin/run-seed.ts rename to packages/modules/user/src/scripts/bin/run-seed.ts diff --git a/packages/user/src/scripts/seed.ts b/packages/modules/user/src/scripts/seed.ts similarity index 100% rename from packages/user/src/scripts/seed.ts rename to packages/modules/user/src/scripts/seed.ts diff --git a/packages/user/src/services/index.ts b/packages/modules/user/src/services/index.ts similarity index 100% rename from packages/user/src/services/index.ts rename to packages/modules/user/src/services/index.ts diff --git a/packages/user/src/services/invite.ts b/packages/modules/user/src/services/invite.ts similarity index 100% rename from packages/user/src/services/invite.ts rename to packages/modules/user/src/services/invite.ts diff --git a/packages/user/src/services/user-module.ts b/packages/modules/user/src/services/user-module.ts similarity index 100% rename from packages/user/src/services/user-module.ts rename to packages/modules/user/src/services/user-module.ts diff --git a/packages/user/src/types/index.ts b/packages/modules/user/src/types/index.ts similarity index 100% rename from packages/user/src/types/index.ts rename to packages/modules/user/src/types/index.ts diff --git a/packages/user/src/types/services/index.ts b/packages/modules/user/src/types/services/index.ts similarity index 100% rename from packages/user/src/types/services/index.ts rename to packages/modules/user/src/types/services/index.ts diff --git a/packages/user/src/types/services/invite.ts b/packages/modules/user/src/types/services/invite.ts similarity index 100% rename from packages/user/src/types/services/invite.ts rename to packages/modules/user/src/types/services/invite.ts diff --git a/packages/user/tsconfig.json b/packages/modules/user/tsconfig.json similarity index 100% rename from packages/user/tsconfig.json rename to packages/modules/user/tsconfig.json diff --git a/packages/user/tsconfig.spec.json b/packages/modules/user/tsconfig.spec.json similarity index 100% rename from packages/user/tsconfig.spec.json rename to packages/modules/user/tsconfig.spec.json diff --git a/packages/stock-location/.gitignore b/packages/stock-location/.gitignore deleted file mode 100644 index 874c6c69d3..0000000000 --- a/packages/stock-location/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/dist -node_modules -.DS_store -.env* -.env -*.sql diff --git a/packages/stock-location/CHANGELOG.md b/packages/stock-location/CHANGELOG.md deleted file mode 100644 index e54ae02133..0000000000 --- a/packages/stock-location/CHANGELOG.md +++ /dev/null @@ -1,263 +0,0 @@ -# @medusajs/stock-location - -## 1.11.5 - -### Patch Changes - -- [#6263](https://github.com/medusajs/medusa/pull/6263) [`45134e4d1`](https://github.com/medusajs/medusa/commit/45134e4d11cfcdc08dbd10aae687bfbe9e848ab9) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Workflows passing MedusaContext as argument - -- [#6197](https://github.com/medusajs/medusa/pull/6197) [`d1c18a309`](https://github.com/medusajs/medusa/commit/d1c18a3090d71c68a98343fdbb53516f416504c5) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(stock-location, medusa, types): add `q` and `order` query parameters to stock locations list endpoint - -- Updated dependencies [[`12054f5c0`](https://github.com/medusajs/medusa/commit/12054f5c01915899223ddc6da734151b31fbb23b), [`3db2f95e65`](https://github.com/medusajs/medusa/commit/3db2f95e65909f4fff432990b48be74509052e83), [`96ba49329`](https://github.com/medusajs/medusa/commit/96ba49329b6b05922c90f0c55f16455cb40aa5ca), [`45134e4d1`](https://github.com/medusajs/medusa/commit/45134e4d11cfcdc08dbd10aae687bfbe9e848ab9), [`884428a1b`](https://github.com/medusajs/medusa/commit/884428a1b573e499d7659aefed639bf797147428), [`882aa549b`](https://github.com/medusajs/medusa/commit/882aa549bdcc6f378934eab2a7c485df354f46aa)]: - - @medusajs/utils@1.11.5 - - @medusajs/modules-sdk@1.12.8 - -## 1.11.4 - -### Patch Changes - -- [#5763](https://github.com/medusajs/medusa/pull/5763) [`d85fee42e`](https://github.com/medusajs/medusa/commit/d85fee42ee7f661310584dfee5741d6c53b989bb) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Medusa App loading modules reference - -- [#6012](https://github.com/medusajs/medusa/pull/6012) [`192bc336cc`](https://github.com/medusajs/medusa/commit/192bc336cc2b6ec3820d94524c046dcd3c4ac7d9) Thanks [@olivermrbl](https://github.com/olivermrbl)! - feat(cart): Partial module service implementation - -- Updated dependencies [[`68ddd866a5`](https://github.com/medusajs/medusa/commit/68ddd866a5ff9414e2db5b80d75acc5e81948540), [`72bc52231c`](https://github.com/medusajs/medusa/commit/72bc52231ca3a72fa6d197a248fe07a938ed0d85), [`99045848f`](https://github.com/medusajs/medusa/commit/99045848fd3e863359c7878d9bc05271ed083a0e), [`a9b4214503`](https://github.com/medusajs/medusa/commit/a9b42145032ee88aa922a11fe03e777b140c68f4), [`d85fee42e`](https://github.com/medusajs/medusa/commit/d85fee42ee7f661310584dfee5741d6c53b989bb), [`5e655dd59`](https://github.com/medusajs/medusa/commit/5e655dd59bda4ffface28db38021ba71cae6de10), [`b782d3bcb7`](https://github.com/medusajs/medusa/commit/b782d3bcb7e8088a962584b9a55200dd29c2161c), [`2b9f98895e`](https://github.com/medusajs/medusa/commit/2b9f98895eaca255e01278674b11cd7cb69b388f), [`302323916`](https://github.com/medusajs/medusa/commit/302323916b6d8eaf571cd59b5fc92a913af207de), [`da5cc4cf7`](https://github.com/medusajs/medusa/commit/da5cc4cf7f7f0ef40d409704a95b025ce95477f4), [`daecd82a7`](https://github.com/medusajs/medusa/commit/daecd82a7cdf7315599f464999690414c20d6748), [`06b33a9b4`](https://github.com/medusajs/medusa/commit/06b33a9b4525b77b1b14b35b973209700945654e), [`b6ac768698`](https://github.com/medusajs/medusa/commit/b6ac768698a3b49d0162cb49e628386f3352d034), [`130c641e5c`](https://github.com/medusajs/medusa/commit/130c641e5c91cf831de64fb87aebbfdc4d23530d), [`fade8ea7bf`](https://github.com/medusajs/medusa/commit/fade8ea7bf560343ecbde116d226ac44053cdb8e), [`8472460f53`](https://github.com/medusajs/medusa/commit/8472460f533322cc4535199aa768ac163021bc79)]: - - @medusajs/utils@1.11.4 - - @medusajs/modules-sdk@1.12.7 - -## 1.11.3 - -### Patch Changes - -- [#5713](https://github.com/medusajs/medusa/pull/5713) [`18afe0b9a`](https://github.com/medusajs/medusa/commit/18afe0b9addb33ec2e3b285651b4eb1ef8065845) Thanks [@pKorsholm](https://github.com/pKorsholm)! - fix(stock-location, inventory, medusa, types, utils): allow buildQuery to take null as an argument in order to prevent default pagination - -- Updated dependencies [[`18afe0b9a`](https://github.com/medusajs/medusa/commit/18afe0b9addb33ec2e3b285651b4eb1ef8065845), [`de8f74867`](https://github.com/medusajs/medusa/commit/de8f748674bfd19b3dbadb9695d9080aa91940de), [`dc5750dd6`](https://github.com/medusajs/medusa/commit/dc5750dd665a91d35c0246ba83c7f90ec74907f4)]: - - @medusajs/utils@1.11.1 - - @medusajs/modules-sdk@1.12.4 - -## 1.11.2 - -### Patch Changes - -- [`d2309e771`](https://github.com/medusajs/medusa/commit/d2309e771de1cb0366a8480787a52c2f01c859ea) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore(changesets): Add missing stock-location changeset - -- Updated dependencies [[`c39bf69a5`](https://github.com/medusajs/medusa/commit/c39bf69a5e5cae75d7fa12aa6022b10903557a32), [`154c9b43b`](https://github.com/medusajs/medusa/commit/154c9b43bde1fdff562aba9da8a79af2660b29b3)]: - - @medusajs/modules-sdk@1.12.3 - - @medusajs/utils@1.10.5 - -## 1.11.1 - -### Patch Changes - -- [#5468](https://github.com/medusajs/medusa/pull/5468) [`a45da9215`](https://github.com/medusajs/medusa/commit/a45da9215d2a7834c368037726aaa3961caadaf9) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(medusa, modules-sdk, modules): Module loading was missing the expected dependencies and remote query reference fix - -- Updated dependencies [[`a45da9215`](https://github.com/medusajs/medusa/commit/a45da9215d2a7834c368037726aaa3961caadaf9)]: - - @medusajs/modules-sdk@1.12.2 - -## 1.11.0 - -### Minor Changes - -- [#5242](https://github.com/medusajs/medusa/pull/5242) [`130cbc1f4`](https://github.com/medusajs/medusa/commit/130cbc1f437af211b6d05f80128d90138abcd38d) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Modules exporting schema with entities and fields - -### Patch Changes - -- Updated dependencies [[`eeceec791`](https://github.com/medusajs/medusa/commit/eeceec791c141996cf7fd06555afb6e738b52840), [`130cbc1f4`](https://github.com/medusajs/medusa/commit/130cbc1f437af211b6d05f80128d90138abcd38d), [`cb569c2df`](https://github.com/medusajs/medusa/commit/cb569c2dfe2d83e1ff72a49f2331450a83b73325)]: - - @medusajs/utils@1.10.3 - - @medusajs/modules-sdk@1.12.0 - -## 1.10.0 - -### Minor Changes - -- [#4695](https://github.com/medusajs/medusa/pull/4695) [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - introduce @medusajs/link-modules - -### Patch Changes - -- Updated dependencies [[`c3dba0694`](https://github.com/medusajs/medusa/commit/c3dba069488952945150117a30b1306a2e0bb3ce), [`460161a69`](https://github.com/medusajs/medusa/commit/460161a69f22cf6d561952e92e7d9b56912113e6), [`fcb6b4f51`](https://github.com/medusajs/medusa/commit/fcb6b4f510dba2757570625acb5da9476b7544fd), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`87bade096`](https://github.com/medusajs/medusa/commit/87bade096e3d536f29ddc57dbc4c04e5d7a46e4b), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`a4906d0ac`](https://github.com/medusajs/medusa/commit/a4906d0ac0af36b1382d3befe64281b404387bd7)]: - - @medusajs/modules-sdk@1.10.0 - - @medusajs/utils@1.10.0 - -## 1.9.1 - -### Patch Changes - -- [#4232](https://github.com/medusajs/medusa/pull/4232) [`af2dc4f75`](https://github.com/medusajs/medusa/commit/af2dc4f75a2ed109495ca83b1bc6ae6941c2f716) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(medusa, inventory, stock-location): Remove unnecessary transaction usage in the modules and list products end points - -- Updated dependencies [[`f98ba5bde`](https://github.com/medusajs/medusa/commit/f98ba5bde83ba785eead31b0c9eb9f135d664178), [`14c0f62f8`](https://github.com/medusajs/medusa/commit/14c0f62f84704a4c87beff3daaff60a52f5c88b8)]: - - @medusajs/utils@1.9.1 - - @medusajs/modules-sdk@1.8.8 - -## 1.9.0 - -### Minor Changes - -- [#4146](https://github.com/medusajs/medusa/pull/4146) [`db4199530`](https://github.com/medusajs/medusa/commit/db419953075e0907b8c4d27ab5188e9bd3e3d72b) Thanks [@fPolic](https://github.com/fPolic)! - chore(medusa, utils, inventory, stock-location): clear deps in the utils package - -### Patch Changes - -- Updated dependencies [[`a91987fab`](https://github.com/medusajs/medusa/commit/a91987fab33745f9864eab21bd1c27e8e3e24571), [`e73c3e51c`](https://github.com/medusajs/medusa/commit/e73c3e51c9cd192eeae7a57b24b07bd466214145), [`db4199530`](https://github.com/medusajs/medusa/commit/db419953075e0907b8c4d27ab5188e9bd3e3d72b), [`c0e527d6e`](https://github.com/medusajs/medusa/commit/c0e527d6e0a67d0c53577a0b9c3d16ee8dc5740f)]: - - @medusajs/utils@1.9.0 - - @medusajs/modules-sdk@1.8.7 - -## 1.8.6 - -### Patch Changes - -- [#4072](https://github.com/medusajs/medusa/pull/4072) [`6511959e2`](https://github.com/medusajs/medusa/commit/6511959e23177f3b4831915db0e8e788bc9047fa) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Revert to official Typeorm package - -- Updated dependencies [[`cdbac2c84`](https://github.com/medusajs/medusa/commit/cdbac2c8403a3c15c0e11993f6b7dab268fa5c08), [`6511959e2`](https://github.com/medusajs/medusa/commit/6511959e23177f3b4831915db0e8e788bc9047fa)]: - - @medusajs/utils@1.8.5 - - @medusajs/modules-sdk@1.8.6 - -## 1.8.5 - -### Patch Changes - -- Updated dependencies [[`1ea57c3a6`](https://github.com/medusajs/medusa/commit/1ea57c3a69a5377a8dd0821df819743ded4a222b)]: - - @medusajs/utils@1.8.4 - - @medusajs/modules-sdk@1.8.5 - -## 1.8.4 - -### Patch Changes - -- [#3981](https://github.com/medusajs/medusa/pull/3981) [`d539c6fee`](https://github.com/medusajs/medusa/commit/d539c6feeba8ee431f9a655b6cd4e9102cba2b25) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Bump Typeorm to Medusa fork - -- Updated dependencies [[`0e488e71b`](https://github.com/medusajs/medusa/commit/0e488e71b186f7d08b18c4c6ba409ef3cadb8152), [`d539c6fee`](https://github.com/medusajs/medusa/commit/d539c6feeba8ee431f9a655b6cd4e9102cba2b25)]: - - @medusajs/utils@1.8.3 - - @medusajs/modules-sdk@1.8.4 - -## 1.8.3 - -### Patch Changes - -- [#3835](https://github.com/medusajs/medusa/pull/3835) [`af710f1b4`](https://github.com/medusajs/medusa/commit/af710f1b48a4545a5064029a557013af34c4c100) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(medusa): Bulk create variant and pass transaction to the inventory service context methods - -- Updated dependencies [[`af710f1b4`](https://github.com/medusajs/medusa/commit/af710f1b48a4545a5064029a557013af34c4c100), [`491566df6`](https://github.com/medusajs/medusa/commit/491566df6b7ced35f655f810961422945e10ecd0)]: - - @medusajs/utils@1.8.2 - - @medusajs/modules-sdk@1.8.3 - -## 1.8.2 - -### Patch Changes - -- Updated dependencies []: - - @medusajs/modules-sdk@1.8.2 - -## 1.8.1 - -### Patch Changes - -- [#3778](https://github.com/medusajs/medusa/pull/3778) [`654a54622`](https://github.com/medusajs/medusa/commit/654a54622303139e7180538bd686630ad9a46cfd) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Bump Typeorm - -- Updated dependencies [[`654a54622`](https://github.com/medusajs/medusa/commit/654a54622303139e7180538bd686630ad9a46cfd), [`abdb74d99`](https://github.com/medusajs/medusa/commit/abdb74d997f49f994bff49787a396179982843b0)]: - - @medusajs/utils@1.8.1 - - @medusajs/modules-sdk@1.8.1 - -## 1.8.0 - -### Minor Changes - -- [#3329](https://github.com/medusajs/medusa/pull/3329) [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Inventory and Stock location modules supporting isolated connection - -### Patch Changes - -- [#3041](https://github.com/medusajs/medusa/pull/3041) [`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724) Thanks [@riqwan](https://github.com/riqwan)! - chore(medusa): Typeorm fixes / enhancements - - - upgrade typeorm from 0.2.51 to 0.3.11 - - Plugin repository loader to work with Typeorm update - -- [#3685](https://github.com/medusajs/medusa/pull/3685) [`8ddb3952c`](https://github.com/medusajs/medusa/commit/8ddb3952c045e6c05c8d0f6922f0d4ba30cf3bd4) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Fix RC package versions - -- [#3649](https://github.com/medusajs/medusa/pull/3649) [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Export initialize method for all modules - -- [#3531](https://github.com/medusajs/medusa/pull/3531) [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Remove dependency on @medusajs/medusa from Inventory and Stock-Location Modules - -- Updated dependencies [[`8ddb3952c`](https://github.com/medusajs/medusa/commit/8ddb3952c045e6c05c8d0f6922f0d4ba30cf3bd4), [`a0c919a8d`](https://github.com/medusajs/medusa/commit/a0c919a8d01ca5edf62336de48e9a112e3822f38), [`55e94d0b4`](https://github.com/medusajs/medusa/commit/55e94d0b45776776639d3970d4264b8f5c5385dd), [`74bc4b16a`](https://github.com/medusajs/medusa/commit/74bc4b16a07f78668003ca930bf2a0d928897ceb), [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b), [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73), [`bca1f80dd`](https://github.com/medusajs/medusa/commit/bca1f80dd501d878455e1ad4f5091cf20ef900ea), [`271844aed`](https://github.com/medusajs/medusa/commit/271844aedbe45c369e188b5d06458dbd6984cd39), [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def)]: - - @medusajs/modules-sdk@1.8.0 - - @medusajs/utils@1.8.0 - -## 1.8.0-rc.3 - -### Patch Changes - -- [#3649](https://github.com/medusajs/medusa/pull/3649) [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Export initialize method for all modules - -- Updated dependencies [[`a0c919a8d`](https://github.com/medusajs/medusa/commit/a0c919a8d01ca5edf62336de48e9a112e3822f38), [`bd12a9508`](https://github.com/medusajs/medusa/commit/bd12a95083b69a70b83ad38578c5a68738c41b2b)]: - - @medusajs/utils@0.0.2-rc.2 - - @medusajs/modules-sdk@0.1.0-rc.4 - -## 1.8.0-rc.2 - -### Patch Changes - -- Updated dependencies [[`55e94d0b4`](https://github.com/medusajs/medusa/commit/55e94d0b45776776639d3970d4264b8f5c5385dd)]: - - @medusajs/modules-sdk@0.1.0-rc.3 - -## 1.8.0-rc.1 - -### Patch Changes - -- chore: Fix RC package versions - -- Updated dependencies []: - - @medusajs/modules-sdk@0.1.0-rc.2 - - @medusajs/utils@0.0.2-rc.1 - -## 1.8.0-rc.0 - -### Minor Changes - -- [#3329](https://github.com/medusajs/medusa/pull/3329) [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Inventory and Stock location modules supporting isolated connection - -### Patch Changes - -- [#3041](https://github.com/medusajs/medusa/pull/3041) [`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724) Thanks [@riqwan](https://github.com/riqwan)! - chore(medusa): Typeorm fixes / enhancements - - - upgrade typeorm from 0.2.51 to 0.3.11 - - Plugin repository loader to work with Typeorm update - -- [#3531](https://github.com/medusajs/medusa/pull/3531) [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Remove dependency on @medusajs/medusa from Inventory and Stock-Location Modules - -- Updated dependencies [[`74bc4b16a`](https://github.com/medusajs/medusa/commit/74bc4b16a07f78668003ca930bf2a0d928897ceb), [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73), [`271844aed`](https://github.com/medusajs/medusa/commit/271844aedbe45c369e188b5d06458dbd6984cd39), [`4e9d257d3`](https://github.com/medusajs/medusa/commit/4e9d257d3bf76703ef5be8ca054cc9f0f7339def)]: - - @medusajs/utils@0.0.2-rc.0 - - @medusajs/modules-sdk@0.1.0-rc.0 - -## 1.0.4 - -### Patch Changes - -- Updated dependencies [[`507ad00be`](https://github.com/medusajs/medusa/commit/507ad00bec74bb63b17eae8a4a3313eb6e0d2503), [`6e443dc70`](https://github.com/medusajs/medusa/commit/6e443dc708ffe20bf96d45ddc207ed274c28e344), [`eee928381`](https://github.com/medusajs/medusa/commit/eee9283818b1717f37f084c319201ea7144fdf8a), [`4cb44a3a2`](https://github.com/medusajs/medusa/commit/4cb44a3a2ec5bcf3d90e3b6a0e1f6bb9ff45e2b6), [`472f96d7f`](https://github.com/medusajs/medusa/commit/472f96d7fb8668a15df6e6f9ea31291891b3e688), [`61b0b2f3a`](https://github.com/medusajs/medusa/commit/61b0b2f3aa1d54d539b216a99032549485136a82), [`80452332d`](https://github.com/medusajs/medusa/commit/80452332d852ad7d33d74e1f08f12f45d7a35503), [`bbbb3d888`](https://github.com/medusajs/medusa/commit/bbbb3d888292391976355c88ecb0fcf8a7c115bc), [`10ff72c30`](https://github.com/medusajs/medusa/commit/10ff72c30ae59d2174d876b0c4141aad135d9a1c), [`968eb8fc6`](https://github.com/medusajs/medusa/commit/968eb8fc6b7ccd7221f88f42d75717f3a0547861), [`a59bd84e4`](https://github.com/medusajs/medusa/commit/a59bd84e41fb5d8fc2edc7bdc43d3cbf74d9d7dc), [`8c5219a31`](https://github.com/medusajs/medusa/commit/8c5219a31ef76ee571fbce84d7d57a63abe56eb0), [`cac13a88d`](https://github.com/medusajs/medusa/commit/cac13a88da42fa986bd7352fbc12a318b566d98f), [`a2cc084db`](https://github.com/medusajs/medusa/commit/a2cc084db817f8f7699e9b0daceda274b5f0e0c0), [`8194d19b0`](https://github.com/medusajs/medusa/commit/8194d19b0e933310fdc65af25300da5dd185e669)]: - - @medusajs/medusa@1.7.7 - - medusa-interfaces@1.3.6 - -## 1.0.3 - -### Patch Changes - -- [#3065](https://github.com/medusajs/medusa/pull/3065) [`2d525237b`](https://github.com/medusajs/medusa/commit/2d525237b682e89495b6cc8e3aa677bfad4d0726) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Fix (stock-location): stock location address required - -- Updated dependencies [[`ce866475b`](https://github.com/medusajs/medusa/commit/ce866475b4b6c8b453638000f7b1df7a27daf45d), [`53532df8d`](https://github.com/medusajs/medusa/commit/53532df8d597ed5471c07296981b6959cba4ddc3), [`d8ffbe25b`](https://github.com/medusajs/medusa/commit/d8ffbe25b047fda0f644240c9f518f95e74f03cb), [`2d525237b`](https://github.com/medusajs/medusa/commit/2d525237b682e89495b6cc8e3aa677bfad4d0726), [`5b63533c7`](https://github.com/medusajs/medusa/commit/5b63533c77528cab31755cedab9e768f7461f373), [`09dc9c667`](https://github.com/medusajs/medusa/commit/09dc9c6677c0d64cf765b27290e707ea75edd4aa), [`4105405f2`](https://github.com/medusajs/medusa/commit/4105405f28c3f3e54a6077c95a575a268fb5569f), [`ee42b60a2`](https://github.com/medusajs/medusa/commit/ee42b60a20db2afc5e9b6b958502f9e86ec37d80), [`d0adaf57e`](https://github.com/medusajs/medusa/commit/d0adaf57ed1018f29bebf01e5cffde5f7192f89f), [`f65f590a2`](https://github.com/medusajs/medusa/commit/f65f590a2771d6e526d7dfc7ca721be74c8f79a9), [`5ec6d438f`](https://github.com/medusajs/medusa/commit/5ec6d438fb1f909be925461c788f3a3a958528e4), [`5c1d2a5e8`](https://github.com/medusajs/medusa/commit/5c1d2a5e83c3654ae468d17c900892c32ef76060), [`8e41c6996`](https://github.com/medusajs/medusa/commit/8e41c6996601142661bde877b9ee1d80b8325f5f), [`d50db84a3`](https://github.com/medusajs/medusa/commit/d50db84a336da2de9c06a59aa79f2a5e9aa558f1), [`82da3605f`](https://github.com/medusajs/medusa/commit/82da3605fb50cef182699900552109ad654f0df2), [`b242e2232`](https://github.com/medusajs/medusa/commit/b242e22326ce74d5437d0da6863f22facbb5964c), [`4339d47e1`](https://github.com/medusajs/medusa/commit/4339d47e1f6c9f6c8f100b3ac72c8a394b6dd44d), [`2e7e16b91`](https://github.com/medusajs/medusa/commit/2e7e16b9173e2779946776b9b07ce7232c683f36), [`9ebb50104`](https://github.com/medusajs/medusa/commit/9ebb50104cc1f6c8ef1cea446ae595fb2eb532a2), [`08324355a`](https://github.com/medusajs/medusa/commit/08324355a4466b017a0bc7ab1d333ee3cd27b8c4), [`e22a383f4`](https://github.com/medusajs/medusa/commit/e22a383f4738e8bc80394ccaba3ac9a4ae678955), [`dc156861d`](https://github.com/medusajs/medusa/commit/dc156861d413ecfe3fd264bcd5ad736d83d8a08e), [`8f4c84121`](https://github.com/medusajs/medusa/commit/8f4c84121bd9b8c7067d72f03125e13afe4d2571), [`bfa33f444`](https://github.com/medusajs/medusa/commit/bfa33f444cd225906149777c5c6e842685f3dd7c), [`f776ed234`](https://github.com/medusajs/medusa/commit/f776ed234fcfccf23041ffebecbae6c9a8b7e922), [`4d6e63d68`](https://github.com/medusajs/medusa/commit/4d6e63d68f4e64c365ecbba133876d95e6528763), [`fcba70570`](https://github.com/medusajs/medusa/commit/fcba705701b8013183fafb39e8dda4a85718080a), [`4f0d8992a`](https://github.com/medusajs/medusa/commit/4f0d8992a091a05e93dd5be3762dfa47f074610e), [`d25a53104`](https://github.com/medusajs/medusa/commit/d25a531045143d3be68d3cd3b5764bbbc792ee3a), [`86c87c7b1`](https://github.com/medusajs/medusa/commit/86c87c7b1020ab6bb02f931e1ee113f2857cf527), [`78650ea66`](https://github.com/medusajs/medusa/commit/78650ea66517b0a77100228615d8122f84ad235b), [`b9bda3bf4`](https://github.com/medusajs/medusa/commit/b9bda3bf4e0f95675041085cea5008268c37edd5), [`e581d3bd9`](https://github.com/medusajs/medusa/commit/e581d3bd90f9bc40105e7eaf34e0c94d4f657f7a), [`4d3210bfb`](https://github.com/medusajs/medusa/commit/4d3210bfbb84877d951f7319d2e87c1acbdd6aad)]: - - @medusajs/medusa@1.7.6 - - medusa-interfaces@1.3.5 - -## 1.0.2 - -### Patch Changes - -- [#2997](https://github.com/medusajs/medusa/pull/2997) [`9dbccd9ca`](https://github.com/medusajs/medusa/commit/9dbccd9ca78b8b66f9a21947bb863622e7ff326b) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - feat(medusa, stock-location, inventory): Allow modules to integrate with core - -- [#3033](https://github.com/medusajs/medusa/pull/3033) [`1547dd814`](https://github.com/medusajs/medusa/commit/1547dd8143889fc30045fc3d0241de8e69acb76e) Thanks [@olivermrbl](https://github.com/olivermrbl)! - fix(medusa): Add module options to transaction base service to use in modules - -- Updated dependencies [[`9dbccd9ca`](https://github.com/medusajs/medusa/commit/9dbccd9ca78b8b66f9a21947bb863622e7ff326b), [`542daeead`](https://github.com/medusajs/medusa/commit/542daeeadd78d939f5144c690e8907374da6d085), [`8c08d0031`](https://github.com/medusajs/medusa/commit/8c08d003198b94c00f8428a51c0e79d2ca9d1dc7), [`017538883`](https://github.com/medusajs/medusa/commit/017538883588792e1ff37abcab0fd2872c9af932), [`b2839e2e4`](https://github.com/medusajs/medusa/commit/b2839e2e4dc0d9344fa2ac8d4d16b796def4c56d), [`76d175231`](https://github.com/medusajs/medusa/commit/76d17523105d3860028a90a45b6038a64040e5ce), [`9e3beaf53`](https://github.com/medusajs/medusa/commit/9e3beaf5319dc785cf84b856cfcc8193df90c3a4), [`7d4b8b9cc`](https://github.com/medusajs/medusa/commit/7d4b8b9cc59672d01cdf0c6f331bc3d1eeec9bee), [`aab163bab`](https://github.com/medusajs/medusa/commit/aab163babb91759a05b852d34c299cdfac96d800), [`a0c4cfe0f`](https://github.com/medusajs/medusa/commit/a0c4cfe0f74cf30c45956c32c2fb22bf833bea68), [`27a29ef24`](https://github.com/medusajs/medusa/commit/27a29ef24e5ea1ba2bc0be8ecb7dd747d4c7c65b), [`aef842123`](https://github.com/medusajs/medusa/commit/aef8421235d8fff68d7d4f8b73f77484073311a5), [`1dc79590b`](https://github.com/medusajs/medusa/commit/1dc79590b3539af09dbc8fbf931d9b5ee225fb0d), [`9c4647383`](https://github.com/medusajs/medusa/commit/9c4647383ebf0a183ccc566636bcf7af06409060), [`a0c4cfe0f`](https://github.com/medusajs/medusa/commit/a0c4cfe0f74cf30c45956c32c2fb22bf833bea68), [`b80124d32`](https://github.com/medusajs/medusa/commit/b80124d32d950790c2a01b49e8c34d562b1d57f4), [`cb1ec0076`](https://github.com/medusajs/medusa/commit/cb1ec0076b4fd932c686d6027e8b060ceded3a64), [`142c8aa70`](https://github.com/medusajs/medusa/commit/142c8aa70f583d9b11a6add2b8f988e9ba4cf979), [`1547dd814`](https://github.com/medusajs/medusa/commit/1547dd8143889fc30045fc3d0241de8e69acb76e), [`d2c692aa9`](https://github.com/medusajs/medusa/commit/d2c692aa96ea89c053f9a694a9ae6dba77e89b14), [`150696de9`](https://github.com/medusajs/medusa/commit/150696de99fc852c5d72a746f168b6f62b2086ed), [`93d0dc1bd`](https://github.com/medusajs/medusa/commit/93d0dc1bdcb54cf6e87428a7bb9b0dac196b4de2), [`b3e4be720`](https://github.com/medusajs/medusa/commit/b3e4be72087d0b528c3cce322edf9325b855c8ae)]: - - @medusajs/medusa@1.7.4 - - medusa-interfaces@1.3.4 - -## 1.0.1 - -### Patch Changes - -- [#2907](https://github.com/medusajs/medusa/pull/2907) [`c07ffb616`](https://github.com/medusajs/medusa/commit/c07ffb61658b0cdbff00461d1fa267c6be2d1967) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Stock locations module added - -- Updated dependencies [[`1817b810f`](https://github.com/medusajs/medusa/commit/1817b810fc8563a08119b74b86ec0587d9e443a1), [`28bec599a`](https://github.com/medusajs/medusa/commit/28bec599ae34d29b626b1dc36f762fc0b2fe8f17), [`3f44abe01`](https://github.com/medusajs/medusa/commit/3f44abe01a7807adf0e807811d4bc52b713cd6b5), [`8ed4eab73`](https://github.com/medusajs/medusa/commit/8ed4eab73a2b067e19da5a1c8498cbff7125ea8d), [`645e0d0ec`](https://github.com/medusajs/medusa/commit/645e0d0ec5e2e49048887c62db662427c8a39cdf), [`47d075351`](https://github.com/medusajs/medusa/commit/47d075351fa4fdeaf32d48f2bd7e72943a293d9b), [`32b038fc3`](https://github.com/medusajs/medusa/commit/32b038fc3fb5f8fab09a7d23f881847c7ae02c0c), [`3d200c41f`](https://github.com/medusajs/medusa/commit/3d200c41f953c3c979a1586f6425a2fbdf159e7e), [`16716f5a4`](https://github.com/medusajs/medusa/commit/16716f5a4f94cb6bc1dcea278d1789da760f2767), [`71fa60892`](https://github.com/medusajs/medusa/commit/71fa60892cd7c00dd9cb8c222a1794ad6577fc1b), [`cc10c20f3`](https://github.com/medusajs/medusa/commit/cc10c20f356d4fe98336d879f8c9523bb63e9e48), [`eda26f6e8`](https://github.com/medusajs/medusa/commit/eda26f6e818a56672cdcce1d794c307c5490f956), [`077e4d960`](https://github.com/medusajs/medusa/commit/077e4d960687a909fd254cd69f4dd5b3e0bad204), [`f3ced106a`](https://github.com/medusajs/medusa/commit/f3ced106ad24fe21f099e10bee5666e1f65a9fc7), [`baeacd1cc`](https://github.com/medusajs/medusa/commit/baeacd1cc52c548eef6896fd83e606c858cf2165), [`e4af96853`](https://github.com/medusajs/medusa/commit/e4af9685313077ece7e3fb7bd27053108cd9d5f8), [`cac81749e`](https://github.com/medusajs/medusa/commit/cac81749eaa06b3b00ac5494591c96a0fcd7bf57), [`4a50786fb`](https://github.com/medusajs/medusa/commit/4a50786fbc78b36147f1f45d77c55dc0a582caba), [`c07ffb616`](https://github.com/medusajs/medusa/commit/c07ffb61658b0cdbff00461d1fa267c6be2d1967), [`8ba0addea`](https://github.com/medusajs/medusa/commit/8ba0addea3997c27efe4a50733b02a31e02f55e5), [`b9680b641`](https://github.com/medusajs/medusa/commit/b9680b641f2984eddbc1f49a37c050499fbaff69)]: - - @medusajs/medusa@1.7.3 diff --git a/packages/stock-location/jest.config.js b/packages/stock-location/jest.config.js deleted file mode 100644 index 7b13ee00a9..0000000000 --- a/packages/stock-location/jest.config.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - transform: { - "^.+\\.[jt]s?$": [ - "ts-jest", - { - tsconfig: "tsconfig.spec.json", - isolatedModules: true, - }, - ], - }, - testEnvironment: `node`, - moduleFileExtensions: [`js`, `ts`], -} diff --git a/packages/stock-location/package.json b/packages/stock-location/package.json deleted file mode 100644 index ac4aed9eb2..0000000000 --- a/packages/stock-location/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "@medusajs/stock-location", - "version": "1.11.5", - "description": "Stock Location Module for Medusa", - "main": "dist/index.js", - "repository": { - "type": "git", - "url": "https://github.com/medusajs/medusa", - "directory": "packages/stock-location" - }, - "engines": { - "node": ">=16" - }, - "publishConfig": { - "access": "public" - }, - "files": [ - "dist" - ], - "author": "Medusa", - "license": "MIT", - "devDependencies": { - "@medusajs/types": "^1.11.12", - "cross-env": "^5.2.1", - "jest": "^29.6.3", - "rimraf": "^5.0.1", - "ts-jest": "^29.1.1", - "typescript": "^5.1.6" - }, - "dependencies": { - "@medusajs/modules-sdk": "^1.12.8", - "@medusajs/utils": "^1.11.5", - "awilix": "^8.0.0", - "typeorm": "^0.3.16" - }, - "scripts": { - "watch": "tsc --build --watch", - "prepublishOnly": "cross-env NODE_ENV=production tsc --build", - "build": "rimraf dist && tsc --build", - "test": "jest --passWithNoTests" - } -} diff --git a/packages/stock-location/src/index.ts b/packages/stock-location/src/index.ts deleted file mode 100644 index 6ec4fe4834..0000000000 --- a/packages/stock-location/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { moduleDefinition } from "./module-definition" - -export default moduleDefinition -export * from "./initialize" -export { revertMigration, runMigrations } from "./migrations/run-migration" -export * from "./types" diff --git a/packages/stock-location/src/initialize/index.ts b/packages/stock-location/src/initialize/index.ts deleted file mode 100644 index 56842628c8..0000000000 --- a/packages/stock-location/src/initialize/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - ExternalModuleDeclaration, - InternalModuleDeclaration, - MedusaModule, - MODULE_PACKAGE_NAMES, - Modules, -} from "@medusajs/modules-sdk" -import { IEventBusService, IStockLocationService } from "@medusajs/types" -import { moduleDefinition } from "../module-definition" -import { StockLocationServiceInitializeOptions } from "../types" - -export const initialize = async ( - options: StockLocationServiceInitializeOptions | ExternalModuleDeclaration, - injectedDependencies?: { - eventBusService: IEventBusService - } -): Promise => { - const serviceKey = Modules.STOCK_LOCATION - const loaded = await MedusaModule.bootstrap({ - moduleKey: serviceKey, - defaultPath: MODULE_PACKAGE_NAMES[Modules.STOCK_LOCATION], - declaration: options as - | InternalModuleDeclaration - | ExternalModuleDeclaration, - injectedDependencies, - moduleExports: moduleDefinition, - }) - - return loaded[serviceKey] -} diff --git a/packages/stock-location/src/joiner-config.ts b/packages/stock-location/src/joiner-config.ts deleted file mode 100644 index ebe7fe4a76..0000000000 --- a/packages/stock-location/src/joiner-config.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ModuleJoinerConfig } from "@medusajs/types" -import { Modules } from "@medusajs/modules-sdk" -import { StockLocation } from "./models" -import moduleSchema from "./schema" - -export const joinerConfig: ModuleJoinerConfig = { - serviceName: Modules.STOCK_LOCATION, - primaryKeys: ["id"], - linkableKeys: { - stock_location_id: StockLocation.name, - location_id: StockLocation.name, - }, - schema: moduleSchema, - alias: [ - { - name: ["stock_location", "stock_locations"], - args: { - entity: "StockLocation", - }, - }, - ], -} diff --git a/packages/stock-location/src/loaders/connection.ts b/packages/stock-location/src/loaders/connection.ts deleted file mode 100644 index b43f7b14c5..0000000000 --- a/packages/stock-location/src/loaders/connection.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { - InternalModuleDeclaration, - LoaderOptions, - MODULE_RESOURCE_TYPE, - MODULE_SCOPE, -} from "@medusajs/modules-sdk" -import { MedusaError } from "@medusajs/utils" -import { asValue } from "awilix" -import { DataSource, DataSourceOptions } from "typeorm" -import * as StockLocationModels from "../models" -import { StockLocationServiceInitializeOptions } from "../types" - -export default async ( - { options, container }: LoaderOptions, - moduleDeclaration?: InternalModuleDeclaration -): Promise => { - if ( - moduleDeclaration?.scope === MODULE_SCOPE.INTERNAL && - moduleDeclaration.resources === MODULE_RESOURCE_TYPE.SHARED - ) { - return - } - - const dbData = - options?.database as StockLocationServiceInitializeOptions["database"] - - if (!dbData) { - throw new MedusaError( - MedusaError.Types.INVALID_ARGUMENT, - `Database config is not present at module config "options.database"` - ) - } - - const entities = Object.values(StockLocationModels) - const dataSource = new DataSource({ - type: dbData.type, - url: dbData.url, - database: dbData.database, - extra: dbData.extra || {}, - schema: dbData.schema, - entities, - logging: dbData.logging, - } as DataSourceOptions) - - await dataSource.initialize() - - container.register({ - manager: asValue(dataSource.manager), - }) -} diff --git a/packages/stock-location/src/migrations/index.ts b/packages/stock-location/src/migrations/index.ts deleted file mode 100644 index 1bf18cac9a..0000000000 --- a/packages/stock-location/src/migrations/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import * as setup from "./schema-migrations/1665749860179-setup" - -export default [setup] diff --git a/packages/stock-location/src/migrations/run-migration.ts b/packages/stock-location/src/migrations/run-migration.ts deleted file mode 100644 index 1ecfd0b1b1..0000000000 --- a/packages/stock-location/src/migrations/run-migration.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk" -import { DataSource, DataSourceOptions } from "typeorm" -import { StockLocationServiceInitializeOptions } from "../types" - -import migrations from "./index" - -function getDataSource( - dbData: StockLocationServiceInitializeOptions["database"] -): DataSource { - return new DataSource({ - type: dbData!.type, - url: dbData!.url, - database: dbData!.database, - extra: dbData!.extra || {}, - migrations: migrations - .map((migration: any): Function[] => { - return Object.values(migration).filter( - (fn) => typeof fn === "function" - ) as Function[] - }) - .flat(), - schema: dbData!.schema, - logging: dbData!.logging, - } as DataSourceOptions) -} - -export async function runMigrations( - { options, logger }: Omit, - moduleDeclaration?: InternalModuleDeclaration -) { - const dbData = - options?.database as StockLocationServiceInitializeOptions["database"] - - try { - const dataSource = getDataSource(dbData) - await dataSource.initialize() - await dataSource.runMigrations() - - logger?.info("Stock Location module migration executed") - } catch (error) { - logger?.error( - `Stock Location module migration failed to run - Error: ${error}` - ) - } -} - -export async function revertMigration( - { options, logger }: Omit, - moduleDeclaration?: InternalModuleDeclaration -) { - const dbData = - options?.database as StockLocationServiceInitializeOptions["database"] - - try { - const dataSource = getDataSource(dbData) - await dataSource.initialize() - await dataSource.undoLastMigration() - - logger?.info("Stock Location module migration reverted") - } catch (error) { - logger?.error( - `Stock Location module migration failed to revert - Error: ${error}` - ) - } -} diff --git a/packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts b/packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts deleted file mode 100644 index 47f422e407..0000000000 --- a/packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class setup1665749860179 implements MigrationInterface { - name = "setup1665749860179" - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - CREATE TABLE "stock_location_address" - ( - "id" CHARACTER VARYING NOT NULL, - "created_at" TIMESTAMP WITH TIME zone NOT NULL DEFAULT Now(), - "updated_at" TIMESTAMP WITH TIME zone NOT NULL DEFAULT Now(), - "deleted_at" TIMESTAMP WITH TIME zone, - "address_1" TEXT NOT NULL, - "address_2" TEXT, - "company" TEXT, - "city" TEXT, - "country_code" TEXT NOT NULL, - "phone" TEXT, - "province" TEXT, - "postal_code" TEXT, - "metadata" JSONB, - CONSTRAINT "PK_b79bc27285bede680501b7b81a5" PRIMARY KEY ("id") - ); - - CREATE INDEX "IDX_stock_location_address_country_code" ON "stock_location_address" ("country_code"); - - CREATE TABLE "stock_location" - ( - "id" CHARACTER VARYING NOT NULL, - "created_at" TIMESTAMP WITH time zone NOT NULL DEFAULT Now(), - "updated_at" TIMESTAMP WITH time zone NOT NULL DEFAULT Now(), - "deleted_at" TIMESTAMP WITH time zone, - "name" TEXT NOT NULL, - "address_id" TEXT, - "metadata" JSONB, - CONSTRAINT "PK_adf770067d0df1421f525fa25cc" PRIMARY KEY ("id") - ); - - CREATE INDEX "IDX_stock_location_address_id" ON "stock_location" ("address_id") WHERE deleted_at IS NOT NULL; - `) - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - DROP INDEX "IDX_stock_location_address_id"; - DROP TABLE "stock_location"; - - DROP INDEX "IDX_stock_location_address_country_code"; - DROP TABLE "stock_location_address"; - `) - } -} diff --git a/packages/stock-location/src/models/index.ts b/packages/stock-location/src/models/index.ts deleted file mode 100644 index 732b15fc23..0000000000 --- a/packages/stock-location/src/models/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./stock-location" -export * from "./stock-location-address" diff --git a/packages/stock-location/src/models/stock-location-address.ts b/packages/stock-location/src/models/stock-location-address.ts deleted file mode 100644 index f2068833e9..0000000000 --- a/packages/stock-location/src/models/stock-location-address.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Searchable, generateEntityId } from "@medusajs/utils" -import { - BeforeInsert, - Column, - CreateDateColumn, - DeleteDateColumn, - Entity, - Index, - PrimaryColumn, - UpdateDateColumn, -} from "typeorm" - -@Entity() -export class StockLocationAddress { - @PrimaryColumn() - id: string - - @CreateDateColumn({ type: "timestamptz" }) - created_at: Date - - @UpdateDateColumn({ type: "timestamptz" }) - updated_at: Date - - @DeleteDateColumn({ type: "timestamptz" }) - deleted_at: Date | null - - @Searchable() - @Column({ type: "text" }) - address_1: string - - @Searchable() - @Column({ type: "text", nullable: true }) - address_2: string | null - - @Searchable() - @Column({ type: "text", nullable: true }) - company: string | null - - @Searchable() - @Column({ type: "text", nullable: true }) - city: string | null - - @Index() - @Column({ type: "text" }) - country_code: string - - @Column({ type: "text", nullable: true }) - phone: string | null - - @Searchable() - @Column({ type: "text", nullable: true }) - province: string | null - - @Searchable() - @Column({ type: "text", nullable: true }) - postal_code: string | null - - @Column({ type: "jsonb", nullable: true }) - metadata: Record | null - - @BeforeInsert() - private beforeInsert(): void { - this.id = generateEntityId(this.id, "laddr") - } -} diff --git a/packages/stock-location/src/models/stock-location.ts b/packages/stock-location/src/models/stock-location.ts deleted file mode 100644 index f6e1df6945..0000000000 --- a/packages/stock-location/src/models/stock-location.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Searchable, generateEntityId } from "@medusajs/utils" -import { - BeforeInsert, - Column, - CreateDateColumn, - DeleteDateColumn, - Entity, - Index, - JoinColumn, - ManyToOne, - PrimaryColumn, - UpdateDateColumn, -} from "typeorm" -import { StockLocationAddress } from "./stock-location-address" - -@Entity() -export class StockLocation { - @PrimaryColumn() - id: string - - @CreateDateColumn({ type: "timestamptz" }) - created_at: Date - - @UpdateDateColumn({ type: "timestamptz" }) - updated_at: Date - - @DeleteDateColumn({ type: "timestamptz" }) - deleted_at: Date | null - - @Searchable() - @Column({ type: "text" }) - name: string - - @Index() - @Column({ type: "text", nullable: true }) - address_id: string | null - - @Searchable() - @ManyToOne(() => StockLocationAddress) - @JoinColumn({ name: "address_id" }) - address: StockLocationAddress | null - - @Column({ type: "jsonb", nullable: true }) - metadata: Record | null - - @BeforeInsert() - private beforeInsert(): void { - this.id = generateEntityId(this.id, "sloc") - } -} diff --git a/packages/stock-location/src/module-definition.ts b/packages/stock-location/src/module-definition.ts deleted file mode 100644 index 44ed23a71c..0000000000 --- a/packages/stock-location/src/module-definition.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { ModuleExports } from "@medusajs/types" -import loadConnection from "./loaders/connection" -import migrations from "./migrations" -import { revertMigration, runMigrations } from "./migrations/run-migration" -import * as StockLocationModels from "./models" -import StockLocationService from "./services/stock-location" - -const service = StockLocationService -const loaders = [loadConnection] -const models = Object.values(StockLocationModels) - -export const moduleDefinition: ModuleExports = { - service, - migrations, - loaders, - models, - runMigrations, - revertMigration, -} diff --git a/packages/stock-location/src/schema/index.ts b/packages/stock-location/src/schema/index.ts deleted file mode 100644 index 9a7b198d62..0000000000 --- a/packages/stock-location/src/schema/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -export default ` -scalar DateTime -scalar JSON -type StockLocation { - id: ID! - created_at: DateTime! - updated_at: DateTime! - deleted_at: DateTime - name: String! - address_id: String - address: StockLocationAddress - metadata: JSON -} -type StockLocationAddress { - id: ID! - created_at: DateTime! - updated_at: DateTime! - deleted_at: DateTime - address_1: String! - address_2: String - company: String - city: String - country_code: String! - phone: String - province: String - postal_code: String - metadata: JSON -} -` diff --git a/packages/stock-location/src/services/index.ts b/packages/stock-location/src/services/index.ts deleted file mode 100644 index 65d66a6208..0000000000 --- a/packages/stock-location/src/services/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as StockLocationService } from "./stock-location" diff --git a/packages/stock-location/src/services/stock-location.ts b/packages/stock-location/src/services/stock-location.ts deleted file mode 100644 index 38fcb67f85..0000000000 --- a/packages/stock-location/src/services/stock-location.ts +++ /dev/null @@ -1,313 +0,0 @@ -import { InternalModuleDeclaration } from "@medusajs/modules-sdk" -import { - CreateStockLocationInput, - FilterableStockLocationProps, - FindConfig, - IEventBusService, - MODULE_RESOURCE_TYPE, - ModuleJoinerConfig, - SharedContext, - StockLocationAddressInput, - UpdateStockLocationInput, -} from "@medusajs/types" -import { - InjectEntityManager, - isDefined, - MedusaContext, - MedusaError, - setMetadata, -} from "@medusajs/utils" -import { EntityManager, FindOptionsWhere, ILike } from "typeorm" -import { joinerConfig } from "../joiner-config" -import { StockLocation, StockLocationAddress } from "../models" -import { buildQuery } from "../utils/build-query" - -type InjectedDependencies = { - manager: EntityManager - eventBusService: IEventBusService -} - -/** - * Service for managing stock locations. - */ - -export default class StockLocationService { - static Events = { - CREATED: "stock-location.created", - UPDATED: "stock-location.updated", - DELETED: "stock-location.deleted", - } - - protected readonly manager_: EntityManager - protected readonly eventBusService_: IEventBusService - - constructor( - { eventBusService, manager }: InjectedDependencies, - options?: unknown, - protected readonly moduleDeclaration?: InternalModuleDeclaration - ) { - this.manager_ = manager - this.eventBusService_ = eventBusService - } - - __joinerConfig(): ModuleJoinerConfig { - return joinerConfig - } - - /** - * Lists all stock locations that match the given selector. - * @param selector - Properties to filter by. - * @param config - Additional configuration for the query. - * @param context - * @return A list of stock locations. - */ - async list( - selector: FilterableStockLocationProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise { - const [locations] = await this.listAndCount(selector, config, context) - return locations - } - - /** - * Lists all stock locations that match the given selector and returns the count of matching stock locations. - * @param selector - Properties to filter by. - * @param config - Additional configuration for the query. - * @param context - * @return A list of stock locations and the count of matching stock locations. - */ - async listAndCount( - selector: FilterableStockLocationProps = {}, - config: FindConfig = { relations: [], skip: 0, take: 10 }, - @MedusaContext() context: SharedContext = {} - ): Promise<[StockLocation[], number]> { - const manager = context.transactionManager ?? this.manager_ - const locationRepo = manager.getRepository(StockLocation) - let q - if (selector.q) { - q = selector.q - delete selector.q - } - - const query = buildQuery(selector, config) - - if (q) { - const where = query.where as FindOptionsWhere - - delete where.name - - query.where = [ - { - ...where, - name: ILike(`%${q}%`), - }, - ] - } - - return await locationRepo.findAndCount(query) - } - - /** - * Retrieves a Stock Location by its ID. - * @param stockLocationId - The ID of the stock location. - * @param config - Additional configuration for the query. - * @param context - * @return The stock location. - * @throws If the stock location ID is not definedor the stock location with the given ID was not found. - */ - async retrieve( - stockLocationId: string, - config: FindConfig = {}, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!isDefined(stockLocationId)) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `"stockLocationId" must be defined` - ) - } - - const manager = context.transactionManager ?? this.manager_ - const locationRepo = manager.getRepository(StockLocation) - - const query = buildQuery({ id: stockLocationId }, config) - const [loc] = await locationRepo.find(query) - - if (!loc) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `StockLocation with id ${stockLocationId} was not found` - ) - } - - return loc - } - - /** - * Creates a new stock location. - * @param data - The input data for creating a Stock Location. - * @param context - * @returns The created stock location. - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async create( - data: CreateStockLocationInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - - const locationRepo = manager.getRepository(StockLocation) - - const loc = locationRepo.create({ - name: data.name, - }) - - if (isDefined(data.address) || isDefined(data.address_id)) { - if (typeof data.address === "string" || data.address_id) { - const addrId = (data.address ?? data.address_id) as string - loc.address_id = addrId - } else { - const locAddressRepo = manager.getRepository(StockLocationAddress) - const locAddress = locAddressRepo.create(data.address!) - const addressResult = await locAddressRepo.save(locAddress) - loc.address_id = addressResult.id - } - } - - const { metadata } = data - if (metadata) { - loc.metadata = setMetadata(loc, metadata) - } - const result = await locationRepo.save(loc) - - await this.eventBusService_?.emit?.(StockLocationService.Events.CREATED, { - id: result.id, - }) - - return result - } - - /** - * Updates an existing stock location. - * @param stockLocationId - The ID of the stock location to update. - * @param updateData - The update data for the stock location. - * @param context - * @returns The updated stock location. - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async update( - stockLocationId: string, - updateData: UpdateStockLocationInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const locationRepo = manager.getRepository(StockLocation) - - const item = await this.retrieve(stockLocationId, undefined, context) - - const { address, ...data } = updateData - - if (address) { - if (item.address_id) { - await this.updateAddress(item.address_id, address, context) - } else { - const locAddressRepo = manager.getRepository(StockLocationAddress) - const locAddress = locAddressRepo.create(address) - const addressResult = await locAddressRepo.save(locAddress) - data.address_id = addressResult.id - } - } - - const { metadata, ...fields } = data - - const toSave = locationRepo.merge(item, fields) - if (metadata) { - toSave.metadata = setMetadata(toSave, metadata) - } - - await locationRepo.save(toSave) - - await this.eventBusService_?.emit?.(StockLocationService.Events.UPDATED, { - id: stockLocationId, - }) - - return item - } - - /** - * Updates an address for a Stock Location. - * @param addressId - The ID of the address to update. - * @param address - The update data for the address. - * @param context - * @returns The updated stock location address. - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - protected async updateAddress( - addressId: string, - address: StockLocationAddressInput, - @MedusaContext() context: SharedContext = {} - ): Promise { - if (!isDefined(addressId)) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `"addressId" must be defined` - ) - } - - const manager = context.transactionManager! - const locationAddressRepo = manager.getRepository(StockLocationAddress) - - const existingAddress = await locationAddressRepo.findOne({ - where: { id: addressId }, - }) - if (!existingAddress) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `StockLocation address with id ${addressId} was not found` - ) - } - - const { metadata, ...fields } = address - - const toSave = locationAddressRepo.merge(existingAddress, fields) - if (metadata) { - toSave.metadata = setMetadata(toSave, metadata) - } - - return await locationAddressRepo.save(toSave) - } - - /** - * Deletes a Stock Location. - * @param id - The ID of the stock location to delete. - * @param context - * @returns An empty promise. - */ - @InjectEntityManager( - (target) => - target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED - ) - async delete( - id: string, - @MedusaContext() context: SharedContext = {} - ): Promise { - const manager = context.transactionManager! - const locationRepo = manager.getRepository(StockLocation) - - await locationRepo.softRemove({ id }) - - await this.eventBusService_?.emit?.(StockLocationService.Events.DELETED, { - id, - }) - } -} diff --git a/packages/stock-location/src/types/index.ts b/packages/stock-location/src/types/index.ts deleted file mode 100644 index 88f8150eb6..0000000000 --- a/packages/stock-location/src/types/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { DatabaseType } from "typeorm" - -export type StockLocationServiceInitializeOptions = { - database?: { - type?: DatabaseType | string - url?: string - database?: string - extra?: Record - schema?: string - logging?: boolean - } -} diff --git a/packages/stock-location/src/utils/build-query.ts b/packages/stock-location/src/utils/build-query.ts deleted file mode 100644 index ee0fb07fe9..0000000000 --- a/packages/stock-location/src/utils/build-query.ts +++ /dev/null @@ -1,166 +0,0 @@ -import { ExtendedFindConfig, FindConfig } from "@medusajs/types" -import { - And, - FindManyOptions, - FindOperator, - FindOptionsOrder, - FindOptionsRelations, - FindOptionsSelect, - FindOptionsWhere, - ILike, - In, - IsNull, - LessThan, - LessThanOrEqual, - MoreThan, - MoreThanOrEqual, -} from "typeorm" -import { buildOrder, buildRelations, buildSelects } from "@medusajs/utils" - -const operatorsMap = { - lt: (value) => LessThan(value), - gt: (value) => MoreThan(value), - lte: (value) => LessThanOrEqual(value), - gte: (value) => MoreThanOrEqual(value), - contains: (value) => ILike(`%${value}%`), - starts_with: (value) => ILike(`${value}%`), - ends_with: (value) => ILike(`%${value}`), -} - -/** - * Used to build TypeORM queries. - * @param selector The selector - * @param config The config - * @return The QueryBuilderConfig - */ -export function buildQuery( - selector: TWhereKeys, - config: FindConfig = {} -) { - const query: ExtendedFindConfig = { - where: buildWhere(selector), - } - - if ("deleted_at" in selector) { - query.withDeleted = true - } - - if ("skip" in config) { - ;(query as FindManyOptions).skip = config.skip ?? undefined - } - - if ("take" in config) { - ;(query as FindManyOptions).take = config.take ?? undefined - } - - if (config.relations) { - query.relations = buildRelations( - config.relations - ) as FindOptionsRelations - } - - if (config.select) { - query.select = buildSelects( - config.select as string[] - ) as FindOptionsSelect - } - - if (config.order) { - query.order = buildOrder(config.order) as FindOptionsOrder - } - - return query -} - -/** - * @param constraints - * - * @example - * const q = buildWhere( - * { - * id: "1234", - * test1: ["123", "12", "1"], - * test2: Not("this"), - * date: { gt: date }, - * amount: { gt: 10 }, - * }, - *) - * - * // Output - * { - * id: "1234", - * test1: In(["123", "12", "1"]), - * test2: Not("this"), - * date: MoreThan(date), - * amount: MoreThan(10) - * } - */ -function buildWhere( - constraints: TWhereKeys -): FindOptionsWhere | FindOptionsWhere[] { - let where: FindOptionsWhere | FindOptionsWhere[] = {} - - if (Array.isArray(constraints)) { - where = [] - constraints.forEach((constraint) => { - ;(where as FindOptionsWhere[]).push( - buildWhere(constraint) as FindOptionsWhere - ) - }) - - return where - } - - for (const [key, value] of Object.entries(constraints)) { - if (value === undefined) { - continue - } - - if (value === null) { - where[key] = IsNull() - continue - } - - if (value instanceof FindOperator) { - where[key] = value - continue - } - - if (Array.isArray(value)) { - where[key] = In(value) - continue - } - - if (typeof value === "object") { - Object.entries(value).forEach(([objectKey, objectValue]) => { - where[key] = where[key] || [] - if (operatorsMap[objectKey]) { - where[key].push(operatorsMap[objectKey](objectValue)) - } else { - if (objectValue != undefined && typeof objectValue === "object") { - where[key] = buildWhere(objectValue) - return - } - where[key] = value - } - return - }) - - if (!Array.isArray(where[key])) { - continue - } - - if (where[key].length === 1) { - where[key] = where[key][0] - } else { - where[key] = And(...where[key]) - } - - continue - } - - where[key] = value - } - - return where -} diff --git a/packages/stock-location/tsconfig.json b/packages/stock-location/tsconfig.json deleted file mode 100644 index 2c99c7503d..0000000000 --- a/packages/stock-location/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "lib": ["es2020"], - "target": "es2020", - "outDir": "./dist", - "esModuleInterop": true, - "declaration": true, - "module": "commonjs", - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "sourceMap": true, - "noImplicitReturns": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "noImplicitThis": true, - "allowJs": true, - "skipLibCheck": true - }, - "include": ["src"], - "exclude": [ - "dist", - "./src/**/__tests__", - "./src/**/__mocks__", - "node_modules" - ] -} diff --git a/packages/stock-location/tsconfig.spec.json b/packages/stock-location/tsconfig.spec.json deleted file mode 100644 index 9b62409191..0000000000 --- a/packages/stock-location/tsconfig.spec.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["src"], - "exclude": ["node_modules"] -} diff --git a/packages/user/.gitignore b/packages/user/.gitignore deleted file mode 100644 index 874c6c69d3..0000000000 --- a/packages/user/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/dist -node_modules -.DS_store -.env* -.env -*.sql diff --git a/packages/user/src/loaders/index.ts b/packages/user/src/loaders/index.ts deleted file mode 100644 index 3614963d8c..0000000000 --- a/packages/user/src/loaders/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./connection" -export * from "./container" diff --git a/yarn.lock b/yarn.lock index 44f4f795d3..9b524d1867 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8596,22 +8596,17 @@ __metadata: languageName: unknown linkType: soft -"@medusajs/inventory@workspace:^, @medusajs/inventory@workspace:packages/inventory": - version: 0.0.0-use.local - resolution: "@medusajs/inventory@workspace:packages/inventory" +"@medusajs/inventory@npm:latest": + version: 1.11.6 + resolution: "@medusajs/inventory@npm:1.11.6" dependencies: "@medusajs/modules-sdk": ^1.12.8 - "@medusajs/types": ^1.11.12 "@medusajs/utils": ^1.11.5 awilix: ^8.0.0 - cross-env: ^5.2.1 - jest: ^29.6.3 - rimraf: ^5.0.1 - ts-jest: ^29.1.1 typeorm: ^0.3.16 - typescript: ^5.1.6 - languageName: unknown - linkType: soft + checksum: 0eaa3b20e60ff75c8c15b7d8a15408778860a3263d855b08610b770a20fe282fe1dd279d4c923dfee98a388b9c036d96c89491eb89ef3c82eae220da6a468bcc + languageName: node + linkType: hard "@medusajs/link-modules@^0.2.11, @medusajs/link-modules@workspace:packages/modules/link-modules": version: 0.0.0-use.local @@ -9130,22 +9125,17 @@ __metadata: languageName: unknown linkType: soft -"@medusajs/stock-location@workspace:packages/stock-location": - version: 0.0.0-use.local - resolution: "@medusajs/stock-location@workspace:packages/stock-location" +"@medusajs/stock-location@npm:latest": + version: 1.11.5 + resolution: "@medusajs/stock-location@npm:1.11.5" dependencies: "@medusajs/modules-sdk": ^1.12.8 - "@medusajs/types": ^1.11.12 "@medusajs/utils": ^1.11.5 awilix: ^8.0.0 - cross-env: ^5.2.1 - jest: ^29.6.3 - rimraf: ^5.0.1 - ts-jest: ^29.1.1 typeorm: ^0.3.16 - typescript: ^5.1.6 - languageName: unknown - linkType: soft + checksum: 812e5b5f82b4e41e39bddc6148de8b45815c00dfff64d66972b1e61258c98c1c5da037b17df910db06ac7409cd6ea81777b130d025034ec6f14aeb9fc45994bd + languageName: node + linkType: hard "@medusajs/store@workspace:^, @medusajs/store@workspace:packages/modules/store": version: 0.0.0-use.local @@ -9332,9 +9322,9 @@ __metadata: languageName: unknown linkType: soft -"@medusajs/user@workspace:^, @medusajs/user@workspace:packages/user": +"@medusajs/user@workspace:^, @medusajs/user@workspace:packages/modules/user": version: 0.0.0-use.local - resolution: "@medusajs/user@workspace:packages/user" + resolution: "@medusajs/user@workspace:packages/modules/user" dependencies: "@medusajs/modules-sdk": ^1.12.10 "@medusajs/types": ^1.11.15 @@ -30393,7 +30383,7 @@ __metadata: "@medusajs/cache-inmemory": "workspace:*" "@medusajs/customer": "workspace:^" "@medusajs/event-bus-local": "workspace:*" - "@medusajs/inventory": "workspace:^" + "@medusajs/inventory": latest "@medusajs/medusa": "workspace:*" "@medusajs/modules-sdk": "workspace:^" "@medusajs/pricing": "workspace:^" @@ -30476,7 +30466,7 @@ __metadata: "@medusajs/currency": "workspace:^" "@medusajs/customer": "workspace:^" "@medusajs/event-bus-local": "workspace:*" - "@medusajs/inventory": "workspace:^" + "@medusajs/inventory": latest "@medusajs/inventory-next": "workspace:^" "@medusajs/medusa": "workspace:*" "@medusajs/modules-sdk": "workspace:^" @@ -30484,6 +30474,7 @@ __metadata: "@medusajs/product": "workspace:^" "@medusajs/promotion": "workspace:^" "@medusajs/region": "workspace:^" + "@medusajs/stock-location": latest "@medusajs/store": "workspace:^" "@medusajs/tax": "workspace:^" "@medusajs/types": "workspace:^"