From 83ee0dc9ad4bb9508ef277b7c97d0e927d8a5085 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 14 Nov 2023 13:09:43 -0500 Subject: [PATCH] chore: Remove DSN loader from develop docs The DSN loader has never worked in develop docs as develop.sentry.dev is not in the allowlist for CORS domains. DSN substitution is infrequently used in develop docs and not having it is simpler than fixing and maintaining it. --- src/components/codeContext.tsx | 120 +-------------------------------- 1 file changed, 3 insertions(+), 117 deletions(-) diff --git a/src/components/codeContext.tsx b/src/components/codeContext.tsx index f5bee08b20..faea92d4c1 100644 --- a/src/components/codeContext.tsx +++ b/src/components/codeContext.tsx @@ -1,4 +1,4 @@ -import React, {useState, useEffect} from 'react'; +import React, {useState} from 'react'; type ProjectCodeKeywords = { DSN: string; @@ -20,27 +20,6 @@ type CodeKeywords = { PROJECT: ProjectCodeKeywords[]; }; -type Dsn = { - scheme: string; - publicKey: string; - secretKey?: string; - host: string; - pathname: string; -}; - -type ProjectApiResult = { - dsn: string; - dsnPublic: string; - id: string; - slug: string; - organizationId: string; - organizationSlug: string; - projectSlug: string; -}; - -// only fetch them once -let cachedCodeKeywords = null; - const DEFAULTS: CodeKeywords = { PROJECT: [ { @@ -69,104 +48,11 @@ type CodeContextType = { const CodeContext = React.createContext(null); -const parseDsn = function (dsn: string): Dsn { - const match = dsn.match(/^(.*?\/\/)(.*?):(.*?)@(.*?)(\/.*?)$/); - - return { - scheme: match[1], - publicKey: escape(match[2]), - secretKey: escape(match[3]), - host: escape(match[4]), - pathname: escape(match[5]), - }; -}; - -const formatMinidumpURL = ({scheme, host, pathname, publicKey}: Dsn) => { - return `${scheme}${host}/api${pathname}/minidump/?sentry_key=${publicKey}`; -}; - -const formatUnrealEngineURL = ({scheme, host, pathname, publicKey}: Dsn) => { - return `${scheme}${host}/api${pathname}/unreal/${publicKey}/`; -}; - -const formatApiUrl = ({scheme, host}: Dsn) => { - const apiHost = host.indexOf('.ingest.') >= 0 ? host.split('.ingest.')[1] : host; - - return `${scheme}${apiHost}/api`; -}; - -export function fetchCodeKeywords() { - return new Promise(resolve => { - function transformResults(projects: ProjectApiResult[]) { - if (projects.length === 0) { - console.warn('Unable to fetch codeContext - using defaults.'); - resolve(DEFAULTS); - } else { - resolve({ - PROJECT: projects.map(project => { - const parsedDsn = parseDsn(project.dsn); - return { - DSN: project.dsn, - PUBLIC_DSN: project.dsnPublic, - PUBLIC_KEY: parsedDsn.publicKey, - SECRET_KEY: parsedDsn.secretKey, - API_URL: formatApiUrl(parsedDsn), - PROJECT_ID: project.id, - PROJECT_SLUG: project.projectSlug, - ORG_ID: project.organizationId, - ORG_SLUG: project.organizationSlug, - ORG_INGEST_DOMAIN: `o${project.organizationId}.ingest.sentry.io`, - MINIDUMP_URL: formatMinidumpURL(parsedDsn), - UNREAL_URL: formatUnrealEngineURL(parsedDsn), - title: `${project.organizationSlug} / ${project.projectSlug}`, - }; - }), - }); - } - } - - const xhr = new XMLHttpRequest(); - xhr.open('GET', 'https://sentry.io/docs/api/user/'); - xhr.withCredentials = true; - xhr.responseType = 'json'; - xhr.onreadystatechange = () => { - if (xhr.readyState === 4) { - if (xhr.status === 0) { - transformResults([]); - } else { - const { - projects, - }: { - projects: ProjectApiResult[]; - } = xhr.response; - transformResults(projects); - } - } - }; - xhr.send(null); - }); -} - export default CodeContext; -export function useCodeContextState(fetcher = fetchCodeKeywords) { - let [codeKeywords, setCodeKeywords] = useState(DEFAULTS); - if (codeKeywords === null && cachedCodeKeywords !== null) { - setCodeKeywords(cachedCodeKeywords); - codeKeywords = cachedCodeKeywords; - } - - useEffect(() => { - if (cachedCodeKeywords === null) { - fetcher().then((config: CodeKeywords) => { - cachedCodeKeywords = config; - setCodeKeywords(config); - }); - } - }); - +export function useCodeContextState() { return { - codeKeywords, + codeKeywords: DEFAULTS, sharedCodeSelection: useState(null), sharedKeywordSelection: useState({}), };