{"version":3,"file":"plugin.mjs","sources":["../../../src/routes/providers/plugin.ts"],"sourcesContent":["import { type Core } from '@strapi/types';\nimport { createDebugger } from '../../utils';\n\nimport { AbstractRoutesProvider } from './abstract';\n\nconst debug = createDebugger('routes:provider:plugins');\n\n/**\n * Class providing routes from Strapi plugins.\n *\n * This class extracts and consolidates routes registered by Strapi plugins,\n * accommodating different ways plugins may define their routes.\n *\n * @extends {@link AbstractRoutesProvider}\n */\nexport class PluginRoutesProvider extends AbstractRoutesProvider {\n /**\n * Retrieves all routes registered in the Strapi plugins.\n *\n * It handles two cases:\n * - The plugin's routes are directly provided as a {@link Core.Route}[].\n * - The plugin's routes are defined as a record of routers which contain their own list of routes.\n *\n * @returns An array of {@link Core.Route} objects.\n */\n public get routes(): Core.Route[] {\n const { plugins } = this._strapi;\n\n const routes = Object.values(plugins).flatMap((plugin) => {\n const { routes } = plugin;\n\n return Array.isArray(routes)\n ? routes\n : Object.values(routes).flatMap((router: Core.Router) => {\n return router.routes.map((route: Core.Route) => {\n const hasOwnPrefix =\n route.config != null &&\n Object.prototype.hasOwnProperty.call(route.config, 'prefix');\n\n const effectivePrefix = hasOwnPrefix\n ? (route.config?.prefix ?? '')\n : (router.prefix ?? '');\n\n const fullPath =\n (`${effectivePrefix}${route.path}` || '/')\n .replace(/\\/+/g, '/')\n .replace(/\\/$/, '') || '/';\n\n return {\n ...route,\n path: fullPath,\n };\n });\n });\n });\n\n debug('found %o routes in Strapi plugins', routes.length);\n\n return routes;\n }\n}\n"],"names":["debug","createDebugger","PluginRoutesProvider","AbstractRoutesProvider","routes","plugins","_strapi","Object","values","flatMap","plugin","Array","isArray","router","map","route","hasOwnPrefix","config","prototype","hasOwnProperty","call","effectivePrefix","prefix","fullPath","path","replace","length"],"mappings":";;;;;AAKA,MAAMA,QAAQC,cAAAA,CAAe,yBAAA,CAAA;AAE7B;;;;;;;IAQO,MAAMC,oBAAAA,SAA6BC,sBAAAA,CAAAA;AACxC;;;;;;;;AAQC,MACD,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