Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix build type errors

Tomas Valentad9bc3da25e9f
diff --git a/apps/docs/src/app/api/cli/page.tsx b/apps/docs/src/app/api/cli/page.tsx
index 8d1f763b8..b02b59cc5 100644
--- a/apps/docs/src/app/api/cli/page.tsx
+++ b/apps/docs/src/app/api/cli/page.tsx
@@ -21,7 +21,7 @@ export default function Page() {
const { user, isLoading: userIsLoading } = useUser()
const apiKey = useApiKey()
const searchParams = useSearchParams()
- const searchParamsObj = Object.fromEntries(searchParams)
+ const searchParamsObj = searchParams ? Object.fromEntries(searchParams) : {}
const { next, state } = searchParamsObj
// TODO: Consider sending back onetime code to be used to get access token
diff --git a/apps/docs/src/app/pricing/Promo.tsx b/apps/docs/src/app/pricing/Promo.tsx
index 3158e5225..5344a39c7 100644
--- a/apps/docs/src/app/pricing/Promo.tsx
+++ b/apps/docs/src/app/pricing/Promo.tsx
@@ -26,6 +26,11 @@ function Promo() {
}
setError('')
+ if (!user || user?.teams.length === 0) {
+ setError('You must be a member of a team to apply a promo code')
+ return
+ }
+
// TODO: Actually apply the promo code
const response = await sendPromoCode(code, user.teams[0].id)
const responseData = await response.json()
diff --git a/apps/docs/src/app/pricing/SwitchToHobbyButton.tsx b/apps/docs/src/app/pricing/SwitchToHobbyButton.tsx
index 0496842ef..964372ad8 100644
--- a/apps/docs/src/app/pricing/SwitchToHobbyButton.tsx
+++ b/apps/docs/src/app/pricing/SwitchToHobbyButton.tsx
@@ -23,8 +23,7 @@ function SwitchToHobbyButton() {
return <Spinner />
}
-
- if (!user && !isLoading) {
+ if (!user) {
return (
<Link href="/sign-in?view=sign-up">
<Button>Sign Up</Button>
diff --git a/apps/docs/src/app/pricing/SwitchToProButton.tsx b/apps/docs/src/app/pricing/SwitchToProButton.tsx
index 297dcce00..124239884 100644
--- a/apps/docs/src/app/pricing/SwitchToProButton.tsx
+++ b/apps/docs/src/app/pricing/SwitchToProButton.tsx
@@ -30,6 +30,10 @@ function SwitchTierButton() {
async function createCheckoutSession() {
setError('')
+ if (!user) {
+ return setError('You must be logged in to switch to Pro.')
+ }
+
const response = await createCheckout(tiers.pro.id, user.teams[0].id)
const responseData = await response.json()
@@ -45,7 +49,7 @@ function SwitchTierButton() {
}
- if (!user && !isLoading) {
+ if (!user) {
return (
<Link href="/sign-in?view=sign-up">
<Button>Sign Up</Button>
diff --git a/apps/docs/src/app/pricing/promo/route.ts b/apps/docs/src/app/pricing/promo/route.ts
index 05b566a97..e0b7af912 100644
--- a/apps/docs/src/app/pricing/promo/route.ts
+++ b/apps/docs/src/app/pricing/promo/route.ts
@@ -2,8 +2,8 @@ import { NextResponse as Response } from 'next/server'
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
- process.env.NEXT_PUBLIC_SUPABASE_URL,
- process.env.SUPABASE_SERVICE_ROLE_KEY,
+ process.env.NEXT_PUBLIC_SUPABASE_URL!,
+ process.env.SUPABASE_SERVICE_ROLE_KEY!,
)
export const dynamic = 'force-dynamic' // defaults to force-static
@@ -41,7 +41,8 @@ export async function POST(request: Request) {
.select('tier')
.eq('id', teamID)
- if (tiersError) {
+
+ if (teamError) {
return new Response(teamError.message, { status: 500 })
}
diff --git a/apps/docs/src/app/sitemap.ts b/apps/docs/src/app/sitemap.ts
index 73872754f..0e1ca2ac8 100644
--- a/apps/docs/src/app/sitemap.ts
+++ b/apps/docs/src/app/sitemap.ts
@@ -2,6 +2,10 @@ import { MetadataRoute } from 'next'
import fs from 'fs'
import path from 'path'
+function nonNull<T>(value: T | null): value is T {
+ return value !== null
+}
+
export default function sitemap(): MetadataRoute.Sitemap {
const appDirectory = path.join(process.cwd(), 'src', 'app')
const mdxFilePaths = getAllMdxFilePaths(appDirectory)
@@ -23,7 +27,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
priority,
}
})
- .filter(Boolean)
+ .filter(nonNull)
}
function getAllMdxFilePaths(directory: string): string[] {
diff --git a/apps/docs/src/app/usage/Credits.tsx b/apps/docs/src/app/usage/Credits.tsx
index a80857dd9..6caad80d9 100644
--- a/apps/docs/src/app/usage/Credits.tsx
+++ b/apps/docs/src/app/usage/Credits.tsx
@@ -41,7 +41,7 @@ function Credits() {
</div>
<span className="text-sm">Will be used when generating invoice</span>
{isLoading && <SpinnerIcon />}
- {!isLoading && (
+ {!isLoading && credits !== null && (
<span className="text-sm font-mono text-green-300/80">${formatCurrency(credits)}</span>
)}
</div>
diff --git a/apps/docs/src/components/Auth.tsx b/apps/docs/src/components/Auth.tsx
index 7b41bfd96..eea8d6dc1 100644
--- a/apps/docs/src/components/Auth.tsx
+++ b/apps/docs/src/components/Auth.tsx
@@ -61,6 +61,10 @@ export const Auth = function () {
function redirectToCurrentURL() {
const url = typeof window !== 'undefined' ? window.location.href : undefined
+ if (!url) {
+ return ''
+ }
+
const encodedURL = encodeURIComponent(url)
return `redirect_to=${encodedURL}`
}
diff --git a/apps/docs/src/components/AuthForm.tsx b/apps/docs/src/components/AuthForm.tsx
index c32d7cbea..55590ed17 100644
--- a/apps/docs/src/components/AuthForm.tsx
+++ b/apps/docs/src/components/AuthForm.tsx
@@ -28,16 +28,16 @@ function getView(hash: string): ViewType {
function AuthForm() {
const searchParams = useSearchParams()
- const redirectTo = searchParams.get('redirect_to')
- const paramView = searchParams.get('view')
+ const redirectTo = searchParams?.get('redirect_to') || undefined
+ const paramView = searchParams?.get('view')
const router = useRouter()
- const [view, setView] = useState<ViewType>(getView(paramView))
+ const [view, setView] = useState<ViewType>(getView(paramView ?? 'sign-in'))
const user = useUser()
useEffect(function redirect() {
- if (user.user) {
+ if (user.user && redirectTo) {
router.push(redirectTo)
}
}, [user.user, router, redirectTo])
diff --git a/apps/docs/src/components/Banner.tsx b/apps/docs/src/components/Banner.tsx
index 8162ad45a..bb04a4a7c 100644
--- a/apps/docs/src/components/Banner.tsx
+++ b/apps/docs/src/components/Banner.tsx
@@ -15,7 +15,7 @@ const fetcher = (url: string) => fetch(url).then((res) => res.json())
export function Banner() {
const { user } = useUser()
- const { data, error, isLoading } = useSWR<Promo>(`/docs/pricing/promo?${new URLSearchParams({ id: user?.pricingTier.id })}`, fetcher)
+ const { data, error, isLoading } = useSWR<Promo>(`/docs/pricing/promo?${new URLSearchParams({ id: user?.pricingTier.id ?? '' })}`, fetcher)
if (isLoading) return null
@@ -26,6 +26,10 @@ export function Banner() {
if (!user?.pricingTier.isPromo) return null
+ if (!data) {
+ return null
+ }
+
return (
<div className="py-2 px-8 border-y border-zinc-700 flex flex-col md:flex-row gap-1 fixed inset-x-0 top-[55px] bg-zinc-800 z-40">
<span className="text-sm">You&apos;re on a <b>trial</b> Pro tier. <b>Your trial will end on {new Date(data.validTo).toLocaleDateString()}.</b></span>
diff --git a/apps/docs/src/components/Code.tsx b/apps/docs/src/components/Code.tsx
index 153dd1628..08bfd3ffd 100644
--- a/apps/docs/src/components/Code.tsx
+++ b/apps/docs/src/components/Code.tsx
@@ -165,7 +165,7 @@ export function CodeGroupHeader({
unoptimized
/>
)}
- {getPanelTitle(isValidElement(child) ? child.props : {})}
+ {getPanelTitle(isValidElement(child) ? child.props : {} as any)}
</div>
</Tab>
))}
@@ -314,7 +314,7 @@ export function CodeGroup({
const header = (
<CodeGroupHeader
- title={title}
+ title={title ?? ''}
selectedIndex={tabGroupProps.selectedIndex}
isFileName={isFileName}
isTerminalCommand={isTerminalCommand}
@@ -328,7 +328,7 @@ export function CodeGroup({
<CodeGroupContext.Provider
value={{
path,
- }}
+ } as any}
>
{hasTabs ? (
<Tab.Group {...tabGroupProps} className={containerClassName}>
diff --git a/apps/docs/src/components/CopyButton.tsx b/apps/docs/src/components/CopyButton.tsx
index 735809664..a633eac5c 100644
--- a/apps/docs/src/components/CopyButton.tsx
+++ b/apps/docs/src/components/CopyButton.tsx
@@ -22,11 +22,11 @@ function ClipboardIcon(props) {
}
export function CopyButton({
- code,
- customPositionClassNames = 'right-4 top-3.5', // default from TailwindUI, works great with code blocks
- onAfterCopy = () => {
- },
- }) {
+ code,
+ customPositionClassNames = 'right-4 top-3.5', // default from TailwindUI, works great with code blocks
+ onAfterCopy = () => {
+ },
+}) {
const buttonRef = useRef()
const [copyCount, setCopyCount] = useState(0)
const copied = copyCount > 0
@@ -47,7 +47,7 @@ export function CopyButton({
return (
<button
type="button"
- ref={buttonRef}
+ ref={buttonRef as any}
tabIndex={-1} /* hide from tab order */
className={clsx(
customPositionClassNames,
@@ -71,7 +71,7 @@ export function CopyButton({
)}
>
<ClipboardIcon
- className="h-5 w-5 fill-zinc-500/20 stroke-zinc-500 transition-colors group-hover/button:stroke-zinc-400"/>
+ className="h-5 w-5 fill-zinc-500/20 stroke-zinc-500 transition-colors group-hover/button:stroke-zinc-400" />
Copy
</span>
<span
diff --git a/apps/docs/src/components/Header.tsx b/apps/docs/src/components/Header.tsx
index 5d44d8fbe..9b0113635 100644
--- a/apps/docs/src/components/Header.tsx
+++ b/apps/docs/src/components/Header.tsx
@@ -41,14 +41,14 @@ export const Header = forwardRef(function Header({ className, isAuth }, ref) {
fetch(config.github.api)
.then(response => response.json())
.then(data => setGithubStars(data.stargazers_count))
- .catch(() => setGithubStars(false))
+ .catch(() => setGithubStars(null))
}, [setGithubStars])
useEffect(() => {
fetch(config.discord.api)
.then(response => response.json())
.then(async data => setDiscordUsers(data.presence_count))
- .catch(() => setDiscordUsers(false))
+ .catch(() => setDiscordUsers(null))
}, [setDiscordUsers])
// TODO: Maybe add Twitter followers count?
diff --git a/apps/docs/src/components/LanguageSpecificText.tsx b/apps/docs/src/components/LanguageSpecificText.tsx
index e0090c8d1..103873375 100644
--- a/apps/docs/src/components/LanguageSpecificText.tsx
+++ b/apps/docs/src/components/LanguageSpecificText.tsx
@@ -17,7 +17,7 @@ export function LanguageSpecificText({
}: Props) {
const languages =
Children.map(children, child =>
- getPanelTitle(isValidElement(child) ? child.props : {}),
+ getPanelTitle(isValidElement(child) ? child.props : {} as any),
) ?? []
const tabGroupProps = useTabGroupProps(languages)
diff --git a/apps/docs/src/components/Layout.tsx b/apps/docs/src/components/Layout.tsx
index 7438ff671..9f94c6ccd 100644
--- a/apps/docs/src/components/Layout.tsx
+++ b/apps/docs/src/components/Layout.tsx
@@ -20,12 +20,12 @@ export function Layout({
}) {
const { user } = useUser()
const pathname = usePathname()
- const relativePathname = pathname.replace(new RegExp('^/docs'), '')
+ const relativePathname = pathname?.replace(new RegExp('^/docs'), '')
const shouldShowBanner = user?.pricingTier.isPromo
- const isAuth = relativePathname.startsWith('/sign-in')
+ const isAuth = relativePathname?.startsWith('/sign-in')
return (
- <SectionProvider sections={allSections[relativePathname] ?? []}>
+ <SectionProvider sections={relativePathname ? allSections[relativePathname] ?? [] : []}>
<div className={clsx('h-full', { 'lg:ml-[var(--sidebar-nav-width)]': !isAuth })}>
<motion.header
layoutScroll
diff --git a/apps/docs/src/components/ManageBilling.tsx b/apps/docs/src/components/ManageBilling.tsx
index 43d23c8b6..1e9dddc54 100644
--- a/apps/docs/src/components/ManageBilling.tsx
+++ b/apps/docs/src/components/ManageBilling.tsx
@@ -16,7 +16,7 @@ function ManageBilling() {
}, [user])
if (!user || !url) {
- return
+ return null
}
return (
diff --git a/apps/docs/src/components/Navigation/canonical.tsx b/apps/docs/src/components/Navigation/canonical.tsx
index 7f4f6c77c..415709b7d 100644
--- a/apps/docs/src/components/Navigation/canonical.tsx
+++ b/apps/docs/src/components/Navigation/canonical.tsx
@@ -5,7 +5,7 @@ import { usePathname } from 'next/navigation'
export default function Canonical() {
const pathname = usePathname()
- const pathWithoutTrailingSlash = pathname.endsWith('/') ? pathname.slice(0, -1) : pathname
+ const pathWithoutTrailingSlash = pathname?.endsWith('/') ? pathname.slice(0, -1) : pathname
const canonicalUrl = 'https://e2b.dev' + pathWithoutTrailingSlash
return <link rel="canonical" href={canonicalUrl} />
diff --git a/apps/docs/src/components/Navigation/index.tsx b/apps/docs/src/components/Navigation/index.tsx
index 479b77d34..e20e80e99 100644
--- a/apps/docs/src/components/Navigation/index.tsx
+++ b/apps/docs/src/components/Navigation/index.tsx
@@ -29,9 +29,9 @@ function useInitialValue<T>(value: T, condition = true) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function TopLevelNavItem({
- href,
- children,
- }: {
+ href,
+ children,
+}: {
href: string
children: React.ReactNode
}) {
@@ -48,15 +48,15 @@ function TopLevelNavItem({
}
function NavLink({
- className,
- href,
- children,
- tag,
- icon,
- active = false,
- isAnchorLink = false,
- isFontMono = false,
- }: {
+ className,
+ href,
+ children,
+ tag,
+ icon,
+ active = false,
+ isAnchorLink = false,
+ isFontMono = false,
+}: {
className?: string
href: string
children: React.ReactNode
@@ -162,6 +162,11 @@ function NavigationGroup({ group, className }) {
[initialPathname, useSectionStore(s => s.sections)],
isInsideMobileNavigation,
)
+
+ if (!pathname) {
+ return null
+ }
+
const isActiveGroup = activeGroupIndex(group, pathname) !== -1
return (
@@ -275,7 +280,7 @@ export function Navigation(props) {
/>
))}
<li className="z-10 mt-6">
- <Feedback className="w-full"/>
+ <Feedback className="w-full" />
</li>
<li
/* -1.5rem to stretch outside the padding of the parent list */
@@ -285,7 +290,7 @@ export function Navigation(props) {
min-[540px]:hidden
"
>
- <Auth/>
+ <Auth />
</li>
</ul>
</nav>
diff --git a/apps/docs/src/components/SectionProvider.tsx b/apps/docs/src/components/SectionProvider.tsx
index 023eab5a5..f74e66fed 100644
--- a/apps/docs/src/components/SectionProvider.tsx
+++ b/apps/docs/src/components/SectionProvider.tsx
@@ -19,10 +19,10 @@ interface SectionState {
visibleSections: Array<string>
setVisibleSections: (visibleSections: Array<string>) => void
registerHeading: ({
- id,
- ref,
- offsetRem,
- }: {
+ id,
+ ref,
+ offsetRem,
+ }: {
id: string
ref: React.RefObject<HTMLHeadingElement>
offsetRem: number
@@ -65,7 +65,7 @@ function useVisibleSections(sectionStore: StoreApi<SectionState>) {
useEffect(() => {
function checkVisibleSections() {
const { innerHeight, scrollY } = window
- const newVisibleSections = []
+ const newVisibleSections: any[] = []
for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
const { id, headingRef, offsetRem = 0 } = sections[sectionIndex]
@@ -117,9 +117,9 @@ const useIsomorphicLayoutEffect =
typeof window === 'undefined' ? useEffect : useLayoutEffect
export function SectionProvider({
- sections,
- children,
- }: {
+ sections,
+ children,
+}: {
sections: Array<Section>
children: React.ReactNode
}) {
diff --git a/apps/docs/src/components/Textarea.tsx b/apps/docs/src/components/Textarea.tsx
index ba3290955..0e09bda57 100644
--- a/apps/docs/src/components/Textarea.tsx
+++ b/apps/docs/src/components/Textarea.tsx
@@ -10,7 +10,7 @@ import { useEffect, useRef } from 'react'
// }
function Textarea({ value = '', className, placeholder, onChange, isOpen }) {
- const ref = useRef(null)
+ const ref = useRef<HTMLTextAreaElement>(null)
useEffect(
function handleFocus() {
diff --git a/apps/docs/src/utils/usePostHog.tsx b/apps/docs/src/utils/usePostHog.tsx
index ff1653315..b004e0e33 100644
--- a/apps/docs/src/utils/usePostHog.tsx
+++ b/apps/docs/src/utils/usePostHog.tsx
@@ -44,7 +44,7 @@ export function PostHogAnalytics() {
useEffect(() => {
if (pathname) {
let url = window.origin + pathname
- if (searchParams.toString()) url = url + `?${searchParams.toString()}`
+ if (searchParams?.toString()) url = url + `?${searchParams.toString()}`
posthog?.capture('$pageview', { $current_url: url })
}
}, [pathname, searchParams])
@@ -53,7 +53,9 @@ export function PostHogAnalytics() {
if (user) {
posthog?.identify(user.id, { email: user.email })
// TODO: When we add teams, make sure to change this
- posthog?.group('team', defaultTeamId, {name: user?.teams?.[0]?.name })
+ if (!defaultTeamId) return
+
+ posthog?.group('team', defaultTeamId, { name: user?.teams?.[0]?.name })
}
}, [user, defaultTeamId])
diff --git a/apps/docs/src/utils/useUsage.tsx b/apps/docs/src/utils/useUsage.tsx
index cc2e6cf42..58109ef69 100644
--- a/apps/docs/src/utils/useUsage.tsx
+++ b/apps/docs/src/utils/useUsage.tsx
@@ -21,7 +21,7 @@ const usageUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/usage`
export function useUsage() {
const { user } = useUser()
const apiKey = useApiKey()
- const [credits, setCredits] = useState(null)
+ const [credits, setCredits] = useState<number | null>(null)
const [usage, setUsage] = useState<MonthlyCosts[]>([])
const [isLoading, setIsLoading] = useState(true)
const supabase = createPagesBrowserClient()
diff --git a/apps/docs/src/utils/useUser.tsx b/apps/docs/src/utils/useUser.tsx
index 0d19402ab..e845474de 100644
--- a/apps/docs/src/utils/useUser.tsx
+++ b/apps/docs/src/utils/useUser.tsx
@@ -41,8 +41,8 @@ export const UserContext = createContext(undefined)
export const CustomUserContextProvider = (props) => {
const supabase = createPagesBrowserClient()
const [session, setSession] = useState<Session | null>(null)
- const [user, setUser] = useState(null)
- const [error, setError] = useState(null)
+ const [user, setUser] = useState<any>()
+ const [error, setError] = useState<any>(null)
const [isLoading, setIsLoading] = useState(true)
const mounted = useRef<boolean>(false)
@@ -137,7 +137,7 @@ export const CustomUserContextProvider = (props) => {
const { data: apiKeys, error: apiKeysError } = await supabase
.from('team_api_keys')
.select('*')
- .in('team_id', teams?.map((team) => team.id)) // Due to RLS, we could also safely just fetch all, but let's be explicit for sure
+ .in('team_id', (teams?.map((team) => team.id) as any)) // Due to RLS, we could also safely just fetch all, but let's be explicit for sure
if (apiKeysError) Sentry.captureException(apiKeysError)
const defaultTeamId = defaultTeam?.id // TODO: Adjust when user can be part of multiple teams
@@ -152,15 +152,15 @@ export const CustomUserContextProvider = (props) => {
setUser({
...session?.user,
- teams,
- apiKeys,
+ teams: teams ?? [],
+ apiKeys: apiKeys ?? [],
accessToken: accessToken?.access_token,
defaultTeamId,
error: teamsError || apiKeysError,
pricingTier: {
id: pricingTier,
isPromo: isPromoTier,
- endsAt: promoEndsAt,
+ ...(isPromoTier ? { endsAt: promoEndsAt } : {})
},
})
setIsLoading(false)
@@ -213,7 +213,7 @@ export const useApiKey = (): string => {
return user?.apiKeys?.[0]?.api_key
}
-export const useAccessToken = (): string => {
+export const useAccessToken = () => {
// for convenience
const { user } = useUser()
return user?.accessToken
diff --git a/apps/docs/tsconfig.json b/apps/docs/tsconfig.json
index 00c895324..40d28762a 100644
--- a/apps/docs/tsconfig.json
+++ b/apps/docs/tsconfig.json
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es6",
- "lib": ["dom", "dom.iterable", "esnext"],
+ "lib": [
+ "dom",
+ "dom.iterable",
+ "esnext"
+ ],
"allowJs": true,
"skipLibCheck": true,
"strict": false, // originally true
@@ -20,9 +24,20 @@
}
],
"paths": {
- "@/*": ["./src/*"]
- }
+ "@/*": [
+ "./src/*"
+ ]
+ },
+ "strictNullChecks": true
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
- "exclude": ["node_modules", "src/code"]
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ ".next/types/**/*.ts"
+ ],
+ "exclude": [
+ "node_modules",
+ "src/code"
+ ]
}