build: switch from yarn to npm to manage js dependencies and move js contents to root

yarn v1 is being deprecated and starts to have some issues

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-11-14 17:24:42 +01:00
parent 32055122c3
commit 2e72f6faf4
595 changed files with 12078 additions and 7843 deletions

View File

@@ -0,0 +1,58 @@
import { IAnalyticsConfig, IKeyValueConfig } from "@/types/config.model";
let app: any = null;
export const setAppForAnalytics = (newApp: any) => {
app = newApp;
};
export const statistics = async (
configAnalytics: IAnalyticsConfig[],
environement: any
) => {
console.debug("Loading statistics", configAnalytics);
const matomoConfig = checkProviderConfig(configAnalytics, "matomo");
if (matomoConfig?.enabled === true) {
const { matomo } = (await import("./matomo")) as any;
matomo({ ...environement, app }, convertConfig(matomoConfig.configuration));
}
const sentryConfig = checkProviderConfig(configAnalytics, "sentry");
if (sentryConfig?.enabled === true) {
const { sentry } = (await import("./sentry")) as any;
sentry({ ...environement, app }, convertConfig(sentryConfig.configuration));
}
};
export const checkProviderConfig = (
configAnalytics: IAnalyticsConfig[],
providerName: string
): IAnalyticsConfig | undefined => {
return configAnalytics?.find((provider) => provider.id === providerName);
};
export const convertConfig = (
configs: IKeyValueConfig[]
): Record<string, any> => {
return configs.reduce(
(acc, config) => {
acc[config.key] = toType(config.value, config.type);
return acc;
},
{} as Record<string, any>
);
};
const toType = (value: string, type: string): string | number | boolean => {
switch (type) {
case "boolean":
return value === "true";
case "integer":
return parseInt(value, 10);
case "float":
return parseFloat(value);
case "string":
default:
return value;
}
};

View File

@@ -0,0 +1,14 @@
import VueMatomo from "vue-matomo";
export const matomo = (environment: any, matomoConfiguration: any) => {
console.debug("Loading Matomo statistics");
console.debug(
"Calling VueMatomo with the following configuration",
matomoConfiguration
);
environment.app.use(VueMatomo, {
...matomoConfiguration,
router: environment.router,
debug: import.meta.env.DEV,
});
};

View File

@@ -0,0 +1,9 @@
import { VuePlausible } from "vue-plausible";
export default (environment: any, plausibleConfiguration: any) => {
console.debug("Loading Plausible statistics");
environment.app.use(VuePlausible, {
// see configuration section
...plausibleConfiguration,
});
};

View File

@@ -0,0 +1,54 @@
import * as Sentry from "@sentry/vue";
import { Integrations } from "@sentry/tracing";
export const sentry = (environment: any, sentryConfiguration: any) => {
console.debug("Loading Sentry statistics");
console.debug(
"Calling Sentry with the following configuration",
sentryConfiguration
);
// Don't attach errors to previous events
window.sessionStorage.removeItem("lastEventId");
Sentry.init({
app: environment.app,
dsn: sentryConfiguration.dsn,
debug: import.meta.env.DEV,
integrations: [
new Integrations.BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(
environment.router
),
tracingOrigins: [window.origin, /^\//],
}),
],
beforeSend(event) {
// Check if it is an exception, and if so, save it in session storage
// so that it can be retreived from the error component
if (event.exception && event.event_id) {
window.sessionStorage.setItem("lastEventId", event.event_id);
}
return event;
},
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: Number.parseFloat(sentryConfiguration.tracesSampleRate),
release: environment.version,
logErrors: true,
});
};
export const submitFeedback = async (
endpoint: string,
dsn: string,
params: Record<string, string>
): Promise<void> => {
await fetch(endpoint, {
method: "POST",
headers: {
"Content-type": "application/json",
Authorization: `DSN ${dsn}`,
},
body: JSON.stringify(params),
});
};