diff --git a/.gitignore b/.gitignore index f171bce..7e70a93 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ package-lock.json yarn.lock medusa-db.sql build +.cache \ No newline at end of file diff --git a/LICENSE b/LICENSE index a612ad9..9c3289a 100644 --- a/LICENSE +++ b/LICENSE @@ -2,6 +2,7 @@ Mozilla Public License Version 2.0 ================================== 1. Definitions + -------------- 1.1. "Contributor" @@ -84,6 +85,7 @@ Mozilla Public License Version 2.0 ownership of such entity. 2. License Grants and Conditions + -------------------------------- 2.1. Grants @@ -155,6 +157,7 @@ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. 3. Responsibilities + ------------------- 3.1. Distribution of Source Form @@ -217,6 +220,7 @@ disclaimers of warranty and limitations of liability specific to any jurisdiction. 4. Inability to Comply Due to Statute or Regulation + --------------------------------------------------- If it is impossible for You to comply with any of the terms of this @@ -230,6 +234,7 @@ or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 5. Termination + -------------- 5.1. The rights granted under this License will terminate automatically @@ -259,48 +264,53 @@ have been validly granted by You or Your distributors under this License prior to termination shall survive termination. ************************************************************************ -* * -* 6. Disclaimer of Warranty * -* ------------------------- * -* * -* Covered Software is provided under this License on an "as is" * -* basis, without warranty of any kind, either expressed, implied, or * -* statutory, including, without limitation, warranties that the * -* Covered Software is free of defects, merchantable, fit for a * -* particular purpose or non-infringing. The entire risk as to the * -* quality and performance of the Covered Software is with You. * -* Should any Covered Software prove defective in any respect, You * -* (not any Contributor) assume the cost of any necessary servicing, * -* repair, or correction. This disclaimer of warranty constitutes an * -* essential part of this License. No use of any Covered Software is * -* authorized under this License except under this disclaimer. * -* * + +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * + ************************************************************************ ************************************************************************ -* * -* 7. Limitation of Liability * -* -------------------------- * -* * -* Under no circumstances and under no legal theory, whether tort * -* (including negligence), contract, or otherwise, shall any * -* Contributor, or anyone who distributes Covered Software as * -* permitted above, be liable to You for any direct, indirect, * -* special, incidental, or consequential damages of any character * -* including, without limitation, damages for lost profits, loss of * -* goodwill, work stoppage, computer failure or malfunction, or any * -* and all other commercial damages or losses, even if such party * -* shall have been informed of the possibility of such damages. This * -* limitation of liability shall not apply to liability for death or * -* personal injury resulting from such party's negligence to the * -* extent applicable law prohibits such limitation. Some * -* jurisdictions do not allow the exclusion or limitation of * -* incidental or consequential damages, so this exclusion and * -* limitation may not apply to You. * -* * + +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * + ************************************************************************ 8. Litigation + ------------- Any litigation relating to this License may be brought only in the @@ -311,6 +321,7 @@ Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. 9. Miscellaneous + ---------------- This License represents the complete agreement concerning the subject @@ -321,6 +332,7 @@ that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. 10. Versions of the License + --------------------------- 10.1. New Versions @@ -357,7 +369,7 @@ Exhibit A - Source Code Form License Notice This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. + file, You can obtain one at . If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE diff --git a/data/seed.json b/data/seed.json index c84682e..496c6e8 100644 --- a/data/seed.json +++ b/data/seed.json @@ -1,6 +1,9 @@ { "store": { - "currencies": ["inr", "usd"] + "currencies": [ + "inr", + "usd" + ] }, "users": [ { @@ -14,18 +17,37 @@ "name": "EU", "currency_code": "eur", "tax_rate": 0, - "payment_providers": ["manual"], - "fulfillment_providers": ["manual"], - "countries": ["gb", "de", "dk", "se", "fr", "es", "it"] + "payment_providers": [ + "manual" + ], + "fulfillment_providers": [ + "manual" + ], + "countries": [ + "gb", + "de", + "dk", + "se", + "fr", + "es", + "it" + ] }, { "id": "test-region-na", "name": "NA", "currency_code": "usd", "tax_rate": 0, - "payment_providers": ["manual"], - "fulfillment_providers": ["manual"], - "countries": ["us", "ca"] + "payment_providers": [ + "manual" + ], + "fulfillment_providers": [ + "manual" + ], + "countries": [ + "us", + "ca" + ] } ], "shipping_options": [ @@ -131,11 +153,19 @@ "options": [ { "title": "Size", - "values": ["S", "M", "L", "XL"] + "values": [ + "S", + "M", + "L", + "XL" + ] }, { "title": "Color", - "values": ["Black", "White"] + "values": [ + "Black", + "White" + ] } ], "variants": [ @@ -339,7 +369,12 @@ "options": [ { "title": "Size", - "values": ["S", "M", "L", "XL"] + "values": [ + "S", + "M", + "L", + "XL" + ] } ], "variants": [ @@ -439,7 +474,12 @@ "options": [ { "title": "Size", - "values": ["S", "M", "L", "XL"] + "values": [ + "S", + "M", + "L", + "XL" + ] } ], "variants": [ @@ -539,7 +579,12 @@ "options": [ { "title": "Size", - "values": ["S", "M", "L", "XL"] + "values": [ + "S", + "M", + "L", + "XL" + ] } ], "variants": [ @@ -639,7 +684,12 @@ "options": [ { "title": "Size", - "values": ["S", "M", "L", "XL"] + "values": [ + "S", + "M", + "L", + "XL" + ] } ], "variants": [ @@ -739,7 +789,12 @@ "options": [ { "title": "Size", - "values": ["S", "M", "L", "XL"] + "values": [ + "S", + "M", + "L", + "XL" + ] } ], "variants": [ @@ -838,7 +893,9 @@ "options": [ { "title": "Size", - "values": ["One Size"] + "values": [ + "One Size" + ] } ], "variants": [ @@ -1188,4 +1245,4 @@ "handle": "women" } ] -} +} \ No newline at end of file diff --git a/dump.rdb b/dump.rdb index fb09091..56e54e8 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/medusa-config.js b/medusa-config.js index 1413e19..e24c1bf 100644 --- a/medusa-config.js +++ b/medusa-config.js @@ -130,7 +130,7 @@ const plugins = [ /** @type {import('@medusajs/admin').PluginOptions} */ options: { autoRebuild: true, - path: "app", + path: "/app", }, }, ]; diff --git a/package.json b/package.json index 5537c65..d689ad1 100644 --- a/package.json +++ b/package.json @@ -24,12 +24,12 @@ }, "dependencies": { "@babel/preset-typescript": "^7.21.5", - "@medusajs/admin": "^6.0.0", + "@medusajs/admin": "^7.1.3", "@medusajs/cache-inmemory": "^1.8.7", "@medusajs/cache-redis": "^1.8.7", "@medusajs/event-bus-local": "^1.9.4", "@medusajs/event-bus-redis": "^1.8.7", - "@medusajs/medusa": "^1.12.0", + "@medusajs/medusa": "^1.17.0", "@medusajs/medusa-cli": "^1.3.15", "babel-preset-medusa-package": "^1.1.19", "body-parser": "^1.20.2", @@ -92,4 +92,4 @@ "engines": { "node": ">=18.0.0" } -} \ No newline at end of file +} diff --git a/src/api/index.ts b/src/api/index.ts index 2596c70..754711a 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,6 +1,25 @@ import { Router } from "express" +import { + getConfigFile, +} from "medusa-core-utils"; +import { ConfigModule } from "@medusajs/medusa"; +import cors from 'cors' +import { restrictUser } from "./routes/admin/restrict-user"; export default (rootDirectory: string): Router | Router[] => { - // add your custom routes here - return [] -} + const { configModule: { projectConfig } } = getConfigFile(rootDirectory, "medusa-config") + const storefrontCorsConfig = { + origin: [...(projectConfig.admin_cors || "")?.split(','), ...(projectConfig.store_cors || "").split(',')], + credentials: true, + } + + const router = Router(); + router.use(cors(storefrontCorsConfig)) + + const endpointHandlers = [restrictUser] + + + endpointHandlers.forEach(endpointHandle => endpointHandle(router)) + + return router +} \ No newline at end of file diff --git a/src/api/routes/admin/restrict-user.ts b/src/api/routes/admin/restrict-user.ts new file mode 100644 index 0000000..5c76636 --- /dev/null +++ b/src/api/routes/admin/restrict-user.ts @@ -0,0 +1,18 @@ +import { CustomerService, authenticate } from "@medusajs/medusa" +import express, { Router } from "express"; + +export const restrictUser = (router: Router) => { + router.use('/admin/restrict-user', express.json()); + + router.post('/admin/restrict-user', authenticate(), async (req, res) => { + const customerService = req.scope.resolve('customerService') as CustomerService; + try { + const result = await customerService.retrieveRegisteredByEmail(req.body.email) + await customerService.delete(result.id); + return res.json({ status: 200, message: 'User has been deleted!' }) + } catch (error) { + return res.status(500).json({ status: 500, message: 'An error occurred!', error: error instanceof Error ? error.message : error }) + } + + }) +} \ No newline at end of file diff --git a/src/api/routes/store/custom-route-handler.ts b/src/api/routes/store/custom-route-handler.ts deleted file mode 100644 index de9530d..0000000 --- a/src/api/routes/store/custom-route-handler.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Request, Response } from 'express' - -export default async (req: Request, res: Response): Promise => { - res.sendStatus(200) -} diff --git a/src/api/routes/store/index.ts b/src/api/routes/store/index.ts deleted file mode 100644 index 0631cda..0000000 --- a/src/api/routes/store/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as cors from "cors" -import { Router } from "express" -import * as bodyParser from "body-parser" -import customRouteHandler from "./custom-route-handler" -import { wrapHandler } from "@medusajs/medusa"; - -const storeRouter = Router() -export function getStoreRouter(storeCorsOptions): Router { - storeRouter.use(cors(storeCorsOptions), bodyParser.json()) - - storeRouter.post( - "/store/my-custom-path", - wrapHandler(customRouteHandler) - ) - - return storeRouter -} diff --git a/src/loaders/README.md b/src/loaders/README.md index a5dcfd2..5845453 100644 --- a/src/loaders/README.md +++ b/src/loaders/README.md @@ -16,4 +16,4 @@ import { AwilixContainer } from 'awilix' export default (container: AwilixContainer, config: Record): void | Promise => { /* Implement your own loader. */ } -``` \ No newline at end of file +``` diff --git a/src/migrations/README.md b/src/migrations/README.md index 6964714..bf42227 100644 --- a/src/migrations/README.md +++ b/src/migrations/README.md @@ -26,4 +26,4 @@ export class MyMigration1617703530229 implements MigrationInterface { } } -``` \ No newline at end of file +``` diff --git a/tsconfig.json b/tsconfig.json index 080cb6d..5341b84 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "lib": ["es5", "es6"], "target": "esnext", "allowJs": true, - "esModuleInterop": false, + "esModuleInterop": true, "module": "commonjs", "moduleResolution": "node", "emitDecoratorMetadata": true,