n8n/packages/editor-ui/src/stores/n8nRoot.store.ts
Ricardo Espinoza cd7c312fbd
feat(editor): Add cloud ExecutionsUsage and API blocking using licenses (#6159)
* Add ExecutionsUsage component

* set $sidebar-expanded-width back to 200px

* add days using interpolation

* Rename PlanData type to CloudPlanData

* Rename Metadata type to PlanMetadata

* Make prop block in the update button

* Use variable in line-height

* Remove progressBarSection class

* fix trial expiration calculation

* mock expirationDate and fix issue with days left

* Remove unnecesary property from class .container

* inject component data via props

* Check for plan data during app mounting and keep data in the store

* Remove mounted hook

* redirect when upgrade plan is clicked

* Remove computed properties

* Remove instance property as it's not needed anymore

* Flatten plan object

* remove console.log

* Add all cloud types within its own namespace

* keep redirection inside component

* get computed properties back

* Improve polling logic

* Move cloudData to its own store

* Remove commented interfaces

* remove cloudPlan from user store

* fix imports

* update logic for userIsTrialing method

* centralize userIsTrialing method

* redirect to production change plan page always

* Call staging or production cloud api depending on base URL

* remove setting store form ExecutionUsage.vue

* fix linting issue

* Add trial group to PlanMetadata group

* Move helpers into the store

* make staging url check more specific

* make cloud state nullable

* fix linting issue

* swap mockup date for endpoint

* Make getCurrentPlan async

* asas

* Improvements

* small improvements

* chore: resolve conflicts

* make sure there is data before calculating trial expiration

* Fix issue with component not loading on first page load

* type safety improvements

* apply component ui feedback

* fix linting issue

* chore: clean up unnecessary change from merge conflict

* feat: Block api feature using licenses, show notice page for trial cloud users (#6187)

* rename planSpec to plan

* Remove instance property as it's not needed anymore

* Flatten plan object

* remove console.log

* feat: disable api using license

* feat: add api page

* chore: resolve conflicts

* chore: resolve conflicts

* feat: update and refactor a bit

* fix: update endpoints

* fix: update endpoints

* fix: use host

* feat: update copy

* fix linting issues

---------

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>

* add pluralization to days left text

---------

Co-authored-by: Mutasem <mutdmour@gmail.com>
Co-authored-by: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com>
2023-05-15 17:16:13 -04:00

120 lines
3.6 KiB
TypeScript

import { CLOUD_BASE_URL_PRODUCTION, CLOUD_BASE_URL_STAGING, STORES } from '@/constants';
import type { IRestApiContext, RootState } from '@/Interface';
import type { IDataObject } from 'n8n-workflow';
import { defineStore } from 'pinia';
import Vue from 'vue';
import { useNodeTypesStore } from './nodeTypes.store';
const { VUE_APP_URL_BASE_API } = import.meta.env;
export const useRootStore = defineStore(STORES.ROOT, {
state: (): RootState => ({
baseUrl:
VUE_APP_URL_BASE_API ?? (window.BASE_PATH === '/{{BASE_PATH}}/' ? '/' : window.BASE_PATH),
restEndpoint:
!window.REST_ENDPOINT || window.REST_ENDPOINT === '{{REST_ENDPOINT}}'
? 'rest'
: window.REST_ENDPOINT,
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: {
getBaseUrl(): string {
return this.baseUrl;
},
getWebhookUrl(): string {
return `${this.urlBaseWebhook}${this.endpointWebhook}`;
},
getWebhookTestUrl(): string {
return `${this.urlBaseEditor}${this.endpointWebhookTest}`;
},
getRestUrl(): string {
return `${this.baseUrl}${this.restEndpoint}`;
},
getRestCloudApiContext(): IRestApiContext {
return {
baseUrl: window.location.host.includes('stage-app.n8n.cloud')
? CLOUD_BASE_URL_STAGING
: CLOUD_BASE_URL_PRODUCTION,
sessionId: '',
};
},
getRestApiContext(): IRestApiContext {
return {
baseUrl: this.getRestUrl,
sessionId: this.sessionId,
};
},
/**
* Getter for node default names ending with a number: `'S3'`, `'Magento 2'`, etc.
*/
nativelyNumberSuffixedDefaults: (): string[] => {
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);
},
},
});