refactor(editor): Add usage state schema and refactor usage APIs (no-changelog) (#20355)

This commit is contained in:
Alex Grozav 2025-10-03 16:32:26 +03:00 committed by GitHub
parent da08b7833c
commit 1b6ecb1fb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 29 deletions

View File

@ -74,3 +74,5 @@ export type {
ExternalSecretsProviderProperty,
ExternalSecretsProviderState,
} from './schemas/external-secrets.schema';
export type { UsageState } from './schemas/usage.schema';

View File

@ -0,0 +1,25 @@
import { z } from 'zod';
export const usageStateSchema = z.object({
loading: z.boolean(),
data: z.object({
usage: z.object({
activeWorkflowTriggers: z.object({
limit: z.number(), // -1 for unlimited, from license
value: z.number(),
warningThreshold: z.number(),
}),
workflowsHavingEvaluations: z.object({
limit: z.number(), // -1 for unlimited, from license
value: z.number(),
}),
}),
license: z.object({
planId: z.string(), // community
planName: z.string(), // defaults to Community
}),
managementToken: z.string().optional(),
}),
});
export type UsageState = z.infer<typeof usageStateSchema>;

View File

@ -19,6 +19,7 @@ export type * from './tags';
export * from './templates';
export * from './third-party-licenses';
export * from './ui';
export * from './usage';
export * from './users';
export * from './versions';
export * from './webhooks';

View File

@ -1,7 +1,7 @@
import type { CommunityRegisteredRequestDto } from '@n8n/api-types';
import { makeRestApiRequest } from '@n8n/rest-api-client';
import type { UsageState } from '@/Interface';
import type { IRestApiContext } from '@n8n/rest-api-client';
import type { CommunityRegisteredRequestDto, UsageState } from '@n8n/api-types';
import type { IRestApiContext } from '../types';
import { makeRestApiRequest } from '../utils';
export const getLicense = async (context: IRestApiContext): Promise<UsageState['data']> => {
return await makeRestApiRequest(context, 'GET', '/license');

View File

@ -1008,28 +1008,6 @@ export type SchemaType =
export type Schema = { type: SchemaType; key?: string; value: string | Schema[]; path: string };
export type UsageState = {
loading: boolean;
data: {
usage: {
activeWorkflowTriggers: {
limit: number; // -1 for unlimited, from license
value: number;
warningThreshold: number; // hardcoded value in BE
};
workflowsHavingEvaluations: {
limit: number; // -1 for unlimited, from license
value: number;
};
};
license: {
planId: string; // community
planName: string; // defaults to Community
};
managementToken?: string;
};
};
export type NodeAuthenticationOption = {
name: string;
value: string;

View File

@ -1,7 +1,7 @@
import { computed, reactive } from 'vue';
import { defineStore } from 'pinia';
import type { UsageState } from '@/Interface';
import * as usageApi from '@/api/usage';
import type { UsageState } from '@n8n/api-types';
import * as usageApi from '@n8n/rest-api-client/api/usage';
import { useRootStore } from '@n8n/stores/useRootStore';
import { useSettingsStore } from '@/stores/settings.store';

View File

@ -70,7 +70,7 @@ const router = createRouter({
],
});
vi.mock('@/api/usage', () => ({
vi.mock('@n8n/rest-api-client/api/usage', () => ({
getLicense: vi.fn(),
}));