@n8n/frontend-module-engine-v2 0.0.0-stage → 0.0.0-tp

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ import { defineFrontendModule } from '@n8n/frontend-module-sdk';
2
+
3
+ /**
4
+ * Keep this file import-light: types and the SDK only. Views load lazily
5
+ * (`const View = async () => await import('./views/X.vue')`), and stores are
6
+ * referenced inside route guards or handlers, never at module scope — a
7
+ * top-level store import pulls the whole module in even when it is disabled.
8
+ */
9
+ export const EngineV2Module = defineFrontendModule({
10
+ // Must match the backend module id: both gate off `/rest/module-settings`.
11
+ id: 'engine-v2',
12
+ name: 'Engine V2',
13
+ description: 'Checks if the open workflow can run on engine v2',
14
+ icon: 'cog',
15
+
16
+ // The shell reads the fields below. Uncomment what this module contributes.
17
+ //
18
+ // routes: [ /* RouteRecordRaw[]; components must be lazy */ ],
19
+ // projectTabs: { overview: [], project: [], shared: [] },
20
+ // resources: [ /* ResourceMetadata[]; feeds ResourcesListLayout */ ],
21
+ // modals: [ /* ModalDefinition[]; rendered by DynamicModalLoader */ ],
22
+ // adHocModalKeyPrefixes: [ /* prefixes for modal keys minted at runtime */ ],
23
+ // settingsPages: [ /* IMenuItem[]; feeds SettingsSidebar */ ],
24
+ // pushHandlers: { /* keyed by push message type */ },
25
+ // parameterInputs: [ /* ParameterInputContribution[]; resolved by parameter.type in the NDV */ ],
26
+ // commands: [ /* CommandBarEntry[] */ ],
27
+
28
+ // The SDK types the fields below, but no host in the shell reads them yet.
29
+ // A value here does nothing at runtime: locales, shortcuts, banners, setup,
30
+ // runDataDisplayModes.
31
+ });
@@ -0,0 +1,67 @@
1
+ import type { INode } from 'n8n-workflow';
2
+
3
+ import { engineV2Check } from './engineV2Check';
4
+
5
+ function node(type: string, overrides: Partial<INode> = {}): INode {
6
+ return {
7
+ id: `id-${type}`,
8
+ name: type.split('.').pop() ?? type,
9
+ type,
10
+ typeVersion: 1,
11
+ position: [0, 0],
12
+ parameters: {},
13
+ ...overrides,
14
+ };
15
+ }
16
+
17
+ describe('engineV2Check.checkWorkflow', () => {
18
+ it('reports an empty workflow as eligible', () => {
19
+ expect(engineV2Check.checkWorkflow({ nodes: [], connections: {}, settings: {} })).toEqual({
20
+ eligible: true,
21
+ reasons: [],
22
+ });
23
+ });
24
+
25
+ it('returns the reason of a workflow setting', () => {
26
+ const result = engineV2Check.checkWorkflow({
27
+ nodes: [],
28
+ connections: {},
29
+ settings: { errorWorkflow: 'wf-1' },
30
+ });
31
+
32
+ expect(result.eligible).toBe(false);
33
+ expect(result.reasons).toEqual([
34
+ expect.objectContaining({ code: 'ERROR_WORKFLOW', severity: 'blocking' }),
35
+ ]);
36
+ });
37
+
38
+ it('returns the reason of a node, with its name', () => {
39
+ const result = engineV2Check.checkWorkflow({
40
+ nodes: [node('n8n-nodes-base.formTrigger', { name: 'On form submission' })],
41
+ connections: {},
42
+ settings: {},
43
+ });
44
+
45
+ expect(result.reasons).toContainEqual(
46
+ expect.objectContaining({ code: 'FORM_NODE', nodeName: 'On form submission' }),
47
+ );
48
+ });
49
+ });
50
+
51
+ describe('engineV2Check.isNodeTypeSupported', () => {
52
+ it.each([
53
+ ['n8n-nodes-base.formTrigger', 'FORM_NODE'],
54
+ ['@n8n/n8n-nodes-langchain.agent', 'AI_NODE'],
55
+ ['n8n-nodes-base.kafkaTrigger', 'TRIGGER_WAITS_FOR_RUN'],
56
+ ['n8n-nodes-acme.example', 'COMMUNITY_NODE'],
57
+ ])('reports %s as unsupported (%s)', (type) => {
58
+ expect(engineV2Check.isNodeTypeSupported(type)).toBe(false);
59
+ });
60
+
61
+ it.each(['n8n-nodes-base.set', 'n8n-nodes-base.webhook', 'n8n-nodes-base.splitInBatches'])(
62
+ 'reports %s as supported',
63
+ (type) => {
64
+ expect(engineV2Check.isNodeTypeSupported(type)).toBe(true);
65
+ },
66
+ );
67
+ });
@@ -0,0 +1,34 @@
1
+ import {
2
+ checkEngineV2Eligibility,
3
+ isNodeTypeSupported,
4
+ type EngineV2Eligibility,
5
+ type EngineV2EligibilityWorkflow,
6
+ type EngineV2Reason,
7
+ type EngineV2ReasonCode,
8
+ type EngineV2ReasonKind,
9
+ } from '@n8n/workflow-engine-check';
10
+
11
+ /*
12
+ * The only file that imports `@n8n/workflow-engine-check`. The rest of the module uses the
13
+ * names below, so a change to the package contract changes this file only.
14
+ */
15
+
16
+ export type EngineCompatibilityWorkflow = EngineV2EligibilityWorkflow;
17
+ export type EngineCompatibilityReason = EngineV2Reason;
18
+ export type EngineCompatibility = EngineV2Eligibility;
19
+ export type EngineCompatibilityReasonCode = EngineV2ReasonCode;
20
+ export type EngineCompatibilityReasonKind = EngineV2ReasonKind;
21
+
22
+ /**
23
+ * The module calls the check through this object, so that tests can replace a method with
24
+ * `mockEngineV2Compatibility` from `./__tests__/mocks`.
25
+ */
26
+ export const engineV2Check = {
27
+ checkWorkflow(workflow: EngineCompatibilityWorkflow): EngineCompatibility {
28
+ return checkEngineV2Eligibility(workflow);
29
+ },
30
+
31
+ isNodeTypeSupported(nodeTypeName: string): boolean {
32
+ return isNodeTypeSupported(nodeTypeName);
33
+ },
34
+ };
@@ -0,0 +1,106 @@
1
+ import { useI18n, type BaseTextKey } from '@n8n/i18n';
2
+
3
+ import type {
4
+ EngineCompatibilityReason,
5
+ EngineCompatibilityReasonCode,
6
+ EngineCompatibilityReasonKind,
7
+ } from './engineV2Check';
8
+
9
+ /**
10
+ * The editor's own text for a code: one key, one key for each `kind` when the code has more
11
+ * than one meaning, or `null` to show the package's `message`. Use `null` when the `message`
12
+ * carries details that a fixed text can't hold, such as a second node name or a count.
13
+ */
14
+ type ReasonText = BaseTextKey | Partial<Record<EngineCompatibilityReasonKind, BaseTextKey>> | null;
15
+
16
+ /**
17
+ * Every code of the package has an entry, so the typecheck fails when the package adds a code.
18
+ * A text says what the package's `message` says, without the node name, which the dialog
19
+ * shows, and without the engine v1 advice, which `describeCompatibilityReason` adds. When a
20
+ * package rule changes what its `message` says, change the text in the same PR, or use `null`.
21
+ */
22
+ const REASON_TEXT_KEYS: Record<EngineCompatibilityReasonCode, ReasonText> = {
23
+ ERROR_WORKFLOW: 'engineV2Compatibility.reason.errorWorkflow',
24
+ REDACTION_POLICY: 'engineV2Compatibility.reason.redactionPolicy',
25
+ END_USER_CREDENTIALS: 'engineV2Compatibility.reason.endUserCredentials',
26
+ TRIGGER_EXTERNAL_IDENTITY: 'engineV2Compatibility.reason.triggerExternalIdentity',
27
+
28
+ AI_NODE: 'engineV2Compatibility.reason.aiNode',
29
+ COMMUNITY_NODE: 'engineV2Compatibility.reason.communityNode',
30
+ CHAT_NODE: 'engineV2Compatibility.reason.unsupportedNode',
31
+ EVALUATION_NODE: 'engineV2Compatibility.reason.unsupportedNode',
32
+ EXECUTION_DATA_NODE: 'engineV2Compatibility.reason.unsupportedNode',
33
+ FORM_NODE: 'engineV2Compatibility.reason.unsupportedNode',
34
+ MCP_SERVER_TRIGGER: 'engineV2Compatibility.reason.unsupportedNode',
35
+ MESSAGE_AN_AGENT_NODE: 'engineV2Compatibility.reason.unsupportedNode',
36
+ MICROSOFT_AGENT365_TRIGGER: 'engineV2Compatibility.reason.unsupportedNode',
37
+ TIME_SAVED_NODE: 'engineV2Compatibility.reason.unsupportedNode',
38
+ TRIGGER_WAITS_FOR_RUN: 'engineV2Compatibility.reason.unsupportedNode',
39
+
40
+ CONTINUE_ERROR_OUTPUT: 'engineV2Compatibility.reason.continueErrorOutput',
41
+ RETRY_ON_FAIL: 'engineV2Compatibility.reason.retryOnFail',
42
+ ALWAYS_OUTPUT_DATA: 'engineV2Compatibility.reason.alwaysOutputData',
43
+ EXECUTE_ONCE: 'engineV2Compatibility.reason.executeOnce',
44
+ MERGE_CHOOSE_BRANCH: 'engineV2Compatibility.reason.mergeChooseBranch',
45
+ MERGE_MODE_EXPRESSION: 'engineV2Compatibility.reason.mergeModeExpression',
46
+ SPLIT_IN_BATCHES_VERSION: null,
47
+ SPLIT_IN_BATCHES_OPTIONS_EXPRESSION:
48
+ 'engineV2Compatibility.reason.splitInBatchesOptionsExpression',
49
+ SPLIT_IN_BATCHES_RESET: 'engineV2Compatibility.reason.splitInBatchesReset',
50
+ SPLIT_IN_BATCHES_BATCH_SIZE: {
51
+ permanent: 'engineV2Compatibility.reason.splitInBatchesBatchSize.expression',
52
+ invalid: 'engineV2Compatibility.reason.splitInBatchesBatchSize.invalid',
53
+ },
54
+ NON_MAIN_CONNECTION: null,
55
+ SUB_WORKFLOW_FOR_EACH_ITEM: 'engineV2Compatibility.reason.subWorkflowForEachItem',
56
+ SUB_WORKFLOW_NOT_IN_DATABASE: 'engineV2Compatibility.reason.subWorkflowNotInDatabase',
57
+
58
+ CYCLE_WITHOUT_SPLIT_IN_BATCHES: 'engineV2Compatibility.reason.cycleWithoutSplitInBatches',
59
+ LOOP_ENTERED_MID_BODY: 'engineV2Compatibility.reason.loopEnteredMidBody',
60
+ LOOP_MULTIPLE_ENTRIES: null,
61
+ LOOP_MULTIPLE_RETURNS: null,
62
+ NESTED_LOOP: null,
63
+ LOOP_EXITS_MID_BODY: null,
64
+ INPUT_SLOT_CONVERGENCE: null,
65
+ NODE_REACHED_ONLY_THROUGH_DISABLED_NODE:
66
+ 'engineV2Compatibility.reason.nodeReachedOnlyThroughDisabledNode',
67
+ LOOP_DONE_OUTPUT_FEEDS_BODY: 'engineV2Compatibility.reason.loopDoneOutputFeedsBody',
68
+ LOOP_INPUT_NOT_FIRST: 'engineV2Compatibility.reason.loopInputNotFirst',
69
+ LOOP_OUTPUT_NOT_DONE_OR_LOOP: 'engineV2Compatibility.reason.loopOutputNotDoneOrLoop',
70
+ LOOP_WITHOUT_RETURN: 'engineV2Compatibility.reason.loopWithoutReturn',
71
+ };
72
+
73
+ function textKey({ code, kind }: EngineCompatibilityReason): BaseTextKey | undefined {
74
+ // `?? null` covers a code from a newer package than this map knows.
75
+ const text = REASON_TEXT_KEYS[code] ?? null;
76
+ if (text === null) return undefined;
77
+ return typeof text === 'string' ? text : text[kind];
78
+ }
79
+
80
+ /**
81
+ * The text of one reason, and the node name to show before it. A reason shown with the
82
+ * package's `message` gets no node name when the `message` already names the node.
83
+ */
84
+ export function describeCompatibilityReason(reason: EngineCompatibilityReason): {
85
+ nodeName?: string;
86
+ text: string;
87
+ } {
88
+ const key = textKey(reason);
89
+ // The package's `message` already ends with the engine v1 advice for a temporary reason.
90
+ if (!key) {
91
+ const { nodeName, message } = reason;
92
+ return nodeName && !message.includes(`"${nodeName}"`)
93
+ ? { nodeName, text: message }
94
+ : { text: message };
95
+ }
96
+
97
+ const i18n = useI18n();
98
+ const text = i18n.baseText(key);
99
+ return {
100
+ nodeName: reason.nodeName,
101
+ text:
102
+ reason.kind === 'temporary'
103
+ ? `${text} ${i18n.baseText('engineV2Compatibility.kind.temporary')}`
104
+ : text,
105
+ };
106
+ }
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ // The module's only public entry. The shell imports the descriptor from here via
2
+ // `modules.manifest.ts`; anything else the shell (or a test) needs must be exported
3
+ // here too — deep paths into `src/` are not part of the contract.
4
+ export { EngineV2Module } from './engine-v2.module';
5
+ export type { EngineCompatibilityReason } from './engineV2Check';
6
+ export {
7
+ describeEngineV2Block,
8
+ useEngineV2Compatibility,
9
+ type EngineV2CompatibilityWorkflowSource,
10
+ } from './composables/useEngineV2Compatibility';
11
+ export { default as EngineV2CompatibilityButton } from './components/EngineV2CompatibilityButton.vue';
@@ -0,0 +1,9 @@
1
+ import { baseConfig } from '@n8n/stylelint-config/base';
2
+
3
+ export default {
4
+ ...baseConfig,
5
+ rules: {
6
+ ...baseConfig.rules,
7
+ '@n8n/css-var-naming': [true, { severity: 'error' }],
8
+ },
9
+ };
package/vite.config.ts ADDED
@@ -0,0 +1,52 @@
1
+ import vue from '@vitejs/plugin-vue';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { resolve } from 'node:path';
4
+ import icons from 'unplugin-icons/vite';
5
+ import svgLoader from 'vite-svg-loader';
6
+ import { defineConfig, mergeConfig } from 'vite';
7
+ import { frontendAliases } from '@n8n/frontend-vite-config';
8
+ import { vitestConfig } from '@n8n/vitest-config/frontend';
9
+
10
+ const packageDir = fileURLToPath(new URL('.', import.meta.url));
11
+ const packagesDir = resolve(packageDir, '..', '..', '..');
12
+
13
+ export default mergeConfig(
14
+ defineConfig({
15
+ // `@n8n/design-system`'s icon set reaches for two things Vite does not handle on its
16
+ // own: `~icons/lucide/*` virtual modules and `./custom/*.svg` single-file components.
17
+ // Consuming design-system from source makes both the consumer's problem — without
18
+ // `svgLoader` an `.svg` import returns a data-URI string, which Vue then renders as a
19
+ // tag name and jsdom rejects. Every module that renders a design-system component
20
+ // needs these two plugins. `src/__tests__/design-system-icons.test.ts` guards them.
21
+ plugins: [
22
+ vue(),
23
+ // Off, so a test never reaches the network for a missing collection. The collection
24
+ // comes from the `@iconify/json` devDependency instead.
25
+ icons({ compiler: 'vue3', autoInstall: false }),
26
+ svgLoader({
27
+ svgoConfig: {
28
+ plugins: [
29
+ {
30
+ name: 'preset-default',
31
+ params: {
32
+ overrides: {
33
+ // The icons rely on their ids, and on a viewBox to stay scalable.
34
+ cleanupIds: false,
35
+ removeViewBox: false,
36
+ },
37
+ },
38
+ },
39
+ ],
40
+ },
41
+ }),
42
+ ],
43
+ resolve: {
44
+ // The same platform mapping the editor-ui dev server uses, so a test resolves
45
+ // `@n8n/stores/...` from source rather than from a stale `dist` — the two disagreeing is
46
+ // what put 1,111 specifiers on the wrong side of the src/dist line. Sibling modules are
47
+ // deliberately absent: nothing here should make a cross-module import resolve.
48
+ alias: frontendAliases(packagesDir),
49
+ },
50
+ }),
51
+ vitestConfig,
52
+ );
@@ -0,0 +1,3 @@
1
+ import { vizeConfig } from '@n8n/oxlint-config/vize';
2
+
3
+ export default vizeConfig();