@n8n/frontend-module-insights 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.
Files changed (38) hide show
  1. package/LICENSE.md +88 -0
  2. package/README.md +64 -0
  3. package/biome.jsonc +4 -0
  4. package/eslint.config.mjs +33 -0
  5. package/package.json +72 -0
  6. package/src/__tests__/setup.ts +4 -0
  7. package/src/chartjs.utils.ts +208 -0
  8. package/src/components/InsightsDashboard.test.ts +891 -0
  9. package/src/components/InsightsDashboard.vue +426 -0
  10. package/src/components/InsightsDataRangePicker.vue +195 -0
  11. package/src/components/InsightsDateRangeAlert.test.ts +134 -0
  12. package/src/components/InsightsDateRangeAlert.vue +89 -0
  13. package/src/components/InsightsPaywall.vue +42 -0
  14. package/src/components/InsightsSummary.test.ts +206 -0
  15. package/src/components/InsightsSummary.vue +357 -0
  16. package/src/components/InsightsUpgradeModal.vue +74 -0
  17. package/src/components/__snapshots__/InsightsSummary.test.ts.snap +446 -0
  18. package/src/components/charts/InsightsChartAverageRuntime.vue +67 -0
  19. package/src/components/charts/InsightsChartFailed.vue +57 -0
  20. package/src/components/charts/InsightsChartFailureRate.vue +58 -0
  21. package/src/components/charts/InsightsChartTimeSaved.vue +74 -0
  22. package/src/components/charts/InsightsChartTotal.vue +58 -0
  23. package/src/components/charts/insightChartProps.ts +9 -0
  24. package/src/components/tables/InsightsTableWorkflows.test.ts +509 -0
  25. package/src/components/tables/InsightsTableWorkflows.vue +279 -0
  26. package/src/index.ts +4 -0
  27. package/src/insights.api.test.ts +435 -0
  28. package/src/insights.api.ts +71 -0
  29. package/src/insights.constants.ts +69 -0
  30. package/src/insights.module.test.ts +59 -0
  31. package/src/insights.module.ts +45 -0
  32. package/src/insights.store.test.ts +118 -0
  33. package/src/insights.store.ts +88 -0
  34. package/src/insights.types.ts +16 -0
  35. package/src/insights.utils.test.ts +339 -0
  36. package/src/insights.utils.ts +172 -0
  37. package/stylelint.config.mjs +9 -0
  38. package/vite.config.ts +29 -0
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,64 @@
1
+ # @n8n/frontend-module-insights
2
+
3
+ Frontend feature module. Consumed from source by the editor-ui shell; there is no
4
+ build step and no `dist`.
5
+
6
+ ## Two entry points, on purpose
7
+
8
+ - `@n8n/frontend-module-insights` — `useInsightsStore` and `InsightsSummary`, for
9
+ the shell views that show the summary widget. Every one of them reaches it
10
+ through a lazy `import()`.
11
+ - `@n8n/frontend-module-insights/insights.module` — the descriptor, for
12
+ `src/app/modules.manifest.ts`.
13
+
14
+ The split is measured, not stylistic. The manifest is imported eagerly at boot,
15
+ and `InsightsSummary` is an SFC. With both behind one entry, the SFC becomes
16
+ statically reachable from the boot chunk: `pnpm build` put `InsightsSummary`'s JS
17
+ **and a render-blocking stylesheet** into `dist/index.html` (353 `modulepreload`
18
+ entries against 346, and 99 stylesheet links against 98). Keep component code out
19
+ of the descriptor's entry.
20
+
21
+ ```bash
22
+ pnpm turbo typecheck --filter=@n8n/frontend-module-insights
23
+ pnpm turbo lint --filter=@n8n/frontend-module-insights
24
+ pnpm turbo test --filter=@n8n/frontend-module-insights
25
+ ```
26
+
27
+ Go through turbo, not `pnpm --filter <pkg> typecheck`: this package is consumed
28
+ from source, and on a cold tree its platform dependencies have not been built
29
+ yet. Turbo builds them first; the bare pnpm form does not.
30
+
31
+ ## Import rules
32
+
33
+ - Depend on foundation and platform packages only (`@n8n/design-system`,
34
+ `@n8n/stores`, `@n8n/composables`, `@n8n/i18n`, `@n8n/rest-api-client`,
35
+ `@n8n/api-types`, `@n8n/permissions`, `@n8n/frontend-constants`,
36
+ `@n8n/utils`, `@n8n/frontend-module-sdk`). Never import another
37
+ `@n8n/frontend-module-*`, and never import `@/…` from the shell.
38
+ - `@n8n/stores` and `@n8n/composables` are **subpath-only** — import
39
+ `@n8n/stores/settings.store`, not `@n8n/stores`.
40
+ - The no-cross-module rule is currently a convention: the shared tsconfig base
41
+ omits sibling modules from `paths`, which blocks an accidental import but not
42
+ a deliberate one (declaring the dependency makes it typecheck clean). The
43
+ ESLint rule that actually enforces it is CAT-3692.
44
+
45
+ ## Adding UI
46
+
47
+ `@vitejs/plugin-vue`, `unplugin-icons` and `vite-svg-loader` are wired into
48
+ `vite.config.ts`, so a `.vue` file that renders a design-system component
49
+ compiles in tests without further setup. All three are needed: the design-system
50
+ icon set imports `~icons/lucide/*` and `./custom/*.svg`, and without the icon
51
+ plugins an icon resolves to a URL string and rendering throws. Route components
52
+ must load lazily — see the note in `src/insights.module.ts`.
53
+
54
+ ## Test harness
55
+
56
+ `src/__tests__/render.ts` is this package's own renderer (i18n, pinia,
57
+ design-system, a telemetry stub). It is deliberately not the shell's
58
+ `@/__tests__/render`, which also provides the workflow document store and the
59
+ touch-events directive — editor-core concerns no insights component reads. The
60
+ shared harness (`@n8n/vitest-config/setup/frontend`) cannot host a Vue renderer:
61
+ it must not import vue, pinia or i18n, or the turbo graph gains a cycle.
62
+
63
+ Store-level fixtures that several packages need live next to the store instead:
64
+ `@n8n/stores/__tests__/defaultSettings` and `@n8n/stores/__tests__/mockedStore`.
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,33 @@
1
+ import { frontendConfig } from '@n8n/eslint-config/frontend';
2
+ import { defineConfig } from 'eslint/config';
3
+
4
+ export default defineConfig(frontendConfig, {
5
+ /**
6
+ * Suppressions inherited with the code, not granted to it.
7
+ *
8
+ * These files came from `editor-ui/src/features/execution/insights`, where
9
+ * `eslint.config.mjs` turns each of these rules off or down to `warn` for the
10
+ * whole shell. The move is content-pristine on purpose — blame and `--follow`
11
+ * survive — so the debt travels with it instead of being rewritten in the same
12
+ * PR. `warn` here, never `off`: the count is visible and can only go down.
13
+ *
14
+ * Most of it is one root cause: `chart.js` / `vue-chartjs` option and dataset
15
+ * types degrade to `any`, which propagates through the chart components. The
16
+ * `naming-convention` hits are data keys (`2weeks`, `6months`, `update:options`)
17
+ * that cannot be camelCase — those need a narrow inline disable, not a fix.
18
+ *
19
+ * Boundary rules are untouched and stay at error: nothing here relaxes what
20
+ * this module may import.
21
+ */
22
+ files: ['src/**/*.ts', 'src/**/*.vue'],
23
+ rules: {
24
+ '@typescript-eslint/naming-convention': 'warn',
25
+ '@typescript-eslint/no-unsafe-argument': 'warn',
26
+ '@typescript-eslint/no-unsafe-assignment': 'warn',
27
+ '@typescript-eslint/no-unsafe-call': 'warn',
28
+ '@typescript-eslint/no-unsafe-member-access': 'warn',
29
+ '@typescript-eslint/no-unsafe-return': 'warn',
30
+ '@typescript-eslint/await-thenable': 'warn',
31
+ '@typescript-eslint/require-await': 'warn',
32
+ },
33
+ });
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@n8n/frontend-module-insights",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "src/index.ts",
6
+ "exports": {
7
+ ".": "./src/index.ts",
8
+ "./insights.module": "./src/insights.module.ts"
9
+ },
10
+ "dependencies": {
11
+ "@internationalized/date": "^3.9.0",
12
+ "@n8n/api-types": "1.39.0",
13
+ "@n8n/composables": "1.29.0",
14
+ "@n8n/design-system": "2.38.0",
15
+ "@n8n/frontend-constants": "0.6.0",
16
+ "@n8n/frontend-module-sdk": "0.9.0",
17
+ "@n8n/i18n": "2.39.0",
18
+ "@n8n/permissions": "0.76.0",
19
+ "@n8n/rest-api-client": "2.39.0",
20
+ "@n8n/stores": "2.39.0",
21
+ "@n8n/utils": "1.47.0",
22
+ "@vueuse/core": "^14.3.0",
23
+ "chart.js": "^4.4.0",
24
+ "dateformat": "^3.0.3",
25
+ "element-plus": "2.4.3",
26
+ "lodash": "4.18.1",
27
+ "pinia": "^2.2.4",
28
+ "vue": "^3.5.13",
29
+ "vue-chartjs": "^5.2.0",
30
+ "vue-i18n": "^11.4.4",
31
+ "vue-router": "^4.5.0"
32
+ },
33
+ "devDependencies": {
34
+ "@iconify/json": "^2.2.488",
35
+ "@n8n/eslint-config": "0.0.1",
36
+ "@n8n/frontend-test-utils": "0.1.0",
37
+ "@n8n/frontend-vite-config": "0.1.0",
38
+ "@n8n/playwright-janitor": "0.1.0",
39
+ "@n8n/stylelint-config": "0.0.1",
40
+ "@n8n/typescript-config": "1.11.0",
41
+ "@n8n/vitest-config": "1.21.0",
42
+ "@pinia/testing": "^0.1.6",
43
+ "@testing-library/jest-dom": "^6.6.3",
44
+ "@testing-library/user-event": "^14.6.1",
45
+ "@testing-library/vue": "^8.1.0",
46
+ "@types/dateformat": "^3.0.0",
47
+ "@types/lodash": "4.17.17",
48
+ "@vitejs/plugin-vue": "^6.0.8",
49
+ "eslint": "9.29.0",
50
+ "stylelint": "^16.23.0",
51
+ "typescript": "6.0.2",
52
+ "unplugin-icons": "^23.0.1",
53
+ "vite": "^8.0.2",
54
+ "vite-svg-loader": "5.1.0",
55
+ "vitest": "^4.1.9",
56
+ "vue-tsc": "^2.2.8"
57
+ },
58
+ "license": "LicenseRef-n8n-sustainable-use",
59
+ "scripts": {
60
+ "clean": "rimraf .turbo",
61
+ "typecheck": "vue-tsc --noEmit",
62
+ "test": "vitest run",
63
+ "test:changed": "janitor test-scoped",
64
+ "test:dev": "vitest",
65
+ "lint": "eslint src --quiet",
66
+ "lint:fix": "eslint src --fix",
67
+ "lint:styles": "stylelint \"src/**/*.{scss,sass,vue}\" --cache",
68
+ "lint:styles:fix": "stylelint \"src/**/*.{scss,sass,vue}\" --fix --cache",
69
+ "format": "biome format --write . && prettier --write . --ignore-path ../../../../.prettierignore",
70
+ "format:check": "biome ci . && prettier --check . --ignore-path ../../../../.prettierignore"
71
+ }
72
+ }
@@ -0,0 +1,4 @@
1
+ // The shared frontend test harness: the jsdom environment, english messages, and a fresh pinia
2
+ // per test. It lives in `@n8n/frontend-test-utils` rather than in `@n8n/vitest-config`, because
3
+ // `@n8n/i18n` devDepends on the latter and importing i18n there closes a cycle in the turbo graph.
4
+ import '@n8n/frontend-test-utils/setup';
@@ -0,0 +1,208 @@
1
+ import { smartDecimal } from '@n8n/utils/number/smart-decimal';
2
+ import { useCssVar } from '@vueuse/core';
3
+ import { type ChartOptions, type ScriptableContext } from 'chart.js';
4
+ import merge from 'lodash/merge';
5
+
6
+ /**
7
+ *
8
+ * Chart js configuration
9
+ */
10
+
11
+ export const generateLinearGradient = (ctx: CanvasRenderingContext2D, height: number) => {
12
+ const gradient = ctx.createLinearGradient(0, 0, 0, height);
13
+ gradient.addColorStop(0, 'rgba(255, 111,92, 1)');
14
+ gradient.addColorStop(0.8, 'rgba(255, 111, 92, 0.25)');
15
+ gradient.addColorStop(1, 'rgba(255, 111, 92, 0)');
16
+ return gradient;
17
+ };
18
+
19
+ export const generateLineChartOptions = (
20
+ overrides: ChartOptions<'line'> = {},
21
+ ): ChartOptions<'line'> => {
22
+ const colorTextDark = useCssVar('--color--text--shade-1', document.body);
23
+ const colorBackgroundLight = useCssVar('--color--background--light-3', document.body);
24
+ const colorForeGroundBase = useCssVar('--color--foreground', document.body);
25
+
26
+ const colorTextLight = useCssVar('--color--text--tint-1', document.body);
27
+
28
+ return merge(
29
+ {
30
+ responsive: true,
31
+ maintainAspectRatio: false,
32
+ animation: false,
33
+ plugins: {
34
+ legend: {
35
+ display: false,
36
+ },
37
+ tooltip: {
38
+ caretSize: 0,
39
+ xAlign: 'center',
40
+ yAlign: 'bottom',
41
+ padding: 16,
42
+ titleFont: {
43
+ size: 14,
44
+ },
45
+ bodyFont: {
46
+ size: 14,
47
+ },
48
+ backgroundColor: colorBackgroundLight.value,
49
+ titleColor: colorTextDark.value,
50
+ bodyColor: colorTextDark.value,
51
+ borderWidth: 1,
52
+ borderColor: colorForeGroundBase.value,
53
+ callbacks: {
54
+ label(context: ScriptableContext<'line'>) {
55
+ const label = context.dataset.label ?? '';
56
+ return `${label} ${smartDecimal(context.parsed.y).toLocaleString('en-US')}`;
57
+ },
58
+ labelColor(context: ScriptableContext<'line'>) {
59
+ return {
60
+ borderColor: 'rgba(0, 0, 0, 0)',
61
+ backgroundColor: context.dataset.backgroundColor as string,
62
+ borderWidth: 0,
63
+ borderRadius: 2,
64
+ };
65
+ },
66
+ },
67
+ },
68
+ },
69
+ interaction: {
70
+ mode: 'nearest',
71
+ axis: 'x',
72
+ intersect: false,
73
+ },
74
+ scales: {
75
+ x: {
76
+ grid: {
77
+ display: false,
78
+ },
79
+ stacked: true,
80
+ beginAtZero: true,
81
+ border: {
82
+ display: false,
83
+ },
84
+ ticks: {
85
+ color: colorTextLight.value,
86
+ },
87
+ },
88
+ y: {
89
+ grid: {
90
+ color: colorForeGroundBase.value,
91
+ },
92
+ stacked: true,
93
+ border: {
94
+ display: false,
95
+ },
96
+ ticks: {
97
+ maxTicksLimit: 3,
98
+ color: colorTextLight.value,
99
+ },
100
+ },
101
+ },
102
+ },
103
+ overrides,
104
+ );
105
+ };
106
+
107
+ export const generateBarChartOptions = (
108
+ overrides: ChartOptions<'bar'> = {},
109
+ ): ChartOptions<'bar'> => {
110
+ const colorTextLight = useCssVar('--color--text--tint-1', document.body);
111
+ const colorTextDark = useCssVar('--color--text--shade-1', document.body);
112
+ const colorBackgroundLight = useCssVar('--color--background--light-3', document.body);
113
+ const colorForeGroundBase = useCssVar('--color--foreground', document.body);
114
+
115
+ return merge(
116
+ {
117
+ responsive: true,
118
+ maintainAspectRatio: false,
119
+ animation: false,
120
+ plugins: {
121
+ legend: {
122
+ display: true,
123
+ align: 'end',
124
+ reverse: true,
125
+ position: 'top',
126
+ labels: {
127
+ boxWidth: 8,
128
+ boxHeight: 8,
129
+ borderRadius: 2,
130
+ useBorderRadius: true,
131
+ color: colorTextLight.value,
132
+ },
133
+ },
134
+ tooltip: {
135
+ caretSize: 0,
136
+ xAlign: 'center',
137
+ yAlign: 'bottom',
138
+ padding: 16,
139
+ titleFont: {
140
+ size: 14,
141
+ },
142
+ bodyFont: {
143
+ size: 14,
144
+ },
145
+ backgroundColor: colorBackgroundLight.value,
146
+ titleColor: colorTextDark.value,
147
+ bodyColor: colorTextDark.value,
148
+ borderWidth: 1,
149
+ borderColor: colorForeGroundBase.value,
150
+ callbacks: {
151
+ label(context: ScriptableContext<'bar'>) {
152
+ const label = context.dataset.label ?? '';
153
+ return `${label} ${context.parsed.y}`;
154
+ },
155
+ labelColor(context: ScriptableContext<'bar'>) {
156
+ return {
157
+ borderColor: 'rgba(0, 0, 0, 0)',
158
+ backgroundColor: context.dataset.backgroundColor as string,
159
+ borderWidth: 0,
160
+ borderRadius: 2,
161
+ };
162
+ },
163
+ },
164
+ },
165
+ },
166
+ interaction: {
167
+ mode: 'nearest',
168
+ axis: 'x',
169
+ intersect: false,
170
+ },
171
+ datasets: {
172
+ bar: {
173
+ maxBarThickness: 32,
174
+ borderRadius: 4,
175
+ },
176
+ },
177
+ scales: {
178
+ x: {
179
+ grid: {
180
+ display: false,
181
+ },
182
+ stacked: true,
183
+ beginAtZero: true,
184
+ border: {
185
+ display: false,
186
+ },
187
+ ticks: {
188
+ color: colorTextLight.value,
189
+ },
190
+ },
191
+ y: {
192
+ grid: {
193
+ color: colorForeGroundBase.value,
194
+ },
195
+ stacked: true,
196
+ border: {
197
+ display: false,
198
+ },
199
+ ticks: {
200
+ maxTicksLimit: 3,
201
+ color: colorTextLight.value,
202
+ },
203
+ },
204
+ },
205
+ },
206
+ overrides,
207
+ );
208
+ };