fix(editor): Disable telemetry in dev mode and in E2E tests (#6869)

* fix(editor): Disable telemetry in dev mode and in E2E tests

* fix(editor): add external js to rollup config

* fix(editor): using vite plugin to control external script loading

* fix(editor): update lock file version

* fix(editor): block telemetry host
This commit is contained in:
Csaba Tuncsik 2023-08-11 14:42:25 +02:00 committed by GitHub
parent 10c15874b2
commit 808a92809e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 52 deletions

View file

@ -18,5 +18,6 @@ module.exports = defineConfig({
screenshotOnRunFailure: true, screenshotOnRunFailure: true,
experimentalInteractiveRunEvents: true, experimentalInteractiveRunEvents: true,
experimentalSessionAndOrigin: true, experimentalSessionAndOrigin: true,
blockHosts: ['telemetry.n8n.io'],
}, },
}); });

View file

@ -63,6 +63,7 @@
"turbo": "1.10.12", "turbo": "1.10.12",
"typescript": "*", "typescript": "*",
"vite": "^4.4.7", "vite": "^4.4.7",
"vite-plugin-ejs": "^1.6.4",
"vitest": "^0.33.0", "vitest": "^0.33.0",
"vue-tsc": "^1.8.8" "vue-tsc": "^1.8.8"
}, },

View file

@ -9,6 +9,9 @@
window.BASE_PATH = '/{{BASE_PATH}}/'; window.BASE_PATH = '/{{BASE_PATH}}/';
window.REST_ENDPOINT = '{{REST_ENDPOINT}}'; window.REST_ENDPOINT = '{{REST_ENDPOINT}}';
</script> </script>
<% if(!isDev){ %>
<script type="text/javascript" src='https://cdn-rs.n8n.io/v1/ra.min.js'></script>
<% } %>
<script>!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled getFeatureFlag onFeatureFlags reloadFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[])</script> <script>!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled getFeatureFlag onFeatureFlags reloadFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[])</script>
<title>n8n.io - Workflow Automation</title> <title>n8n.io - Workflow Automation</title>

View file

