+ const result = this.getRegisteredPluginOrTheme(npmName)
+ if (!result || result.type !== PluginType.PLUGIN) return []
+
+ return result.registerHelpersStore.getSettings()
+ }
+
+ getRouter (npmName: string) {
+ const result = this.getRegisteredPluginOrTheme(npmName)
+ if (!result || result.type !== PluginType.PLUGIN) return null
+
+ return result.registerHelpersStore.getRouter()
+ }
+
+ getTranslations (locale: string) {
+ return this.translations[locale] || {}
+ }
+
+ async isTokenValid (token: MOAuthTokenUser, type: 'access' | 'refresh') {
+ const auth = this.getAuth(token.User.pluginAuth, token.authName)
+ if (!auth) return true
+
+ if (auth.hookTokenValidity) {
+ try {
+ const { valid } = await auth.hookTokenValidity({ token, type })
+
+ if (valid === false) {
+ logger.info('Rejecting %s token validity from auth %s of plugin %s', type, token.authName, token.User.pluginAuth)
+ }
+
+ return valid
+ } catch (err) {
+ logger.warn('Cannot run check token validity from auth %s of plugin %s.', token.authName, token.User.pluginAuth, { err })
+ return true
+ }
+ }
+
+ return true
+ }
+
+ // ###################### External events ######################
+
+ onLogout (npmName: string, authName: string, user: MUser) {
+ const auth = this.getAuth(npmName, authName)
+
+ if (auth?.onLogout) {
+ logger.info('Running onLogout function from auth %s of plugin %s', authName, npmName)
+
+ try {
+ auth.onLogout(user)
+ } catch (err) {
+ logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err })
+ }
+ }
+ }
+
+ onSettingsChanged (name: string, settings: any) {
+ const registered = this.getRegisteredPluginByShortName(name)
+ if (!registered) {
+ logger.error('Cannot find plugin %s to call on settings changed.', name)
+ }
+
+ for (const cb of registered.registerHelpersStore.getOnSettingsChangedCallbacks()) {
+ try {
+ cb(settings)
+ } catch (err) {
+ logger.error('Cannot run on settings changed callback for %s.', registered.npmName, { err })
+ }
+ }