Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Val <68596159+valya@users.noreply.github.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Valya Bullions <valya@n8n.io> Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: Danny Martini <despair.blue@gmail.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Giulio Andreini <g.andreini@gmail.com> Co-authored-by: Ayato Hayashi <go12limchangyong@gmail.com>
97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
|
|
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
|
import { useRootStore } from '@/stores/n8nRoot.store';
|
|
import { useSettingsStore } from '@/stores/settings.store';
|
|
import { useSourceControlStore } from '@/stores/sourceControl.store';
|
|
import { useUsersStore } from '@/stores/users.store';
|
|
import { initializeCloudHooks } from '@/hooks/register';
|
|
import { useVersionsStore } from '@/stores/versions.store';
|
|
import { useProjectsStore } from '@/features/projects/projects.store';
|
|
import { useRolesStore } from './stores/roles.store';
|
|
|
|
let coreInitialized = false;
|
|
let authenticatedFeaturesInitialized = false;
|
|
|
|
/**
|
|
* Initializes the core application stores and hooks
|
|
* This is called once, when the first route is loaded.
|
|
*/
|
|
export async function initializeCore() {
|
|
if (coreInitialized) {
|
|
return;
|
|
}
|
|
|
|
const settingsStore = useSettingsStore();
|
|
const usersStore = useUsersStore();
|
|
const versionsStore = useVersionsStore();
|
|
|
|
await settingsStore.initialize();
|
|
if (!settingsStore.isPreviewMode) {
|
|
await usersStore.initialize();
|
|
|
|
void versionsStore.checkForNewVersions();
|
|
|
|
if (settingsStore.isCloudDeployment) {
|
|
try {
|
|
await initializeCloudHooks();
|
|
} catch (e) {
|
|
console.error('Failed to initialize cloud hooks:', e);
|
|
}
|
|
}
|
|
}
|
|
|
|
coreInitialized = true;
|
|
}
|
|
|
|
/**
|
|
* Initializes the features of the application that require an authenticated user
|
|
*/
|
|
export async function initializeAuthenticatedFeatures() {
|
|
if (authenticatedFeaturesInitialized) {
|
|
return;
|
|
}
|
|
|
|
const usersStore = useUsersStore();
|
|
if (!usersStore.currentUser) {
|
|
return;
|
|
}
|
|
|
|
const sourceControlStore = useSourceControlStore();
|
|
const settingsStore = useSettingsStore();
|
|
const rootStore = useRootStore();
|
|
const nodeTypesStore = useNodeTypesStore();
|
|
const cloudPlanStore = useCloudPlanStore();
|
|
const projectsStore = useProjectsStore();
|
|
const rolesStore = useRolesStore();
|
|
|
|
if (sourceControlStore.isEnterpriseSourceControlEnabled) {
|
|
await sourceControlStore.getPreferences();
|
|
}
|
|
|
|
if (settingsStore.isTemplatesEnabled) {
|
|
try {
|
|
await settingsStore.testTemplatesEndpoint();
|
|
} catch (e) {}
|
|
}
|
|
|
|
if (rootStore.defaultLocale !== 'en') {
|
|
await nodeTypesStore.getNodeTranslationHeaders();
|
|
}
|
|
|
|
if (settingsStore.isCloudDeployment) {
|
|
try {
|
|
await cloudPlanStore.initialize();
|
|
} catch (e) {
|
|
console.error('Failed to initialize cloud plan store:', e);
|
|
}
|
|
}
|
|
await Promise.all([
|
|
projectsStore.getMyProjects(),
|
|
projectsStore.getPersonalProject(),
|
|
projectsStore.getProjectsCount(),
|
|
rolesStore.fetchRoles(),
|
|
]);
|
|
|
|
authenticatedFeaturesInitialized = true;
|
|
}
|