@n8n/frontend-module-instance-registry 0.1.0

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.
package/LICENSE.md ADDED
@@ -0,0 +1,88 @@
1
+ # License
2
+
3
+ Portions of this software are licensed as follows:
4
+
5
+ - Content of branches other than the main branch (i.e. "master") are not licensed.
6
+ - Source code files that contain ".ee." in their filename or ".ee" in their dirname are NOT licensed under
7
+ the Sustainable Use License.
8
+ To use source code files that contain ".ee." in their filename or ".ee" in their dirname you must hold a
9
+ valid n8n Enterprise License specifically allowing you access to such source code files and as defined
10
+ in "LICENSE_EE.md".
11
+ - All third party components incorporated into the n8n Software are licensed under the original license
12
+ provided by the owner of the applicable component.
13
+ - Content outside of the above mentioned files or restrictions is available under the "Sustainable Use
14
+ License" as defined below.
15
+
16
+ ## Sustainable Use License
17
+
18
+ Version 1.0
19
+
20
+ ### Acceptance
21
+
22
+ By using the software, you agree to all of the terms and conditions below.
23
+
24
+ ### Copyright License
25
+
26
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license
27
+ to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject
28
+ to the limitations below.
29
+
30
+ ### Limitations
31
+
32
+ You may use or modify the software only for your own internal business purposes or for non-commercial or
33
+ personal use. You may distribute the software or provide it to others only if you do so free of charge for
34
+ non-commercial purposes. You may not alter, remove, or obscure any licensing, copyright, or other notices of
35
+ the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
36
+
37
+ ### Patents
38
+
39
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to
40
+ license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case
41
+ subject to the limitations and conditions in this license. This license does not cover any patent claims that
42
+ you cause to be infringed by modifications or additions to the software. If you or your company make any
43
+ written claim that the software infringes or contributes to infringement of any patent, your patent license
44
+ for the software granted under these terms ends immediately. If your company makes such a claim, your patent
45
+ license ends immediately for work on behalf of your company.
46
+
47
+ ### Notices
48
+
49
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these
50
+ terms. If you modify the software, you must include in any modified copies of the software a prominent notice
51
+ stating that you have modified the software.
52
+
53
+ ### No Other Rights
54
+
55
+ These terms do not imply any licenses other than those expressly granted in these terms.
56
+
57
+ ### Termination
58
+
59
+ If you use the software in violation of these terms, such use is not licensed, and your license will
60
+ automatically terminate. If the licensor provides you with a notice of your violation, and you cease all
61
+ violation of this license no later than 30 days after you receive that notice, your license will be reinstated
62
+ retroactively. However, if you violate these terms after such reinstatement, any additional violation of these
63
+ terms will cause your license to terminate automatically and permanently.
64
+
65
+ ### No Liability
66
+
67
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will
68
+ not be liable to you for any damages arising out of these terms or the use or nature of the software, under
69
+ any kind of legal claim.
70
+
71
+ ### Definitions
72
+
73
+ The “licensor” is the entity offering these terms.
74
+
75
+ The “software” is the software the licensor makes available under these terms, including any portion of it.
76
+
77
+ “You” refers to the individual or entity agreeing to these terms.
78
+
79
+ “Your company” is any legal entity, sole proprietorship, or other kind of organization that you work for, plus
80
+ all organizations that have control over, are under the control of, or are under common control with that
81
+ organization. Control means ownership of substantially all the assets of an entity, or the power to direct its
82
+ management and policies by vote, contract, or otherwise. Control can be direct or indirect.
83
+
84
+ “Your license” is the license granted to you for the software under these terms.
85
+
86
+ “Use” means anything you do with the software requiring your license.
87
+
88
+ “Trademark” means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @n8n/frontend-module-instance-registry
2
+
3
+ Frontend feature module. Consumed from source by the editor-ui shell through
4
+ `src/app/modules.manifest.ts`; there is no build step and no `dist`.
5
+
6
+ ```bash
7
+ pnpm turbo typecheck --filter=@n8n/frontend-module-instance-registry
8
+ pnpm turbo lint --filter=@n8n/frontend-module-instance-registry
9
+ pnpm turbo test --filter=@n8n/frontend-module-instance-registry
10
+ ```
11
+
12
+ Go through turbo, not `pnpm --filter <pkg> typecheck`: this package is consumed
13
+ from source, and on a cold tree its platform dependencies have not been built
14
+ yet. Turbo builds them first; the bare pnpm form does not.
15
+
16
+ ## Import rules
17
+
18
+ - Depend on foundation and platform packages only (`@n8n/design-system`,
19
+ `@n8n/stores`, `@n8n/composables`, `@n8n/i18n`, `@n8n/rest-api-client`,
20
+ `@n8n/api-types`, `@n8n/frontend-module-sdk`). Never import another
21
+ `@n8n/frontend-module-*`, and never import `@/…` from the shell.
22
+ - `@n8n/stores` and `@n8n/composables` are **subpath-only** — import
23
+ `@n8n/stores/settings.store`, not `@n8n/stores`.
24
+ - The no-cross-module rule is currently a convention: the shared tsconfig base
25
+ omits sibling modules from `paths`, which blocks an accidental import but not
26
+ a deliberate one (declaring the dependency makes it typecheck clean). The
27
+ ESLint rule that actually enforces it is CAT-3692.
package/biome.jsonc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "../../../../node_modules/@biomejs/biome/configuration_schema.json",
3
+ "extends": ["../../../../biome.jsonc"]
4
+ }
@@ -0,0 +1,4 @@
1
+ import { defineConfig } from 'eslint/config';
2
+ import { frontendConfig } from '@n8n/eslint-config/frontend';
3
+
4
+ export default defineConfig(frontendConfig);
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@n8n/frontend-module-instance-registry",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "src/index.ts",
6
+ "exports": {
7
+ ".": "./src/index.ts"
8
+ },
9
+ "dependencies": {
10
+ "pinia": "^2.2.4",
11
+ "vue": "^3.5.13",
12
+ "vue-router": "^4.5.0",
13
+ "@n8n/api-types": "1.36.0",
14
+ "@n8n/composables": "1.26.0",
15
+ "@n8n/frontend-module-sdk": "0.6.0",
16
+ "@n8n/i18n": "2.36.0",
17
+ "@n8n/permissions": "0.73.0",
18
+ "@n8n/design-system": "2.35.0",
19
+ "@n8n/rest-api-client": "2.36.0",
20
+ "@n8n/stores": "2.36.0",
21
+ "n8n-workflow": "2.36.0"
22
+ },
23
+ "devDependencies": {
24
+ "@testing-library/jest-dom": "^6.6.3",
25
+ "@testing-library/vue": "^8.1.0",
26
+ "@vitejs/plugin-vue": "^5.2.4",
27
+ "eslint": "9.29.0",
28
+ "typescript": "6.0.2",
29
+ "unplugin-icons": "^23.0.1",
30
+ "vite": "^8.0.2",
31
+ "vitest": "^4.1.9",
32
+ "vue-tsc": "^2.2.8",
33
+ "@n8n/eslint-config": "0.0.1",
34
+ "@n8n/frontend-vite-config": "0.1.0",
35
+ "@n8n/playwright-janitor": "0.1.0",
36
+ "@n8n/typescript-config": "1.10.0",
37
+ "@n8n/vitest-config": "1.21.0"
38
+ },
39
+ "license": "LicenseRef-n8n-sustainable-use",
40
+ "scripts": {
41
+ "clean": "rimraf .turbo",
42
+ "typecheck": "vue-tsc --noEmit",
43
+ "test": "vitest run",
44
+ "test:changed": "janitor test-scoped",
45
+ "test:dev": "vitest",
46
+ "lint": "eslint src --quiet",
47
+ "lint:fix": "eslint src --fix",
48
+ "format": "biome format --write . && prettier --write . --ignore-path ../../../../.prettierignore",
49
+ "format:check": "biome ci . && prettier --check . --ignore-path ../../../../.prettierignore"
50
+ }
51
+ }
@@ -0,0 +1,12 @@
1
+ // The shared jsdom harness — observers, matchMedia, canvas, timers, teardown guards.
2
+ import '@n8n/vitest-config/setup/frontend';
3
+
4
+ import { createPinia, setActivePinia } from 'pinia';
5
+ import { beforeEach } from 'vitest';
6
+
7
+ // Framework boot stays per-package on purpose: `@n8n/i18n` devDepends on
8
+ // `@n8n/vitest-config`, so booting i18n from inside the shared harness would
9
+ // close a turbo build cycle. Add `useI18n` boot here if this module needs it.
10
+ beforeEach(() => {
11
+ setActivePinia(createPinia());
12
+ });
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
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 { InstanceRegistryModule } from './instance-registry.module';
5
+ export { useInstanceRegistryStore } from './instance-registry.store';
@@ -0,0 +1,15 @@
1
+ import type { FrontendModuleDescription } from '@n8n/frontend-module-sdk';
2
+
3
+ /**
4
+ * Store-only: this module contributes no UI surface, so registering it is a no-op —
5
+ * `moduleInitializer` guards every surface it reads. `AboutModal` and `useDebugInfo`
6
+ * consume the store directly; the descriptor is what makes this a module the shell
7
+ * knows about rather than a library it happens to import.
8
+ */
9
+ export const InstanceRegistryModule: FrontendModuleDescription = {
10
+ // Must match the backend module id: both gate off `/rest/module-settings`.
11
+ id: 'instance-registry',
12
+ name: 'Instance Registry',
13
+ description: 'Reports which instances are in this deployment and their health',
14
+ icon: 'server',
15
+ };
@@ -0,0 +1,67 @@
1
+ import type { ClusterInfoResponse } from '@n8n/api-types';
2
+ import { setActivePinia, createPinia } from 'pinia';
3
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
4
+
5
+ import { useInstanceRegistryStore } from './instance-registry.store';
6
+
7
+ const mocks = vi.hoisted(() => ({
8
+ getClusterInfo: vi.fn(),
9
+ }));
10
+
11
+ vi.mock('@n8n/rest-api-client/api/instance-registry', () => ({
12
+ getClusterInfo: mocks.getClusterInfo,
13
+ }));
14
+
15
+ vi.mock('@n8n/stores/useRootStore', () => ({
16
+ useRootStore: () => ({
17
+ restApiContext: { baseUrl: 'http://localhost', sessionId: 'test' },
18
+ }),
19
+ }));
20
+
21
+ const SAMPLE_RESPONSE: ClusterInfoResponse = {
22
+ instances: [
23
+ {
24
+ schemaVersion: 1,
25
+ instanceKey: 'main-1',
26
+ hostId: 'host-a',
27
+ instanceType: 'main',
28
+ instanceRole: 'leader',
29
+ version: '1.110.0',
30
+ registeredAt: 0,
31
+ lastSeen: 0,
32
+ },
33
+ ],
34
+ checks: {},
35
+ };
36
+
37
+ describe('useInstanceRegistryStore', () => {
38
+ beforeEach(() => {
39
+ setActivePinia(createPinia());
40
+ mocks.getClusterInfo.mockReset();
41
+ });
42
+
43
+ it('fetches and stores cluster info', async () => {
44
+ mocks.getClusterInfo.mockResolvedValue(SAMPLE_RESPONSE);
45
+
46
+ const store = useInstanceRegistryStore();
47
+ await store.fetchClusterInfo();
48
+
49
+ expect(mocks.getClusterInfo).toHaveBeenCalledTimes(1);
50
+ expect(store.clusterInfo).toEqual(SAMPLE_RESPONSE);
51
+ expect(store.isAvailable).toBe(true);
52
+ });
53
+
54
+ it('swallows errors and preserves the prior snapshot', async () => {
55
+ mocks.getClusterInfo.mockResolvedValueOnce(SAMPLE_RESPONSE);
56
+ mocks.getClusterInfo.mockRejectedValueOnce(new Error('endpoint failure'));
57
+ const debugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {});
58
+
59
+ const store = useInstanceRegistryStore();
60
+ await store.fetchClusterInfo();
61
+ await store.fetchClusterInfo();
62
+
63
+ expect(store.clusterInfo).toEqual(SAMPLE_RESPONSE);
64
+ expect(debugSpy).toHaveBeenCalled();
65
+ debugSpy.mockRestore();
66
+ });
67
+ });
@@ -0,0 +1,29 @@
1
+ import type { ClusterInfoResponse } from '@n8n/api-types';
2
+ import * as instanceRegistryApi from '@n8n/rest-api-client/api/instance-registry';
3
+ import { useRootStore } from '@n8n/stores/useRootStore';
4
+ import { defineStore } from 'pinia';
5
+ import { computed, ref } from 'vue';
6
+
7
+ export const useInstanceRegistryStore = defineStore('instanceRegistry', () => {
8
+ const rootStore = useRootStore();
9
+
10
+ const clusterInfo = ref<ClusterInfoResponse | null>(null);
11
+
12
+ const isAvailable = computed(() => clusterInfo.value !== null);
13
+
14
+ async function fetchClusterInfo(): Promise<void> {
15
+ try {
16
+ clusterInfo.value = await instanceRegistryApi.getClusterInfo(rootStore.restApiContext);
17
+ } catch (error) {
18
+ // Leave the previous snapshot in place on transient network errors — debug
19
+ // generation must never fail because cluster info couldn't be fetched.
20
+ console.debug('Failed to fetch instance registry cluster info', error);
21
+ }
22
+ }
23
+
24
+ return {
25
+ clusterInfo,
26
+ isAvailable,
27
+ fetchClusterInfo,
28
+ };
29
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "@n8n/typescript-config/tsconfig.frontend-module.json",
3
+ "compilerOptions": {
4
+ // `rootDirs`, `types` and `include` cannot be inherited from the base: relative entries in
5
+ // them resolve against this file, so a copy in the base would point at the base's directory.
6
+ // (`paths` is the exception and does come from the base.)
7
+ "rootDirs": [".", "../../../frontend/@n8n/design-system/src"],
8
+ // The two `.d.ts` entries are ambient declarations this package never imports, so nothing
9
+ // pulls them into the program: `~icons/*` and `markdown-it-task-lists` for design-system's
10
+ // source, `window.BASE_PATH` for `@n8n/stores`'s. Consuming those packages from source is
11
+ // what makes them the consumer's problem — a built `dist` would have carried them.
12
+ "types": [
13
+ "vite/client",
14
+ "vitest/globals",
15
+ "unplugin-icons/types/vue",
16
+ "../../../frontend/@n8n/design-system/src/shims-modules.d.ts",
17
+ "../../../frontend/@n8n/stores/src/shims.d.ts"
18
+ ]
19
+ },
20
+ "include": ["src/**/*.ts", "src/**/*.vue", "vite.config.ts"]
21
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,23 @@
1
+ import vue from '@vitejs/plugin-vue';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { resolve } from 'node:path';
4
+ import { defineConfig, mergeConfig } from 'vite';
5
+ import { frontendAliases } from '@n8n/frontend-vite-config';
6
+ import { vitestConfig } from '@n8n/vitest-config/frontend';
7
+
8
+ const packageDir = fileURLToPath(new URL('.', import.meta.url));
9
+ const packagesDir = resolve(packageDir, '..', '..', '..');
10
+
11
+ export default mergeConfig(
12
+ defineConfig({
13
+ plugins: [vue()],
14
+ resolve: {
15
+ // The same platform mapping the editor-ui dev server uses, so a test resolves
16
+ // `@n8n/stores/...` from source rather than from a stale `dist` — the two disagreeing is
17
+ // what put 1,111 specifiers on the wrong side of the src/dist line. Sibling modules are
18
+ // deliberately absent: nothing here should make a cross-module import resolve.
19
+ alias: frontendAliases(packagesDir),
20
+ },
21
+ }),
22
+ vitestConfig,
23
+ );