diff --git a/packages/frontend/@n8n/rest-api-client/src/api/cloudPlans.ts b/packages/frontend/@n8n/rest-api-client/src/api/cloudPlans.ts new file mode 100644 index 0000000000..cbe55cdff8 --- /dev/null +++ b/packages/frontend/@n8n/rest-api-client/src/api/cloudPlans.ts @@ -0,0 +1,61 @@ +import type { IRestApiContext } from '../types'; +import { get, post } from '../utils'; + +export declare namespace Cloud { + export interface PlanData { + planId: number; + monthlyExecutionsLimit: number; + activeWorkflowsLimit: number; + credentialsLimit: number; + isActive: boolean; + displayName: string; + expirationDate: string; + metadata: PlanMetadata; + } + + export interface PlanMetadata { + version: 'v1'; + group: 'opt-out' | 'opt-in' | 'trial'; + slug: 'pro-1' | 'pro-2' | 'starter' | 'trial-1'; + trial?: Trial; + } + + interface Trial { + length: number; + gracePeriod: number; + } + + export type UserAccount = { + confirmed: boolean; + username: string; + email: string; + hasEarlyAccess?: boolean; + role?: string; + }; +} + +export interface InstanceUsage { + timeframe?: string; + executions: number; + activeWorkflows: number; +} + +export async function getCurrentPlan(context: IRestApiContext): Promise { + return await get(context.baseUrl, '/admin/cloud-plan'); +} + +export async function getCurrentUsage(context: IRestApiContext): Promise { + return await get(context.baseUrl, '/cloud/limits'); +} + +export async function getCloudUserInfo(context: IRestApiContext): Promise { + return await get(context.baseUrl, '/cloud/proxy/user/me'); +} + +export async function sendConfirmationEmail(context: IRestApiContext): Promise { + return await post(context.baseUrl, '/cloud/proxy/user/resend-confirmation-email'); +} + +export async function getAdminPanelLoginCode(context: IRestApiContext): Promise<{ code: string }> { + return await get(context.baseUrl, '/cloud/proxy/login/code'); +} diff --git a/packages/frontend/@n8n/rest-api-client/src/api/index.ts b/packages/frontend/@n8n/rest-api-client/src/api/index.ts index 30190ab166..a361ca3b8e 100644 --- a/packages/frontend/@n8n/rest-api-client/src/api/index.ts +++ b/packages/frontend/@n8n/rest-api-client/src/api/index.ts @@ -1,4 +1,5 @@ export * from './api-keys'; +export * from './cloudPlans'; export * from './communityNodes'; export * from './ctas'; export * from './eventbus.ee'; diff --git a/packages/frontend/editor-ui/src/Interface.ts b/packages/frontend/editor-ui/src/Interface.ts index accb818cd8..a6591d4236 100644 --- a/packages/frontend/editor-ui/src/Interface.ts +++ b/packages/frontend/editor-ui/src/Interface.ts @@ -46,6 +46,7 @@ import type { ISourceData, } from 'n8n-workflow'; import type { Version, VersionNode } from '@n8n/rest-api-client/api/versions'; +import type { Cloud, InstanceUsage } from '@n8n/rest-api-client/api/cloudPlans'; import type { AI_NODE_CREATOR_VIEW, @@ -1300,39 +1301,6 @@ export type ExecutionsQueryFilter = { vote?: ExecutionFilterVote; }; -export declare namespace Cloud { - export interface PlanData { - planId: number; - monthlyExecutionsLimit: number; - activeWorkflowsLimit: number; - credentialsLimit: number; - isActive: boolean; - displayName: string; - expirationDate: string; - metadata: PlanMetadata; - } - - export interface PlanMetadata { - version: 'v1'; - group: 'opt-out' | 'opt-in' | 'trial'; - slug: 'pro-1' | 'pro-2' | 'starter' | 'trial-1'; - trial?: Trial; - } - - interface Trial { - length: number; - gracePeriod: number; - } - - export type UserAccount = { - confirmed: boolean; - username: string; - email: string; - hasEarlyAccess?: boolean; - role?: string; - }; -} - export interface CloudPlanState { initialized: boolean; data: Cloud.PlanData | null; @@ -1340,12 +1308,6 @@ export interface CloudPlanState { loadingPlan: boolean; } -export interface InstanceUsage { - timeframe?: string; - executions: number; - activeWorkflows: number; -} - export type CloudPlanAndUsageData = Cloud.PlanData & { usage: InstanceUsage }; export interface ExternalSecretsProviderSecret { diff --git a/packages/frontend/editor-ui/src/api/cloudPlans.ts b/packages/frontend/editor-ui/src/api/cloudPlans.ts deleted file mode 100644 index a7eabed0f0..0000000000 --- a/packages/frontend/editor-ui/src/api/cloudPlans.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { Cloud, InstanceUsage } from '@/Interface'; -import type { IRestApiContext } from '@n8n/rest-api-client'; -import { get, post } from '@n8n/rest-api-client'; - -export async function getCurrentPlan(context: IRestApiContext): Promise { - return await get(context.baseUrl, '/admin/cloud-plan'); -} - -export async function getCurrentUsage(context: IRestApiContext): Promise { - return await get(context.baseUrl, '/cloud/limits'); -} - -export async function getCloudUserInfo(context: IRestApiContext): Promise { - return await get(context.baseUrl, '/cloud/proxy/user/me'); -} - -export async function sendConfirmationEmail(context: IRestApiContext): Promise { - return await post(context.baseUrl, '/cloud/proxy/user/resend-confirmation-email'); -} - -export async function getAdminPanelLoginCode(context: IRestApiContext): Promise<{ code: string }> { - return await get(context.baseUrl, '/cloud/proxy/login/code'); -} diff --git a/packages/frontend/editor-ui/src/composables/usePageRedirectionHelper.test.ts b/packages/frontend/editor-ui/src/composables/usePageRedirectionHelper.test.ts index ed23b24761..76b04accc9 100644 --- a/packages/frontend/editor-ui/src/composables/usePageRedirectionHelper.test.ts +++ b/packages/frontend/editor-ui/src/composables/usePageRedirectionHelper.test.ts @@ -5,7 +5,7 @@ import { usePageRedirectionHelper } from './usePageRedirectionHelper'; import { defaultSettings } from '@/__tests__/defaults'; import { useUsersStore } from '@/stores/users.store'; import { createPinia, setActivePinia } from 'pinia'; -import * as cloudPlanApi from '@/api/cloudPlans'; +import * as cloudPlanApi from '@n8n/rest-api-client/api/cloudPlans'; import { useVersionsStore } from '@/stores/versions.store'; import { useTelemetry } from './useTelemetry'; diff --git a/packages/frontend/editor-ui/src/stores/__tests__/utils/cloudStoreUtils.ts b/packages/frontend/editor-ui/src/stores/__tests__/utils/cloudStoreUtils.ts index a74e7db78e..044f9595be 100644 --- a/packages/frontend/editor-ui/src/stores/__tests__/utils/cloudStoreUtils.ts +++ b/packages/frontend/editor-ui/src/stores/__tests__/utils/cloudStoreUtils.ts @@ -1,4 +1,4 @@ -import type { Cloud } from '@/Interface'; +import type { Cloud } from '@n8n/rest-api-client/api/cloudPlans'; // Mocks cloud plan API responses with different trial expiration dates function getUserPlanData(trialExpirationDate: Date, isTrial = true): Cloud.PlanData { diff --git a/packages/frontend/editor-ui/src/stores/cloudPlan.store.ts b/packages/frontend/editor-ui/src/stores/cloudPlan.store.ts index f67b099d79..62131278a7 100644 --- a/packages/frontend/editor-ui/src/stores/cloudPlan.store.ts +++ b/packages/frontend/editor-ui/src/stores/cloudPlan.store.ts @@ -5,7 +5,11 @@ import { useRootStore } from '@n8n/stores/useRootStore'; import { useSettingsStore } from '@/stores/settings.store'; import { useUIStore } from '@/stores/ui.store'; import { useUsersStore } from '@/stores/users.store'; -import { getAdminPanelLoginCode, getCurrentPlan, getCurrentUsage } from '@/api/cloudPlans'; +import { + getAdminPanelLoginCode, + getCurrentPlan, + getCurrentUsage, +} from '@n8n/rest-api-client/api/cloudPlans'; import { DateTime } from 'luxon'; import { CLOUD_TRIAL_CHECK_INTERVAL } from '@/constants'; import { STORES } from '@n8n/stores'; diff --git a/packages/frontend/editor-ui/src/stores/ui.test.ts b/packages/frontend/editor-ui/src/stores/ui.test.ts index 5c24638372..e8b9878de3 100644 --- a/packages/frontend/editor-ui/src/stores/ui.test.ts +++ b/packages/frontend/editor-ui/src/stores/ui.test.ts @@ -4,7 +4,7 @@ import { useSettingsStore } from '@/stores/settings.store'; import { useUsersStore } from '@/stores/users.store'; import merge from 'lodash/merge'; import { useCloudPlanStore } from '@/stores/cloudPlan.store'; -import * as cloudPlanApi from '@/api/cloudPlans'; +import * as cloudPlanApi from '@n8n/rest-api-client/api/cloudPlans'; import { defaultSettings } from '../__tests__/defaults'; import { getTrialExpiredUserResponse, diff --git a/packages/frontend/editor-ui/src/stores/users.store.ts b/packages/frontend/editor-ui/src/stores/users.store.ts index 08758d330c..168b55a30d 100644 --- a/packages/frontend/editor-ui/src/stores/users.store.ts +++ b/packages/frontend/editor-ui/src/stores/users.store.ts @@ -10,13 +10,13 @@ import { BROWSER_ID_STORAGE_KEY } from '@n8n/constants'; import { PERSONALIZATION_MODAL_KEY, ROLE } from '@/constants'; import { STORES } from '@n8n/stores'; import type { - Cloud, IPersonalizationLatestVersion, IUser, IUserResponse, CurrentUserResponse, InvitableRoleName, } from '@/Interface'; +import type { Cloud } from '@n8n/rest-api-client/api/cloudPlans'; import { getPersonalizedNodeTypes } from '@/utils/userUtils'; import { defineStore } from 'pinia'; import { useRootStore } from '@n8n/stores/useRootStore'; @@ -24,7 +24,7 @@ import { usePostHog } from './posthog.store'; import { useUIStore } from './ui.store'; import { useCloudPlanStore } from './cloudPlan.store'; import * as mfaApi from '@n8n/rest-api-client/api/mfa'; -import * as cloudApi from '@/api/cloudPlans'; +import * as cloudApi from '@n8n/rest-api-client/api/cloudPlans'; import { useRBACStore } from '@/stores/rbac.store'; import type { Scope } from '@n8n/permissions'; import * as invitationsApi from '@/api/invitation';