fix: ensure the code doesn’t crash in the worker environment (#23238)
Co-authored-by: Satish Gandham <hello@satishgandham.com>
This commit is contained in:
parent
2a65b232a0
commit
2a9eb75f51
|
|
@ -2,7 +2,6 @@ import type { AppsmithUIConfigs } from "./types";
|
|||
import { Integrations } from "@sentry/tracing";
|
||||
import * as Sentry from "@sentry/react";
|
||||
import { createBrowserHistory } from "history";
|
||||
const history = createBrowserHistory();
|
||||
|
||||
export interface INJECTED_CONFIGS {
|
||||
sentry: {
|
||||
|
|
@ -136,62 +135,64 @@ const getConfig = (fromENV: string, fromWindow = "") => {
|
|||
|
||||
// TODO(Abhinav): See if this is called so many times, that we may need some form of memoization.
|
||||
export const getAppsmithConfigs = (): AppsmithUIConfigs => {
|
||||
const { APPSMITH_FEATURE_CONFIGS } = window;
|
||||
const APPSMITH_FEATURE_CONFIGS =
|
||||
// This code might be called both from the main thread and a web worker
|
||||
typeof window === "undefined" ? undefined : window.APPSMITH_FEATURE_CONFIGS;
|
||||
const ENV_CONFIG = getConfigsFromEnvVars();
|
||||
// const sentry = getConfig(ENV_CONFIG.sentry, APPSMITH_FEATURE_CONFIGS.sentry);
|
||||
const sentryDSN = getConfig(
|
||||
ENV_CONFIG.sentry.dsn,
|
||||
APPSMITH_FEATURE_CONFIGS.sentry.dsn,
|
||||
APPSMITH_FEATURE_CONFIGS?.sentry.dsn,
|
||||
);
|
||||
const sentryRelease = getConfig(
|
||||
ENV_CONFIG.sentry.release,
|
||||
APPSMITH_FEATURE_CONFIGS.sentry.release,
|
||||
APPSMITH_FEATURE_CONFIGS?.sentry.release,
|
||||
);
|
||||
const sentryENV = getConfig(
|
||||
ENV_CONFIG.sentry.environment,
|
||||
APPSMITH_FEATURE_CONFIGS.sentry.environment,
|
||||
APPSMITH_FEATURE_CONFIGS?.sentry.environment,
|
||||
);
|
||||
const segment = getConfig(
|
||||
ENV_CONFIG.segment.apiKey,
|
||||
APPSMITH_FEATURE_CONFIGS.segment.apiKey,
|
||||
APPSMITH_FEATURE_CONFIGS?.segment.apiKey,
|
||||
);
|
||||
const fusioncharts = getConfig(
|
||||
ENV_CONFIG.fusioncharts.licenseKey,
|
||||
APPSMITH_FEATURE_CONFIGS.fusioncharts.licenseKey,
|
||||
APPSMITH_FEATURE_CONFIGS?.fusioncharts.licenseKey,
|
||||
);
|
||||
|
||||
const googleRecaptchaSiteKey = getConfig(
|
||||
ENV_CONFIG.googleRecaptchaSiteKey,
|
||||
APPSMITH_FEATURE_CONFIGS.googleRecaptchaSiteKey,
|
||||
APPSMITH_FEATURE_CONFIGS?.googleRecaptchaSiteKey,
|
||||
);
|
||||
|
||||
// As the following shows, the config variables can be set using a combination
|
||||
// of env variables and injected configs
|
||||
const smartLook = getConfig(
|
||||
ENV_CONFIG.smartLook.id,
|
||||
APPSMITH_FEATURE_CONFIGS.smartLook.id,
|
||||
APPSMITH_FEATURE_CONFIGS?.smartLook.id,
|
||||
);
|
||||
|
||||
const algoliaAPIID = getConfig(
|
||||
ENV_CONFIG.algolia.apiId,
|
||||
APPSMITH_FEATURE_CONFIGS.algolia.apiId,
|
||||
APPSMITH_FEATURE_CONFIGS?.algolia.apiId,
|
||||
);
|
||||
const algoliaAPIKey = getConfig(
|
||||
ENV_CONFIG.algolia.apiKey,
|
||||
APPSMITH_FEATURE_CONFIGS.algolia.apiKey,
|
||||
APPSMITH_FEATURE_CONFIGS?.algolia.apiKey,
|
||||
);
|
||||
const algoliaIndex = getConfig(
|
||||
ENV_CONFIG.algolia.indexName,
|
||||
APPSMITH_FEATURE_CONFIGS.algolia.indexName,
|
||||
APPSMITH_FEATURE_CONFIGS?.algolia.indexName,
|
||||
);
|
||||
const algoliaSnippetIndex = getConfig(
|
||||
ENV_CONFIG.algolia.indexName,
|
||||
APPSMITH_FEATURE_CONFIGS.algolia.snippetIndex,
|
||||
APPSMITH_FEATURE_CONFIGS?.algolia.snippetIndex,
|
||||
);
|
||||
|
||||
const segmentCEKey = getConfig(
|
||||
ENV_CONFIG.segment.ceKey,
|
||||
APPSMITH_FEATURE_CONFIGS.segment.ceKey,
|
||||
APPSMITH_FEATURE_CONFIGS?.segment.ceKey,
|
||||
);
|
||||
|
||||
// We enable segment tracking if either the Cloud API key is set or the self-hosted CE key is set
|
||||
|
|
@ -205,11 +206,16 @@ export const getAppsmithConfigs = (): AppsmithUIConfigs => {
|
|||
environment: sentryENV.value,
|
||||
normalizeDepth: 3,
|
||||
integrations: [
|
||||
new Integrations.BrowserTracing({
|
||||
// Can also use reactRouterV4Instrumentation
|
||||
routingInstrumentation: Sentry.reactRouterV5Instrumentation(history),
|
||||
}),
|
||||
],
|
||||
typeof window === "undefined"
|
||||
? // The Browser Tracing instrumentation isn’t working (and is unnecessary) in the worker environment
|
||||
undefined
|
||||
: new Integrations.BrowserTracing({
|
||||
// Can also use reactRouterV4Instrumentation
|
||||
routingInstrumentation: Sentry.reactRouterV5Instrumentation(
|
||||
createBrowserHistory(),
|
||||
),
|
||||
}),
|
||||
].filter((i) => i !== undefined),
|
||||
tracesSampleRate: 0.1,
|
||||
},
|
||||
smartLook: {
|
||||
|
|
@ -237,33 +243,53 @@ export const getAppsmithConfigs = (): AppsmithUIConfigs => {
|
|||
apiKey: googleRecaptchaSiteKey.value,
|
||||
},
|
||||
enableRapidAPI:
|
||||
ENV_CONFIG.enableRapidAPI || APPSMITH_FEATURE_CONFIGS.enableRapidAPI,
|
||||
ENV_CONFIG.enableRapidAPI ||
|
||||
APPSMITH_FEATURE_CONFIGS?.enableRapidAPI ||
|
||||
false,
|
||||
disableLoginForm:
|
||||
ENV_CONFIG.disableLoginForm || APPSMITH_FEATURE_CONFIGS.disableLoginForm,
|
||||
ENV_CONFIG.disableLoginForm ||
|
||||
APPSMITH_FEATURE_CONFIGS?.disableLoginForm ||
|
||||
false,
|
||||
disableSignup:
|
||||
ENV_CONFIG.disableSignup || APPSMITH_FEATURE_CONFIGS.disableSignup,
|
||||
ENV_CONFIG.disableSignup ||
|
||||
APPSMITH_FEATURE_CONFIGS?.disableSignup ||
|
||||
false,
|
||||
enableMixpanel:
|
||||
ENV_CONFIG.enableMixpanel || APPSMITH_FEATURE_CONFIGS.enableMixpanel,
|
||||
ENV_CONFIG.enableMixpanel ||
|
||||
APPSMITH_FEATURE_CONFIGS?.enableMixpanel ||
|
||||
false,
|
||||
cloudHosting:
|
||||
ENV_CONFIG.cloudHosting || APPSMITH_FEATURE_CONFIGS.cloudHosting,
|
||||
logLevel: ENV_CONFIG.logLevel || APPSMITH_FEATURE_CONFIGS.logLevel,
|
||||
enableTNCPP: ENV_CONFIG.enableTNCPP || APPSMITH_FEATURE_CONFIGS.enableTNCPP,
|
||||
appVersion: ENV_CONFIG.appVersion || APPSMITH_FEATURE_CONFIGS.appVersion,
|
||||
ENV_CONFIG.cloudHosting ||
|
||||
APPSMITH_FEATURE_CONFIGS?.cloudHosting ||
|
||||
false,
|
||||
logLevel:
|
||||
ENV_CONFIG.logLevel || APPSMITH_FEATURE_CONFIGS?.logLevel || false,
|
||||
enableTNCPP:
|
||||
ENV_CONFIG.enableTNCPP || APPSMITH_FEATURE_CONFIGS?.enableTNCPP || false,
|
||||
appVersion:
|
||||
ENV_CONFIG.appVersion || APPSMITH_FEATURE_CONFIGS?.appVersion || false,
|
||||
intercomAppID:
|
||||
ENV_CONFIG.intercomAppID || APPSMITH_FEATURE_CONFIGS.intercomAppID,
|
||||
mailEnabled: ENV_CONFIG.mailEnabled || APPSMITH_FEATURE_CONFIGS.mailEnabled,
|
||||
ENV_CONFIG.intercomAppID || APPSMITH_FEATURE_CONFIGS?.intercomAppID || "",
|
||||
mailEnabled:
|
||||
ENV_CONFIG.mailEnabled || APPSMITH_FEATURE_CONFIGS?.mailEnabled || false,
|
||||
cloudServicesBaseUrl:
|
||||
ENV_CONFIG.cloudServicesBaseUrl ||
|
||||
APPSMITH_FEATURE_CONFIGS.cloudServicesBaseUrl,
|
||||
APPSMITH_FEATURE_CONFIGS?.cloudServicesBaseUrl ||
|
||||
"",
|
||||
appsmithSupportEmail: ENV_CONFIG.supportEmail,
|
||||
hideWatermark:
|
||||
ENV_CONFIG.hideWatermark || APPSMITH_FEATURE_CONFIGS.hideWatermark,
|
||||
ENV_CONFIG.hideWatermark ||
|
||||
APPSMITH_FEATURE_CONFIGS?.hideWatermark ||
|
||||
false,
|
||||
disableIframeWidgetSandbox:
|
||||
ENV_CONFIG.disableIframeWidgetSandbox ||
|
||||
APPSMITH_FEATURE_CONFIGS.disableIframeWidgetSandbox,
|
||||
pricingUrl: ENV_CONFIG.pricingUrl || APPSMITH_FEATURE_CONFIGS.pricingUrl,
|
||||
APPSMITH_FEATURE_CONFIGS?.disableIframeWidgetSandbox ||
|
||||
false,
|
||||
pricingUrl:
|
||||
ENV_CONFIG.pricingUrl || APPSMITH_FEATURE_CONFIGS?.pricingUrl || "",
|
||||
customerPortalUrl:
|
||||
ENV_CONFIG.customerPortalUrl ||
|
||||
APPSMITH_FEATURE_CONFIGS.customerPortalUrl,
|
||||
APPSMITH_FEATURE_CONFIGS?.customerPortalUrl ||
|
||||
"",
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user