Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { useEffect, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
import { PageTitle } from "@app/components/PageTitle";
import {
Button,
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
Field,
FieldLabel,
SecretPathInput,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue
} from "@app/components/v3";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useCreateIntegration } from "@app/hooks/api";
import {
useGetIntegrationAuthApps,
useGetIntegrationAuthById
} from "@app/hooks/api/integrationAuth";
import { IntegrationsListPageTabs } from "@app/types/integrations";
export const CloudflareWorkersConfigurePage = () => {
const navigate = useNavigate();
const { mutateAsync } = useCreateIntegration();
const { currentProject } = useProject();
const { currentOrg } = useOrganization();
const integrationAuthId = useSearch({
from: ROUTE_PATHS.SecretManager.Integratons.CloudflareWorkersConfigurePage.id,
select: (el) => el.integrationAuthId
});
const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? "");
const { data: integrationAuthApps } = useGetIntegrationAuthApps({
integrationAuthId: (integrationAuthId as string) ?? ""
});
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState(
currentProject.environments[0].slug
);
const [secretPath, setSecretPath] = useState("/");
const [targetApp, setTargetApp] = useState("");
const [targetAppId, setTargetAppId] = useState("");
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
if (integrationAuthApps) {
if (integrationAuthApps.length > 0) {
setTargetApp(integrationAuthApps[0].name);
setTargetAppId(String(integrationAuthApps[0].appId));
} else {
setTargetApp("none");
}
}
}, [integrationAuthApps]);
const handleButtonClick = async () => {
try {
if (!integrationAuth?.id) return;
setIsLoading(true);
await mutateAsync({
integrationAuthId: integrationAuth?.id,
isActive: true,
app: targetApp,
appId: targetAppId,
sourceEnvironment: selectedSourceEnvironment,
secretPath
});
setIsLoading(false);
navigate({
to: "/organizations/$orgId/projects/secret-management/$projectId/integrations",
params: {
orgId: currentOrg.id,
projectId: currentProject.id
},
search: {
selectedTab: IntegrationsListPageTabs.NativeIntegrations
}
});
} catch {
setIsLoading(false);
}
};
return integrationAuth && selectedSourceEnvironment && integrationAuthApps && targetApp ? (
<div className="flex h-full w-full items-center justify-center bg-linear-to-tr from-surface-base to-page-deep">
<PageTitle title="Set Up Cloudflare Workers Integration" />
<Card className="w-full max-w-lg">
<CardHeader>
<CardTitle>Cloudflare Workers Integration</CardTitle>
<CardDescription>
Choose which environment in Infisical you want to sync with your Cloudflare Workers
project.
</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-5">
<Field className="mt-2" data-invalid={false}>
<FieldLabel htmlFor="cloudflareworkers-infisical-project-environment">
Infisical Project Environment
</FieldLabel>
<Select
value={selectedSourceEnvironment}
onValueChange={(val) => setSelectedSourceEnvironment(val)}
>
<SelectTrigger
className="w-full"
id="cloudflareworkers-infisical-project-environment"
>
<SelectValue />
</SelectTrigger>
<SelectContent>
{currentProject?.environments.map((sourceEnvironment) => (
<SelectItem
value={sourceEnvironment.slug}
key={`source-environment-${sourceEnvironment.slug}`}
>
{sourceEnvironment.name}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<Field className="mt-2" data-invalid={false}>
<FieldLabel htmlFor="cloudflareworkers-infisical-secret-path">
Infisical Secret Path
</FieldLabel>
<SecretPathInput
value={secretPath}
onChange={(value) => setSecretPath(value)}
environment={selectedSourceEnvironment}
placeholder="Provide a path, default is /"
id="cloudflareworkers-infisical-secret-path"
/>
</Field>
<Field className="mt-4" data-invalid={false}>
<FieldLabel htmlFor="cloudflareworkers-cloudflare-workers-project">
Cloudflare Workers Project
</FieldLabel>
<Select
value={targetApp}
onValueChange={(val) => setTargetApp(val)}
disabled={integrationAuthApps.length === 0}
>
<SelectTrigger className="w-full" id="cloudflareworkers-cloudflare-workers-project">
<SelectValue />
</SelectTrigger>
<SelectContent>
{integrationAuthApps.length > 0 ? (
integrationAuthApps.map((integrationAuthApp) => (
<SelectItem
value={integrationAuthApp.name}
key={`target-app-${integrationAuthApp.name}`}
>
{integrationAuthApp.name}
</SelectItem>
))
) : (
<SelectItem value="none" key="target-app-none">
No apps found
</SelectItem>
)}
</SelectContent>
</Select>
</Field>
</CardContent>
<CardFooter className="justify-end">
<Button onClick={handleButtonClick} isPending={isLoading} variant="project">
Create Integration
</Button>
</CardFooter>
</Card>
</div>
) : (
<>
<PageTitle title="Set Up Cloudflare Workers Integration" />
<div />
</>
);
};