2023-05-15 14:16:13 -07:00
|
|
|
import { CLOUD_BASE_URL_PRODUCTION, CLOUD_BASE_URL_STAGING, STORES } from '@/constants';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { IRestApiContext, RootState } from '@/Interface';
|
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
import Vue from 'vue';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useNodeTypesStore } from './nodeTypes.store';
|
2022-11-04 06:04:31 -07:00
|
|
|
|
2023-04-06 02:35:05 -07:00
|
|
|
const { VUE_APP_URL_BASE_API } = import.meta.env;
|
2023-01-26 17:09:30 -08:00
|
|
|
|
2022-11-04 06:04:31 -07:00
|
|
|
export const useRootStore = defineStore(STORES.ROOT, {
|
|
|
|
state: (): RootState => ({
|
2023-01-26 17:09:30 -08:00
|
|
|
baseUrl:
|
2023-01-27 02:16:34 -08:00
|
|
|
VUE_APP_URL_BASE_API ?? (window.BASE_PATH === '/{{BASE_PATH}}/' ? '/' : window.BASE_PATH),
|
2023-04-06 02:35:05 -07:00
|
|
|
restEndpoint:
|
|
|
|
!window.REST_ENDPOINT || window.REST_ENDPOINT === '{{REST_ENDPOINT}}'
|
|
|
|
? 'rest'
|
|
|
|
: window.REST_ENDPOINT,
|
2022-11-04 06:04:31 -07:00
|
|
|
defaultLocale: 'en',
|
|
|
|
endpointWebhook: 'webhook',
|
|
|
|
endpointWebhookTest: 'webhook-test',
|
|
|
|
pushConnectionActive: true,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
executionTimeout: -1,
|
|
|
|
maxExecutionTimeout: Number.MAX_SAFE_INTEGER,
|
|
|
|
versionCli: '0.0.0',
|
|
|
|
oauthCallbackUrls: {},
|
|
|
|
n8nMetadata: {},
|
|
|
|
sessionId: Math.random().toString(36).substring(2, 15),
|
|
|
|
urlBaseWebhook: 'http://localhost:5678/',
|
|
|
|
urlBaseEditor: 'http://localhost:5678',
|
|
|
|
isNpmAvailable: false,
|
|
|
|
instanceId: '',
|
|
|
|
}),
|
|
|
|
getters: {
|
2022-11-23 07:20:28 -08:00
|
|
|
getBaseUrl(): string {
|
|
|
|
return this.baseUrl;
|
|
|
|
},
|
|
|
|
|
2022-11-04 06:04:31 -07:00
|
|
|
getWebhookUrl(): string {
|
|
|
|
return `${this.urlBaseWebhook}${this.endpointWebhook}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
getWebhookTestUrl(): string {
|
|
|
|
return `${this.urlBaseEditor}${this.endpointWebhookTest}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
getRestUrl(): string {
|
2023-04-06 02:35:05 -07:00
|
|
|
return `${this.baseUrl}${this.restEndpoint}`;
|
2022-11-04 06:04:31 -07:00
|
|
|
},
|
|
|
|
|
2023-05-15 14:16:13 -07:00
|
|
|
getRestCloudApiContext(): IRestApiContext {
|
|
|
|
return {
|
|
|
|
baseUrl: window.location.host.includes('stage-app.n8n.cloud')
|
|
|
|
? CLOUD_BASE_URL_STAGING
|
|
|
|
: CLOUD_BASE_URL_PRODUCTION,
|
|
|
|
sessionId: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2022-11-04 06:04:31 -07:00
|
|
|
getRestApiContext(): IRestApiContext {
|
|
|
|
return {
|
2023-04-06 02:35:05 -07:00
|
|
|
baseUrl: this.getRestUrl,
|
2022-11-04 06:04:31 -07:00
|
|
|
sessionId: this.sessionId,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Getter for node default names ending with a number: `'S3'`, `'Magento 2'`, etc.
|
|
|
|
*/
|
2022-12-14 01:04:10 -08:00
|
|
|
nativelyNumberSuffixedDefaults: (): string[] => {
|
2022-11-04 06:04:31 -07:00
|
|
|
return useNodeTypesStore().allNodeTypes.reduce<string[]>((acc, cur) => {
|
|
|
|
if (/\d$/.test(cur.defaults.name as string)) acc.push(cur.defaults.name as string);
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setUrlBaseWebhook(urlBaseWebhook: string): void {
|
|
|
|
const url = urlBaseWebhook.endsWith('/') ? urlBaseWebhook : `${urlBaseWebhook}/`;
|
|
|
|
Vue.set(this, 'urlBaseWebhook', url);
|
|
|
|
},
|
|
|
|
setUrlBaseEditor(urlBaseEditor: string): void {
|
|
|
|
const url = urlBaseEditor.endsWith('/') ? urlBaseEditor : `${urlBaseEditor}/`;
|
|
|
|
Vue.set(this, 'urlBaseEditor', url);
|
|
|
|
},
|
|
|
|
setEndpointWebhook(endpointWebhook: string): void {
|
|
|
|
Vue.set(this, 'endpointWebhook', endpointWebhook);
|
|
|
|
},
|
|
|
|
setEndpointWebhookTest(endpointWebhookTest: string): void {
|
|
|
|
Vue.set(this, 'endpointWebhookTest', endpointWebhookTest);
|
|
|
|
},
|
|
|
|
setTimezone(timezone: string): void {
|
|
|
|
Vue.set(this, 'timezone', timezone);
|
|
|
|
},
|
|
|
|
setExecutionTimeout(executionTimeout: number): void {
|
|
|
|
Vue.set(this, 'executionTimeout', executionTimeout);
|
|
|
|
},
|
|
|
|
setMaxExecutionTimeout(maxExecutionTimeout: number): void {
|
|
|
|
Vue.set(this, 'maxExecutionTimeout', maxExecutionTimeout);
|
|
|
|
},
|
|
|
|
setVersionCli(version: string): void {
|
|
|
|
Vue.set(this, 'versionCli', version);
|
|
|
|
},
|
|
|
|
setInstanceId(instanceId: string): void {
|
|
|
|
Vue.set(this, 'instanceId', instanceId);
|
|
|
|
},
|
|
|
|
setOauthCallbackUrls(urls: IDataObject): void {
|
|
|
|
Vue.set(this, 'oauthCallbackUrls', urls);
|
|
|
|
},
|
|
|
|
setN8nMetadata(metadata: IDataObject): void {
|
|
|
|
Vue.set(this, 'n8nMetadata', metadata);
|
|
|
|
},
|
|
|
|
setDefaultLocale(locale: string): void {
|
|
|
|
Vue.set(this, 'defaultLocale', locale);
|
|
|
|
},
|
|
|
|
setIsNpmAvailable(isNpmAvailable: boolean): void {
|
|
|
|
Vue.set(this, 'isNpmAvailable', isNpmAvailable);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|