From 8406eb5a350131bb6a9d65c1b041335378d671c9 Mon Sep 17 00:00:00 2001 From: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:15:15 +0100 Subject: [PATCH] feat(stock-location): Convert module to use mikro-orm (#6616) * convert module * fix migration * cleanup module service * fix pr feedback --- .../src/module-test-runner.ts | 10 +- packages/stock-location-next/.gitignore | 6 + packages/stock-location-next/CHANGELOG.md | 263 +++++++++++++++ .../stock-location-module-service.spec.ts | 158 +++++++++ packages/stock-location-next/jest.config.js | 13 + .../mikro-orm.config.dev.ts | 13 + packages/stock-location-next/package.json | 58 ++++ packages/stock-location-next/src/index.ts | 14 + .../stock-location-next/src/joiner-config.ts | 37 +++ .../.snapshot-medusa-stock-location.json | 270 ++++++++++++++++ .../src/migrations/Migration20240307161216.ts | 23 ++ .../stock-location-next/src/models/index.ts | 2 + .../src/models/stock-location-address.ts | 79 +++++ .../src/models/stock-location.ts | 75 +++++ .../src/module-definition.ts | 44 +++ .../src/repositories/index.ts | 1 + .../stock-location-next/src/schema/index.ts | 29 ++ .../src/services/__tests__/noop.ts | 5 + .../stock-location-next/src/services/index.ts | 1 + .../src/services/stock-location.ts | 197 ++++++++++++ packages/stock-location-next/tsconfig.json | 38 +++ .../stock-location-next/tsconfig.spec.json | 5 + packages/types/src/stock-location/common.ts | 4 + packages/types/src/stock-location/index.ts | 1 + .../types/src/stock-location/service-next.ts | 304 ++++++++++++++++++ .../src/stock-location/stock-location.ts | 42 --- yarn.lock | 25 ++ 27 files changed, 1670 insertions(+), 47 deletions(-) create mode 100644 packages/stock-location-next/.gitignore create mode 100644 packages/stock-location-next/CHANGELOG.md create mode 100644 packages/stock-location-next/integration-tests/__tests__/stock-location-module-service.spec.ts create mode 100644 packages/stock-location-next/jest.config.js create mode 100644 packages/stock-location-next/mikro-orm.config.dev.ts create mode 100644 packages/stock-location-next/package.json create mode 100644 packages/stock-location-next/src/index.ts create mode 100644 packages/stock-location-next/src/joiner-config.ts create mode 100644 packages/stock-location-next/src/migrations/.snapshot-medusa-stock-location.json create mode 100644 packages/stock-location-next/src/migrations/Migration20240307161216.ts create mode 100644 packages/stock-location-next/src/models/index.ts create mode 100644 packages/stock-location-next/src/models/stock-location-address.ts create mode 100644 packages/stock-location-next/src/models/stock-location.ts create mode 100644 packages/stock-location-next/src/module-definition.ts create mode 100644 packages/stock-location-next/src/repositories/index.ts create mode 100644 packages/stock-location-next/src/schema/index.ts create mode 100644 packages/stock-location-next/src/services/__tests__/noop.ts create mode 100644 packages/stock-location-next/src/services/index.ts create mode 100644 packages/stock-location-next/src/services/stock-location.ts create mode 100644 packages/stock-location-next/tsconfig.json create mode 100644 packages/stock-location-next/tsconfig.spec.json create mode 100644 packages/types/src/stock-location/service-next.ts delete mode 100644 packages/types/src/stock-location/stock-location.ts diff --git a/packages/medusa-test-utils/src/module-test-runner.ts b/packages/medusa-test-utils/src/module-test-runner.ts index 758e2959fc..f80649b14a 100644 --- a/packages/medusa-test-utils/src/module-test-runner.ts +++ b/packages/medusa-test-utils/src/module-test-runner.ts @@ -1,10 +1,7 @@ -import { - MedusaAppOutput, - ModulesDefinition -} from "@medusajs/modules-sdk" import { ContainerRegistrationKeys, ModulesSdkUtils } from "@medusajs/utils" -import { TestDatabase, getDatabaseURL, getMikroOrmWrapper } from "./database" import { InitModulesOptions, initModules } from "./init-modules" +import { MedusaAppOutput, ModulesDefinition } from "@medusajs/modules-sdk" +import { TestDatabase, getDatabaseURL, getMikroOrmWrapper } from "./database" import { MockEventBusService } from "." @@ -25,6 +22,7 @@ export function moduleIntegrationTestRunner({ joinerConfig = [], schema = "public", debug = false, + resolve, testSuite, injectedDependencies = {}, }: { @@ -34,6 +32,7 @@ export function moduleIntegrationTestRunner({ joinerConfig?: any[] schema?: string dbName?: string + resolve?: string injectedDependencies?: Record debug?: boolean testSuite: (options: SuiteOptions) => () => void @@ -64,6 +63,7 @@ export function moduleIntegrationTestRunner({ const modulesConfig_ = { [moduleName]: { definition: ModulesDefinition[moduleName], + resolve, options: { defaultAdapterOptions: { database: dbConfig, diff --git a/packages/stock-location-next/.gitignore b/packages/stock-location-next/.gitignore new file mode 100644 index 0000000000..874c6c69d3 --- /dev/null +++ b/packages/stock-location-next/.gitignore @@ -0,0 +1,6 @@ +/dist +node_modules +.DS_store +.env* +.env +*.sql diff --git a/packages/stock-location-next/CHANGELOG.md b/packages/stock-location-next/CHANGELOG.md new file mode 100644 index 0000000000..e54ae02133 --- /dev/null +++ b/packages/stock-location-next/CHANGELOG.md @@ -0,0 +1,263 @@ +# @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-next/integration-tests/__tests__/stock-location-module-service.spec.ts b/packages/stock-location-next/integration-tests/__tests__/stock-location-module-service.spec.ts new file mode 100644 index 0000000000..cf57872c21 --- /dev/null +++ b/packages/stock-location-next/integration-tests/__tests__/stock-location-module-service.spec.ts @@ -0,0 +1,158 @@ +import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils" + +import { IStockLocationService } from "@medusajs/types" +import { Modules } from "@medusajs/modules-sdk" + +jest.setTimeout(100000) + +moduleIntegrationTestRunner({ + moduleName: Modules.STOCK_LOCATION, + resolve: "@medusajs/stock-location-next", + testSuite: ({ + MikroOrmWrapper, + service, + }: SuiteOptions) => { + describe("Stock Location Module Service", () => { + describe("create", () => { + it("should create a stock location", async () => { + const data = { name: "location" } + const location = await service.create(data) + + expect(location).toEqual( + expect.objectContaining({ id: expect.any(String), ...data }) + ) + }) + + it("should create stock locations for arrray", async () => { + const data = [{ name: "location" }, { name: "location-1" }] + const locations = await service.create(data) + + expect(locations).toEqual([ + expect.objectContaining({ id: expect.any(String), ...data[0] }), + expect.objectContaining({ id: expect.any(String), ...data[1] }), + ]) + }) + + it("should create a stock location with addresses", async () => { + const data = { + name: "location", + address: { city: "city", address_1: "street", country_code: "US" }, + } + const location = await service.create(data) + + expect(location).toEqual( + expect.objectContaining({ + id: expect.any(String), + ...data, + address: expect.objectContaining({ + id: expect.any(String), + ...data.address, + }), + }) + ) + }) + + it("should create stock locations with addresses", async () => { + const data = [ + { + name: "location", + address: { + city: "city", + address_1: "street", + country_code: "US", + }, + }, + { + name: "location-1", + address: { + city: "city 1", + address_1: "street 1", + country_code: "US", + }, + }, + ] + const location = await service.create(data) + + expect(location).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(String), + ...data[0], + address: expect.objectContaining({ + id: expect.any(String), + ...data[0].address, + }), + }), + expect.objectContaining({ + id: expect.any(String), + ...data[1], + address: expect.objectContaining({ + id: expect.any(String), + ...data[1].address, + }), + }), + ]) + ) + }) + }) + + describe("update", () => { + let stockLocation + beforeEach(async () => { + stockLocation = await service.create({ name: "location" }) + }) + + it("should update a stock location", async () => { + const data = { + id: stockLocation.id, + name: "updated location", + } + const location = await service.update(data) + + expect(location).toEqual(expect.objectContaining(data)) + }) + + it("should update a stock location with an address", async () => { + const data = { + id: stockLocation.id, + address: { + address_1: "street", + city: "city", + country_code: "US", + }, + } + + const location = await service.update(data) + + expect(location).toEqual( + expect.objectContaining({ + address: expect.objectContaining(data.address), + }) + ) + }) + }) + + describe("updateStockLocationAddress", () => { + let stockLocation + beforeEach(async () => { + stockLocation = await service.create({ + name: "location", + address: { city: "city", address_1: "street", country_code: "US" }, + }) + }) + + it("should update an address", async () => { + const data = { + id: stockLocation.address.id, + city: "updated city", + address_1: "updated address_1", + country_code: "updated country_code", + } + const location = await service.updateStockLocationAddress(data) + + expect(location).toEqual(expect.objectContaining(data)) + }) + }) + }) + }, +}) diff --git a/packages/stock-location-next/jest.config.js b/packages/stock-location-next/jest.config.js new file mode 100644 index 0000000000..701550aa4b --- /dev/null +++ b/packages/stock-location-next/jest.config.js @@ -0,0 +1,13 @@ +module.exports = { + transform: { + "^.+\\.[jt]s?$": [ + "ts-jest", + { + tsConfig: "tsconfig.spec.json", + isolatedModules: true, + }, + ], + }, + testEnvironment: `node`, + moduleFileExtensions: [`js`, `ts`], +} diff --git a/packages/stock-location-next/mikro-orm.config.dev.ts b/packages/stock-location-next/mikro-orm.config.dev.ts new file mode 100644 index 0000000000..44d8bb6455 --- /dev/null +++ b/packages/stock-location-next/mikro-orm.config.dev.ts @@ -0,0 +1,13 @@ +import * as entities from "./src/models" + +import { TSMigrationGenerator } from "@medusajs/utils" + +module.exports = { + entities: Object.values(entities), + schema: "public", + clientUrl: "postgres://postgres@localhost/medusa-stock-location", + type: "postgresql", + migrations: { + generator: TSMigrationGenerator, + }, +} diff --git a/packages/stock-location-next/package.json b/packages/stock-location-next/package.json new file mode 100644 index 0000000000..1b8f275dac --- /dev/null +++ b/packages/stock-location-next/package.json @@ -0,0 +1,58 @@ +{ + "name": "@medusajs/stock-location-next", + "version": "0.0.1", + "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", + "@mikro-orm/cli": "5.9.7", + "cross-env": "^5.2.1", + "jest": "^29.6.3", + "medusa-test-utils": "^1.1.40", + "rimraf": "^5.0.1", + "ts-jest": "^29.1.1", + "ts-node": "^10.9.1", + "tsc-alias": "^1.8.6", + "typescript": "^5.1.6" + }, + "dependencies": { + "@medusajs/modules-sdk": "^1.12.4", + "@medusajs/types": "^1.11.8", + "@medusajs/utils": "^1.11.1", + "@mikro-orm/core": "5.9.7", + "@mikro-orm/migrations": "5.9.7", + "@mikro-orm/postgresql": "5.9.7", + "awilix": "^8.0.0", + "dotenv": "16.4.5", + "knex": "2.4.2" + }, + "scripts": { + "watch": "tsc --build --watch", + "watch:test": "tsc --build tsconfig.spec.json --watch", + "prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json", + "build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json", + "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", + "test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.spec.ts", + "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate", + "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial -n InitialSetupMigration", + "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create", + "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up", + "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear" + } +} diff --git a/packages/stock-location-next/src/index.ts b/packages/stock-location-next/src/index.ts new file mode 100644 index 0000000000..f9bdcf3c9e --- /dev/null +++ b/packages/stock-location-next/src/index.ts @@ -0,0 +1,14 @@ +import { Modules, initializeFactory } from "@medusajs/modules-sdk" + +import { moduleDefinition } from "./module-definition" + +export * from "./models" +export * from "./services" + +export const initialize = initializeFactory({ + moduleName: Modules.STOCK_LOCATION, + moduleDefinition, +}) +export const runMigrations = moduleDefinition.runMigrations +export const revertMigration = moduleDefinition.revertMigration +export default moduleDefinition diff --git a/packages/stock-location-next/src/joiner-config.ts b/packages/stock-location-next/src/joiner-config.ts new file mode 100644 index 0000000000..6b07dcaeef --- /dev/null +++ b/packages/stock-location-next/src/joiner-config.ts @@ -0,0 +1,37 @@ +import { MapToConfig } from "@medusajs/utils" +import { ModuleJoinerConfig } from "@medusajs/types" +import { Modules } from "@medusajs/modules-sdk" +import { StockLocation } from "./models" +import moduleSchema from "./schema" + +export const LinkableKeys = { + stock_location_id: StockLocation.name, +} + +const entityLinkableKeysMap: MapToConfig = {} +Object.entries(LinkableKeys).forEach(([key, value]) => { + entityLinkableKeysMap[value] ??= [] + entityLinkableKeysMap[value].push({ + mapTo: key, + valueFrom: key.split("_").pop()!, + }) +}) +export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap + +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-next/src/migrations/.snapshot-medusa-stock-location.json b/packages/stock-location-next/src/migrations/.snapshot-medusa-stock-location.json new file mode 100644 index 0000000000..14628770a4 --- /dev/null +++ b/packages/stock-location-next/src/migrations/.snapshot-medusa-stock-location.json @@ -0,0 +1,270 @@ +{ + "namespaces": [ + "public" + ], + "name": "public", + "tables": [ + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "address_1": { + "name": "address_1", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "address_2": { + "name": "address_2", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "company": { + "name": "company", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "city": { + "name": "city", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "country_code": { + "name": "country_code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "phone": { + "name": "phone", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "province": { + "name": "province", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + } + }, + "name": "stock_location_address", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_stock_location_address_deleted_at", + "columnNames": [ + "deleted_at" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_stock_location_address_deleted_at\" ON \"stock_location_address\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "stock_location_address_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, + "name": { + "name": "name", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "address_id": { + "name": "address_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + } + }, + "name": "stock_location", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_stock_location_deleted_at", + "columnNames": [ + "deleted_at" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_stock_location_deleted_at\" ON \"stock_location\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "stock_location_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "stock_location_address_id_foreign": { + "constraintName": "stock_location_address_id_foreign", + "columnNames": [ + "address_id" + ], + "localTableName": "public.stock_location", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.stock_location_address", + "deleteRule": "set null", + "updateRule": "cascade" + } + } + } + ] +} diff --git a/packages/stock-location-next/src/migrations/Migration20240307161216.ts b/packages/stock-location-next/src/migrations/Migration20240307161216.ts new file mode 100644 index 0000000000..ca82b0db33 --- /dev/null +++ b/packages/stock-location-next/src/migrations/Migration20240307161216.ts @@ -0,0 +1,23 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20240307161216 extends Migration { + + async up(): Promise { + this.addSql('create table if not exists "stock_location_address" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "address_1" text not null, "address_2" text null, "company" text null, "city" text null, "country_code" text not null, "phone" text null, "province" text null, "postal_code" text null, "metadata" jsonb null, constraint "stock_location_address_pkey" primary key ("id"));'); + this.addSql('CREATE INDEX IF NOT EXISTS "IDX_stock_location_address_deleted_at" ON "stock_location_address" (deleted_at) WHERE deleted_at IS NOT NULL;'); + + this.addSql('create table if not exists "stock_location" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "name" text not null, "address_id" text null, "metadata" jsonb null, constraint "stock_location_pkey" primary key ("id"));'); + this.addSql('CREATE INDEX IF NOT EXISTS "IDX_stock_location_deleted_at" ON "stock_location" (deleted_at) WHERE deleted_at IS NOT NULL;'); + + this.addSql('alter table if exists "stock_location" add constraint "stock_location_address_id_foreign" foreign key ("address_id") references "stock_location_address" ("id") on update cascade on delete set null;'); + } + + async down(): Promise { + this.addSql('alter table if exists "stock_location" drop constraint if exists "stock_location_address_id_foreign";'); + + this.addSql('drop table if exists "stock_location_address" cascade;'); + + this.addSql('drop table if exists "stock_location" cascade;'); + } + +} diff --git a/packages/stock-location-next/src/models/index.ts b/packages/stock-location-next/src/models/index.ts new file mode 100644 index 0000000000..732b15fc23 --- /dev/null +++ b/packages/stock-location-next/src/models/index.ts @@ -0,0 +1,2 @@ +export * from "./stock-location" +export * from "./stock-location-address" diff --git a/packages/stock-location-next/src/models/stock-location-address.ts b/packages/stock-location-next/src/models/stock-location-address.ts new file mode 100644 index 0000000000..d8ec2f3771 --- /dev/null +++ b/packages/stock-location-next/src/models/stock-location-address.ts @@ -0,0 +1,79 @@ +import { + BeforeCreate, + Entity, + OnInit, + PrimaryKey, + Property, +} from "@mikro-orm/core" +import { + createPsqlIndexStatementHelper, + generateEntityId, +} from "@medusajs/utils" + +const StockLocationAddressDeletedAtIndex = createPsqlIndexStatementHelper({ + tableName: "stock_location_address", + columns: "deleted_at", + where: "deleted_at IS NOT NULL", +}) + +@Entity() +export class StockLocationAddress { + @PrimaryKey({ columnType: "text" }) + id: string + + @Property({ + onCreate: () => new Date(), + columnType: "timestamptz", + defaultRaw: "now()", + }) + created_at: Date + + @Property({ + onCreate: () => new Date(), + onUpdate: () => new Date(), + columnType: "timestamptz", + defaultRaw: "now()", + }) + updated_at: Date + + @StockLocationAddressDeletedAtIndex.MikroORMIndex() + @Property({ columnType: "timestamptz", nullable: true }) + deleted_at: Date | null = null + + @Property({ columnType: "text" }) + address_1: string + + @Property({ columnType: "text", nullable: true }) + address_2: string | null + + @Property({ columnType: "text", nullable: true }) + company: string | null + + @Property({ columnType: "text", nullable: true }) + city: string | null + + @Property({ columnType: "text" }) + country_code: string + + @Property({ columnType: "text", nullable: true }) + phone: string | null + + @Property({ columnType: "text", nullable: true }) + province: string | null + + @Property({ columnType: "text", nullable: true }) + postal_code: string | null + + @Property({ columnType: "jsonb", nullable: true }) + metadata: Record | null + + @BeforeCreate() + private beforeCreate(): void { + this.id = generateEntityId(this.id, "laddr") + } + + @OnInit() + private onInit(): void { + this.id = generateEntityId(this.id, "laddr") + } +} diff --git a/packages/stock-location-next/src/models/stock-location.ts b/packages/stock-location-next/src/models/stock-location.ts new file mode 100644 index 0000000000..7fff2b1a30 --- /dev/null +++ b/packages/stock-location-next/src/models/stock-location.ts @@ -0,0 +1,75 @@ +import { + BeforeCreate, + Entity, + ManyToOne, + OnInit, + PrimaryKey, + Property, +} from "@mikro-orm/core" +import { + createPsqlIndexStatementHelper, + generateEntityId, +} from "@medusajs/utils" + +import { StockLocationAddress } from "./stock-location-address" + +const StockLocationDeletedAtIndex = createPsqlIndexStatementHelper({ + tableName: "stock_location", + columns: "deleted_at", + where: "deleted_at IS NOT NULL", +}) + +@Entity() +export class StockLocation { + @PrimaryKey({ columnType: "text" }) + id: string + + @Property({ + onCreate: () => new Date(), + columnType: "timestamptz", + defaultRaw: "now()", + }) + created_at: Date + + @Property({ + onCreate: () => new Date(), + onUpdate: () => new Date(), + columnType: "timestamptz", + defaultRaw: "now()", + }) + updated_at: Date + + @StockLocationDeletedAtIndex.MikroORMIndex() + @Property({ columnType: "timestamptz", nullable: true }) + deleted_at: Date | null = null + + @Property({ columnType: "text" }) + name: string + + @ManyToOne(() => StockLocationAddress, { + fieldName: "address_id", + type: "text", + mapToPk: true, + nullable: true, + onDelete: "cascade", + }) + address_id: string | null + + @ManyToOne(() => StockLocationAddress, { + nullable: true, + }) + address: StockLocationAddress | null + + @Property({ columnType: "jsonb", nullable: true }) + metadata: Record | null + + @BeforeCreate() + private beforeCreate(): void { + this.id = generateEntityId(this.id, "sloc") + } + + @OnInit() + private onInit(): void { + this.id = generateEntityId(this.id, "sloc") + } +} diff --git a/packages/stock-location-next/src/module-definition.ts b/packages/stock-location-next/src/module-definition.ts new file mode 100644 index 0000000000..ddeba045bd --- /dev/null +++ b/packages/stock-location-next/src/module-definition.ts @@ -0,0 +1,44 @@ +import * as StockLocationModels from "@models" +import * as StockLocationRepostiories from "@repositories" +import * as StockLocationServices from "@services" + +import { ModuleExports } from "@medusajs/types" +import { Modules } from "@medusajs/modules-sdk" +import { ModulesSdkUtils } from "@medusajs/utils" +import { StockLocationModuleService } from "@services" + +const migrationScriptOptions = { + moduleName: Modules.STOCK_LOCATION, + models: StockLocationModels, + pathToMigrations: __dirname + "/migrations", +} + +const runMigrations = ModulesSdkUtils.buildMigrationScript( + migrationScriptOptions +) + +const revertMigration = ModulesSdkUtils.buildRevertMigrationScript( + migrationScriptOptions +) + +const containerLoader = ModulesSdkUtils.moduleContainerLoaderFactory({ + moduleModels: StockLocationModels, + moduleRepositories: StockLocationRepostiories, + moduleServices: StockLocationServices, +}) + +const connectionLoader = ModulesSdkUtils.mikroOrmConnectionLoaderFactory({ + moduleName: Modules.STOCK_LOCATION, + moduleModels: Object.values(StockLocationModels), + migrationsPath: __dirname + "/migrations", +}) + +const service = StockLocationModuleService +const loaders = [containerLoader, connectionLoader] + +export const moduleDefinition: ModuleExports = { + service, + loaders, + revertMigration, + runMigrations, +} diff --git a/packages/stock-location-next/src/repositories/index.ts b/packages/stock-location-next/src/repositories/index.ts new file mode 100644 index 0000000000..147c9cc259 --- /dev/null +++ b/packages/stock-location-next/src/repositories/index.ts @@ -0,0 +1 @@ +export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils" diff --git a/packages/stock-location-next/src/schema/index.ts b/packages/stock-location-next/src/schema/index.ts new file mode 100644 index 0000000000..9a7b198d62 --- /dev/null +++ b/packages/stock-location-next/src/schema/index.ts @@ -0,0 +1,29 @@ +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-next/src/services/__tests__/noop.ts b/packages/stock-location-next/src/services/__tests__/noop.ts new file mode 100644 index 0000000000..333c84c1dd --- /dev/null +++ b/packages/stock-location-next/src/services/__tests__/noop.ts @@ -0,0 +1,5 @@ +describe("noop", function () { + it("should run", function () { + expect(true).toBe(true) + }) +}) diff --git a/packages/stock-location-next/src/services/index.ts b/packages/stock-location-next/src/services/index.ts new file mode 100644 index 0000000000..3facc2c5c6 --- /dev/null +++ b/packages/stock-location-next/src/services/index.ts @@ -0,0 +1 @@ +export { default as StockLocationModuleService } from "./stock-location" diff --git a/packages/stock-location-next/src/services/stock-location.ts b/packages/stock-location-next/src/services/stock-location.ts new file mode 100644 index 0000000000..a02ac28ef5 --- /dev/null +++ b/packages/stock-location-next/src/services/stock-location.ts @@ -0,0 +1,197 @@ +import { InternalModuleDeclaration } from "@medusajs/modules-sdk" +import { + Context, + CreateStockLocationInput, + IEventBusService, + ModuleJoinerConfig, + StockLocationAddressInput, + StockLocationTypes, + UpdateStockLocationInput, + ModulesSdkTypes, + DAL, + IStockLocationServiceNext, +} from "@medusajs/types" +import { + InjectManager, + InjectTransactionManager, + MedusaContext, + ModulesSdkUtils, +} from "@medusajs/utils" +import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" +import { StockLocation, StockLocationAddress } from "../models" +import { UpdateStockLocationNextInput } from "@medusajs/types" + +type InjectedDependencies = { + eventBusService: IEventBusService + baseRepository: DAL.RepositoryService + stockLocationService: ModulesSdkTypes.InternalModuleService + stockLocationAddressService: ModulesSdkTypes.InternalModuleService +} + +const generateMethodForModels = [StockLocationAddress] + +/** + * Service for managing stock locations. + */ + +export default class StockLocationModuleService< + TEntity extends StockLocation = StockLocation, + TStockLocationAddress extends StockLocationAddress = StockLocationAddress + > + extends ModulesSdkUtils.abstractModuleServiceFactory< + InjectedDependencies, + StockLocationTypes.StockLocationDTO, + { + StockLocation: { dto: StockLocationTypes.StockLocationDTO } + StockLocationAddress: { dto: StockLocationTypes.StockLocationAddressDTO } + } + >(StockLocation, generateMethodForModels, entityNameToLinkableKeysMap) + implements IStockLocationServiceNext +{ + protected readonly eventBusService_: IEventBusService + protected baseRepository_: DAL.RepositoryService + protected readonly stockLocationService_: ModulesSdkTypes.InternalModuleService + protected readonly stockLocationAddressService_: ModulesSdkTypes.InternalModuleService + + constructor( + { + eventBusService, + baseRepository, + stockLocationService, + stockLocationAddressService, + }: InjectedDependencies, + protected readonly moduleDeclaration?: InternalModuleDeclaration + ) { + // @ts-ignore + super(...arguments) + + this.baseRepository_ = baseRepository + this.stockLocationService_ = stockLocationService + this.stockLocationAddressService_ = stockLocationAddressService + this.eventBusService_ = eventBusService + } + + __joinerConfig(): ModuleJoinerConfig { + return joinerConfig + } + + create( + data: CreateStockLocationInput, + context: Context + ): Promise + create( + data: CreateStockLocationInput[], + context: Context + ): Promise + + /** + * Creates a new stock location. + * @param data - The input data for creating a Stock Location. + * @param context + * @returns The created stock location. + */ + @InjectManager("baseRepository_") + async create( + data: CreateStockLocationInput | CreateStockLocationInput[], + @MedusaContext() context: Context = {} + ): Promise< + StockLocationTypes.StockLocationDTO | StockLocationTypes.StockLocationDTO[] + > { + const input = Array.isArray(data) ? data : [data] + + const created = await this.create_(input, context) + + const serialized = await this.baseRepository_.serialize< + | StockLocationTypes.StockLocationDTO + | StockLocationTypes.StockLocationDTO[] + >(created, { populate: true }) + + return Array.isArray(data) ? serialized : serialized[0] + } + + @InjectTransactionManager("baseRepository_") + async create_( + data: CreateStockLocationInput[], + @MedusaContext() context: Context = {} + ): Promise { + return await this.stockLocationService_.create(data, context) + } + + update( + data: UpdateStockLocationNextInput, + context: Context + ): Promise + update( + data: UpdateStockLocationNextInput[], + context: Context + ): Promise + /** + * 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. + */ + @InjectManager("baseRepository_") + async update( + data: UpdateStockLocationNextInput | UpdateStockLocationNextInput[], + @MedusaContext() context: Context = {} + ): Promise< + StockLocationTypes.StockLocationDTO | StockLocationTypes.StockLocationDTO[] + > { + const input = Array.isArray(data) ? data : [data] + + const updated = await this.update_(input, context) + + const serialized = await this.baseRepository_.serialize< + | StockLocationTypes.StockLocationDTO + | StockLocationTypes.StockLocationDTO[] + >(updated, { populate: true }) + + return Array.isArray(data) ? serialized : serialized[0] + } + + @InjectTransactionManager("baseRepository_") + async update_( + data: (UpdateStockLocationInput & { id: string })[], + @MedusaContext() context: Context = {} + ): Promise { + return await this.stockLocationService_.update(data, context) + } + + updateStockLocationAddress( + data: StockLocationAddressInput & { id: string }, + context?: Context + ): Promise + updateStockLocationAddress( + data: (StockLocationAddressInput & { id: string })[], + context?: Context + ): Promise + + @InjectManager("baseRepository_") + async updateStockLocationAddress( + data: + | (StockLocationAddressInput & { id: string }) + | (StockLocationAddressInput & { id: string })[], + @MedusaContext() context: Context = {} + ) { + const input = Array.isArray(data) ? data : [data] + + const updated = await this.updateStockLocationAddress_(input, context) + + const serialized = await this.baseRepository_.serialize< + | StockLocationTypes.StockLocationAddressDTO + | StockLocationTypes.StockLocationAddressDTO[] + >(updated, { populate: true }) + + return Array.isArray(data) ? serialized : serialized[0] + } + + @InjectTransactionManager("baseRepository_") + private async updateStockLocationAddress_( + input: (StockLocationAddressInput & { id: string })[], + @MedusaContext() context: Context + ) { + return await this.stockLocationAddressService_.update(input, context) + } +} diff --git a/packages/stock-location-next/tsconfig.json b/packages/stock-location-next/tsconfig.json new file mode 100644 index 0000000000..7adee6410c --- /dev/null +++ b/packages/stock-location-next/tsconfig.json @@ -0,0 +1,38 @@ +{ + "compilerOptions": { + "lib": ["es2020"], + "target": "es2020", + "outDir": "./dist", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": false, + "noImplicitReturns": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noImplicitThis": true, + "allowJs": true, + "skipLibCheck": true, + "downlevelIteration": true, // to use ES5 specific tooling + "baseUrl": ".", + "resolveJsonModule": true, + "paths": { + "@models": ["./src/models"], + "@services": ["./src/services"], + "@repositories": ["./src/repositories"], + "@types": ["./src/types"], + "@utils": ["./src/utils"] + } + }, + "include": ["src"], + "exclude": [ + "dist", + "./src/**/__tests__", + "./src/**/__mocks__", + "./src/**/__fixtures__", + "node_modules" + ] +} diff --git a/packages/stock-location-next/tsconfig.spec.json b/packages/stock-location-next/tsconfig.spec.json new file mode 100644 index 0000000000..9b62409191 --- /dev/null +++ b/packages/stock-location-next/tsconfig.spec.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "include": ["src"], + "exclude": ["node_modules"] +} diff --git a/packages/types/src/stock-location/common.ts b/packages/types/src/stock-location/common.ts index fac5606cca..72fef1d687 100644 --- a/packages/types/src/stock-location/common.ts +++ b/packages/types/src/stock-location/common.ts @@ -431,3 +431,7 @@ export type UpdateStockLocationInput = { */ metadata?: Record } + +export type UpdateStockLocationNextInput = UpdateStockLocationInput & { + id: string +} diff --git a/packages/types/src/stock-location/index.ts b/packages/types/src/stock-location/index.ts index eade309433..1d8d51e51e 100644 --- a/packages/types/src/stock-location/index.ts +++ b/packages/types/src/stock-location/index.ts @@ -1,2 +1,3 @@ export * from "./common" export * from "./service" +export * from "./service-next" diff --git a/packages/types/src/stock-location/service-next.ts b/packages/types/src/stock-location/service-next.ts new file mode 100644 index 0000000000..148b170f9b --- /dev/null +++ b/packages/types/src/stock-location/service-next.ts @@ -0,0 +1,304 @@ +import { + CreateStockLocationInput, + FilterableStockLocationProps, + StockLocationDTO, + UpdateStockLocationInput, + UpdateStockLocationNextInput, +} from "./common" + +import { Context } from "../shared-context" +import { FindConfig } from "../common/common" +import { IModuleService } from "../modules-sdk" + +/** + * The main service interface for the stock location's module. + */ +export interface IStockLocationServiceNext extends IModuleService { + /** + * This method is used to retrieve a paginated list of stock locations based on optional filters and configuration. + * + * @param {FilterableStockLocationProps} selector - The filters to apply on the retrieved stock locations. + * @param {FindConfig} config - + * The configurations determining how the stock locations are retrieved. Its properties, such as `select` or `relations`, accept the + * attributes or relations associated with a stock location. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @return {Promise} The list of stock locations. + * + * @example + * To retrieve a list of stock locations using their IDs: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function listStockLocations (ids: string[]) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const stockLocations = await stockLocationModule.list({ + * id: ids + * }) + * + * // do something with the stock locations or return them + * } + * ``` + * + * To specify relations that should be retrieved within the stock locations: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function listStockLocations (ids: string[]) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const stockLocations = await stockLocationModule.list({ + * id: ids + * }, { + * relations: ["address"] + * }) + * + * // do something with the stock locations or return them + * } + * ``` + * + * By default, only the first `10` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function listStockLocations (ids: string[], skip: number, take: number) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const stockLocations = await stockLocationModule.list({ + * id: ids + * }, { + * relations: ["address"], + * skip, + * take + * }) + * + * // do something with the stock locations or return them + * } + * ``` + */ + list( + selector: FilterableStockLocationProps, + config?: FindConfig, + context?: Context + ): Promise + + /** + * This method is used to retrieve a paginated list of stock locations along with the total count of available stock locations satisfying the provided filters. + * + * @param {FilterableStockLocationProps} selector - The filters to apply on the retrieved stock locations. + * @param {FindConfig} config - + * The configurations determining how the stock locations are retrieved. Its properties, such as `select` or `relations`, accept the + * attributes or relations associated with a stock location. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @return {Promise<[StockLocationDTO[], number]>} The list of stock locations along with the total count. + * + * @example + * To retrieve a list of stock locations using their IDs: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function listStockLocations (ids: string[]) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const [stockLocations, count] = await stockLocationModule.listAndCount({ + * id: ids + * }) + * + * // do something with the stock locations or return them + * } + * ``` + * + * To specify relations that should be retrieved within the stock locations: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function listStockLocations (ids: string[]) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const [stockLocations, count] = await stockLocationModule.listAndCount({ + * id: ids + * }, { + * relations: ["address"] + * }) + * + * // do something with the stock locations or return them + * } + * ``` + * + * By default, only the first `10` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function listStockLocations (ids: string[], skip: number, take: number) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const [stockLocations, count] = await stockLocationModule.listAndCount({ + * id: ids + * }, { + * relations: ["address"], + * skip, + * take + * }) + * + * // do something with the stock locations or return them + * } + * ``` + */ + listAndCount( + selector: FilterableStockLocationProps, + config?: FindConfig, + context?: Context + ): Promise<[StockLocationDTO[], number]> + + /** + * This method is used to retrieve a stock location by its ID + * + * @param {string} id - The ID of the stock location + * @param {FindConfig} config - + * The configurations determining how the stock location is retrieved. Its properties, such as `select` or `relations`, accept the + * attributes or relations associated with a stock location. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The stock location's details. + * + * @example + * A simple example that retrieves a inventory item by its ID: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function retrieveStockLocation (id: string) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const stockLocation = await stockLocationModule.retrieve(id) + * + * // do something with the stock location or return it + * } + * ``` + * + * To specify relations that should be retrieved: + * + * ```ts + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function retrieveStockLocation (id: string) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const stockLocation = await stockLocationModule.retrieve(id, { + * relations: ["address"] + * }) + * + * // do something with the stock location or return it + * } + * ``` + */ + retrieve( + id: string, + config?: FindConfig, + context?: Context + ): Promise + + /** + * This method is used to create a stock location. + * + * @param {CreateStockLocationInput} input - The details of the stock location to create. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The created stock location's details. + * + * @example + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function createStockLocation (name: string) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const stockLocation = await stockLocationModule.create({ + * name + * }) + * + * // do something with the stock location or return it + * } + */ + create( + input: CreateStockLocationInput, + context?: Context + ): Promise + create( + input: CreateStockLocationInput[], + context?: Context + ): Promise + + /** + * This method is used to update a stock location. + * + * @param {string} id - The ID of the stock location. + * @param {UpdateStockLocationInput} input - The attributes to update in the stock location. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The stock location's details. + * + * @example + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function updateStockLocation (id:string, name: string) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * const stockLocation = await stockLocationModule.update(id, { + * name + * }) + * + * // do something with the stock location or return it + * } + */ + update( + input: UpdateStockLocationNextInput[], + context?: Context + ): Promise + update( + input: UpdateStockLocationNextInput, + context?: Context + ): Promise + + /** + * This method is used to delete a stock location. + * + * @param {string} id - The ID of the stock location. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} Resolves when the stock location is successfully deleted. + * + * @example + * import { + * initialize as initializeStockLocationModule, + * } from "@medusajs/stock-location" + * + * async function deleteStockLocation (id:string) { + * const stockLocationModule = await initializeStockLocationModule({}) + * + * await stockLocationModule.delete(id) + * } + */ + delete(id: string, context?: Context): Promise +} diff --git a/packages/types/src/stock-location/stock-location.ts b/packages/types/src/stock-location/stock-location.ts deleted file mode 100644 index 502c5803f9..0000000000 --- a/packages/types/src/stock-location/stock-location.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - CreateStockLocationInput, - FilterableStockLocationProps, - StockLocationDTO, - UpdateStockLocationInput, -} from "./common" - -import { FindConfig } from "../common/common" -import { SharedContext } from "../shared-context" - -export interface IStockLocationService { - list( - selector: FilterableStockLocationProps, - config?: FindConfig, - context?: SharedContext - ): Promise - - listAndCount( - selector: FilterableStockLocationProps, - config?: FindConfig, - context?: SharedContext - ): Promise<[StockLocationDTO[], number]> - - retrieve( - id: string, - config?: FindConfig, - context?: SharedContext - ): Promise - - create( - input: CreateStockLocationInput, - context?: SharedContext - ): Promise - - update( - id: string, - input: UpdateStockLocationInput, - context?: SharedContext - ): Promise - - delete(id: string, context?: SharedContext): Promise -} diff --git a/yarn.lock b/yarn.lock index 9fdbf6aa18..fe573b1870 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8818,6 +8818,31 @@ __metadata: languageName: unknown linkType: soft +"@medusajs/stock-location-next@workspace:packages/stock-location-next": + version: 0.0.0-use.local + resolution: "@medusajs/stock-location-next@workspace:packages/stock-location-next" + dependencies: + "@medusajs/modules-sdk": ^1.12.4 + "@medusajs/types": ^1.11.12 + "@medusajs/utils": ^1.11.1 + "@mikro-orm/cli": 5.9.7 + "@mikro-orm/core": 5.9.7 + "@mikro-orm/migrations": 5.9.7 + "@mikro-orm/postgresql": 5.9.7 + awilix: ^8.0.0 + cross-env: ^5.2.1 + dotenv: 16.4.5 + jest: ^29.6.3 + knex: 2.4.2 + medusa-test-utils: ^1.1.40 + rimraf: ^5.0.1 + ts-jest: ^29.1.1 + ts-node: ^10.9.1 + tsc-alias: ^1.8.6 + typescript: ^5.1.6 + 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"