| 1 |
const { pluginRecommendations = [] } = window?.extAgentData?.agentContext || {}; |
| 2 |
const { adminUrl, homeUrl } = window?.extSharedData || {}; |
| 3 |
|
| 4 |
export const getPluginSetup = (pluginSlug) => { |
| 5 |
const plugin = pluginRecommendations.find(({ slug }) => slug === pluginSlug); |
| 6 |
if (!plugin?.redirectTo) return null; |
| 7 |
const url = makeRedirectUrl(plugin.redirectTo); |
| 8 |
return url ? { title: plugin.title, url } : null; |
| 9 |
}; |
| 10 |
|
| 11 |
const makeRedirectUrl = (url) => { |
| 12 |
try { |
| 13 |
return new URL( |
| 14 |
url.replace('{{ADMIN_URL}}', adminUrl).replace('{{HOME_URL}}', homeUrl), |
| 15 |
).toString(); |
| 16 |
} catch (e) { |
| 17 |
console.error(e); |
| 18 |
return ''; |
| 19 |
} |
| 20 |
}; |
| 21 |
|