@ -1,35 +1,28 @@
import type { Plugin } from 'vue'; import type { Plugin } from 'vue';
import type { ITelemetrySettings, ITelemetryTrackProperties, IDataObject } from 'n8n-workflow'; import type { IDataObject, ITelemetrySettings, ITelemetryTrackProperties } from 'n8n-workflow';
import type { RouteLocation } from 'vue-router'; import type { RouteLocation } from 'vue-router';
import type { INodeCreateElement, IUpdateInformation } from '@/Interface'; import type { INodeCreateElement, IUpdateInformation } from '@/Interface';
import type { IUserNodesPanelSession } from './telemetry.types'; import type { IUserNodesPanelSession, RudderStack } from './telemetry.types';
import { useSettingsStore } from '@/stores/settings.store'; import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store'; import { useRootStore } from '@/stores/n8nRoot.store';
import { useTelemetryStore } from '@/stores/telemetry.store'; import { useTelemetryStore } from '@/stores/telemetry.store';
import { SLACK_NODE_TYPE } from '@/constants'; import { SLACK_NODE_TYPE } from '@/constants';
export class Telemetry { export class Telemetry {
private pageEventQueue: Array<{ route: RouteLocation }>; constructor(
private previousPath: string; private rudderStack: RudderStack,
private userNodesPanelSession: IUserNodesPanelSession = {
private get rudderStack() { sessionId: '',
return window.rudderanalytics; data: {
} nodeFilter: '',
resultsNodes: [],
private userNodesPanelSession: IUserNodesPanelSession = { filterMode: 'Regular',
sessionId: '', },
data: {
nodeFilter: '',
resultsNodes: [],
filterMode: 'Regular',
}, },
}; private pageEventQueue: Array<{ route: RouteLocation }> = [],
private previousPath: string = '',
constructor() { ) {}
this.pageEventQueue = [];
this.previousPath = '';
}
init( init(
telemetrySettings: ITelemetrySettings, telemetrySettings: ITelemetrySettings,
@ -100,17 +93,12 @@ export class Telemetry {
const pageName = route.name; const pageName = route.name;
let properties: { [key: string]: string } = {}; let properties: { [key: string]: string } = {};
if ( if (route.meta?.telemetry && typeof route.meta.telemetry.getProperties === 'function') {
route.meta &&
route.meta.telemetry &&
typeof route.meta.telemetry.getProperties === 'function'
) {
properties = route.meta.telemetry.getProperties(route); properties = route.meta.telemetry.getProperties(route);
} }
const category = const category = route.meta?.telemetry?.pageCategory || 'Editor';
(route.meta && route.meta.telemetry && route.meta.telemetry.pageCategory) || 'Editor'; this.rudderStack.page(category, pageName, properties);
this.rudderStack.page(category, pageName!, properties);
} else { } else {
this.pageEventQueue.push({ this.pageEventQueue.push({
route, route,
@ -234,8 +222,6 @@ export class Telemetry {
} }
private initRudderStack(key: string, url: string, options: IDataObject) { private initRudderStack(key: string, url: string, options: IDataObject) {
window.rudderanalytics = window.rudderanalytics || [];
this.rudderStack.methods = [ this.rudderStack.methods = [
'load', 'load',
'page', 'page',
@ -262,26 +248,20 @@ export class Telemetry {
this.rudderStack[method] = this.rudderStack.factory(method); this.rudderStack[method] = this.rudderStack.factory(method);
} }
this.rudderStack.loadJS = () => {
const script = document.createElement('script');
script.type = 'text/javascript';
script.async = !0;
script.src = 'https://cdn-rs.n8n.io/v1/ra.min.js';
const element: Element = document.getElementsByTagName('script')[0];
if (element && element.parentNode) {
element.parentNode.insertBefore(script, element);
}
};
this.rudderStack.loadJS();
this.rudderStack.load(key, url, options); this.rudderStack.load(key, url, options);
} }
} }
export const telemetry = new Telemetry(); export const telemetry = new Telemetry(
window.rudderanalytics ?? {
identify: () => {},
reset: () => {},
track: () => {},
page: () => {},
push: () => {},
load: () => {},
},
);
export const TelemetryPlugin: Plugin<{}> = { export const TelemetryPlugin: Plugin<{}> = {
install(app) { install(app) {

View file

@ -17,17 +17,15 @@ interface IUserNodesPanelSessionData {
/** /**
* Simplified version of: * Simplified version of:
* https://github.com/rudderlabs/rudder-sdk-js/blob/master/dist/rudder-sdk-js/index.d.ts * https://github.com/rudderlabs/rudder-sdk-js/blob/production-staging/packages/npm/index.d.ts
*/ */
interface RudderStack extends Array<unknown> { export interface RudderStack {
[key: string]: unknown; [key: string]: unknown;
methods: string[]; methods: string[];
factory: (method: string) => (...args: unknown[]) => RudderStack; factory: (method: string) => (...args: unknown[]) => RudderStack;
loadJS(): void;
/** /**
* Native methods * Native methods
*/ */

View file

@ -3,6 +3,7 @@ import { resolve } from 'path';
import { defineConfig, mergeConfig } from 'vite'; import { defineConfig, mergeConfig } from 'vite';
import { defineConfig as defineVitestConfig } from 'vitest/config'; import { defineConfig as defineVitestConfig } from 'vitest/config';
import { sentryVitePlugin } from '@sentry/vite-plugin'; import { sentryVitePlugin } from '@sentry/vite-plugin';
import { ViteEjsPlugin } from "vite-plugin-ejs";
import packageJSON from './package.json'; import packageJSON from './package.json';
@ -62,7 +63,7 @@ const alias = [
}, },
]; ];
const plugins = [vue()]; const plugins = [vue(), ViteEjsPlugin()];
const { SENTRY_AUTH_TOKEN: authToken, RELEASE: release } = process.env; const { SENTRY_AUTH_TOKEN: authToken, RELEASE: release } = process.env;
if (release && authToken) { if (release && authToken) {

View file

@ -124,6 +124,9 @@ importers:
vite: vite:
specifier: ^4.4.7 specifier: ^4.4.7
version: 4.4.7(less@4.1.3)(sass@1.64.1) version: 4.4.7(less@4.1.3)(sass@1.64.1)
vite-plugin-ejs:
specifier: ^1.6.4
version: 1.6.4
vitest: vitest:
specifier: ^0.33.0 specifier: ^0.33.0
version: 0.33.0 version: 0.33.0
@ -20715,6 +20718,12 @@ packages:
- terser - terser
dev: true dev: true
/vite-plugin-ejs@1.6.4:
resolution: {integrity: sha512-23p1RS4PiA0veXY5/gHZ60pl3pPvd8NEqdBsDgxNK8nM1rjFFDcVb0paNmuipzCgNP/Y0f/Id22M7Il4kvZ2jA==}
dependencies:
ejs: 3.1.8
dev: true
/vite@4.4.7(@types/node@18.16.16): /vite@4.4.7(@types/node@18.16.16):
resolution: {integrity: sha512-6pYf9QJ1mHylfVh39HpuSfMPojPSKVxZvnclX1K1FyZ1PXDOcLBibdq5t1qxJSnL63ca8Wf4zts6mD8u8oc9Fw==} resolution: {integrity: sha512-6pYf9QJ1mHylfVh39HpuSfMPojPSKVxZvnclX1K1FyZ1PXDOcLBibdq5t1qxJSnL63ca8Wf4zts6mD8u8oc9Fw==}
engines: {node: ^14.18.0 || >=16.0.0} engines: {node: ^14.18.0 || >=16.0.0}