Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: limit vercel projects returned

Daniel Hougaarde4053722743a
diff --git a/backend/src/main.ts b/backend/src/main.ts
index 400804804a..c6af8e0e3d 100644
--- a/backend/src/main.ts
+++ b/backend/src/main.ts
@@ -2,6 +2,7 @@
// If you rename the import, update the Dockerfile.fips.standalone-infisical file as well.
import "./lib/telemetry/instrumentation";
+import axios from "axios";
import dotenv from "dotenv";
import { initializeHsmModule } from "@app/ee/services/hsm/hsm-fns";
@@ -15,6 +16,7 @@ import { formatSmtpConfig, getDatabaseCredentials, getHsmConfig, initEnvConfig }
import { buildRedisFromConfig } from "./lib/config/redis";
import { removeTemporaryBaseDirectory } from "./lib/files";
import { initLogger } from "./lib/logger";
+import { CustomLogger } from "./lib/logger/logger";
import { queueServiceFactory } from "./queue";
import { main } from "./server/app";
import { bootstrapCheck } from "./server/boot-strap-check";
@@ -24,10 +26,32 @@ import { superAdminDALFactory } from "./services/super-admin/super-admin-dal";
dotenv.config();
+const setupAxiosResponseInterceptor = (logger: CustomLogger) => {
+ axios.interceptors.response.use((response) => {
+ try {
+ const contentLength = response.headers["content-length"] as string | undefined;
+ const responseSize = contentLength ? parseInt(contentLength, 10) : 0;
+
+ let megabyteSize = "";
+
+ if (responseSize && responseSize > 1024 * 1024) {
+ megabyteSize = `Large payload: ${(responseSize / 1024 / 1024).toFixed(2)} MB`;
+ }
+
+ logger.info({ url: response.config.url, responseSize }, `Intercepted axios response ${megabyteSize}`);
+ } catch (error) {
+ logger.error(error, "Error intercepting axios response");
+ }
+
+ return response;
+ });
+};
+
const run = async () => {
const logger = initLogger();
await removeTemporaryBaseDirectory();
+ setupAxiosResponseInterceptor(logger);
const hsmConfig = getHsmConfig(logger);
const hsmModule = initializeHsmModule(hsmConfig);
diff --git a/backend/src/server/routes/v1/app-connection-routers/vercel-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/vercel-connection-router.ts
index 079870305d..e249c5fe28 100644
--- a/backend/src/server/routes/v1/app-connection-routers/vercel-connection-router.ts
+++ b/backend/src/server/routes/v1/app-connection-routers/vercel-connection-router.ts
@@ -33,6 +33,9 @@ export const registerVercelConnectionRouter = async (server: FastifyZodProvider)
params: z.object({
connectionId: z.string().uuid()
}),
+ querystring: z.object({
+ projectSearch: z.string().optional()
+ }),
response: {
200: z
.object({
@@ -65,10 +68,12 @@ export const registerVercelConnectionRouter = async (server: FastifyZodProvider)
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const { connectionId } = req.params;
+ const { projectSearch } = req.query;
const projects: VercelOrgWithApps[] = await server.services.appConnection.vercel.listProjects(
connectionId,
- req.permission
+ req.permission,
+ projectSearch
);
return projects;
diff --git a/backend/src/services/app-connection/vercel/vercel-connection-fns.ts b/backend/src/services/app-connection/vercel/vercel-connection-fns.ts
index 01eac84dcc..76ad52759a 100644
--- a/backend/src/services/app-connection/vercel/vercel-connection-fns.ts
+++ b/backend/src/services/app-connection/vercel/vercel-connection-fns.ts
@@ -59,17 +59,24 @@ interface ApiResponse<T> {
[key: string]: unknown;
}
-async function fetchAllPages<T>(
- apiUrl: string,
- apiToken: string,
- initialParams: Record<string, string | number> = {},
- dataPath?: string
-): Promise<T[]> {
+async function fetchAllPages<T>({
+ apiUrl,
+ apiToken,
+ initialParams,
+ dataPath,
+ maxItems
+}: {
+ apiUrl: string;
+ apiToken: string;
+ initialParams?: Record<string, string | number>;
+ dataPath?: string;
+ maxItems?: number;
+}): Promise<T[]> {
const allItems: T[] = [];
let hasMoreItems = true;
- let params: Record<string, string | number> = { ...initialParams, limit: 100 };
+ let params: Record<string, string | number> = { limit: 100, ...initialParams };
- while (hasMoreItems) {
+ while (hasMoreItems && (!maxItems || allItems.length < maxItems)) {
try {
const response = await request.get<ApiResponse<T>>(apiUrl, {
params,
@@ -119,13 +126,19 @@ async function fetchAllPages<T>(
return allItems;
}
-async function fetchOrgProjects(orgId: string, apiToken: string): Promise<VercelApp[]> {
- return fetchAllPages<VercelApp>(
- `${IntegrationUrls.VERCEL_API_URL}/v9/projects`,
+async function fetchOrgProjects(orgId: string, apiToken: string, projectSearch?: string): Promise<VercelApp[]> {
+ const params: Record<string, string | number> = {
+ teamId: orgId,
+ ...(projectSearch ? { search: projectSearch } : {}),
+ limit: 10
+ };
+ return fetchAllPages<VercelApp>({
+ apiUrl: `${IntegrationUrls.VERCEL_API_URL}/v10/projects`,
apiToken,
- { teamId: orgId },
- "projects"
- );
+ initialParams: params,
+ dataPath: "projects",
+ maxItems: 10
+ });
}
async function fetchProjectEnvironments(
@@ -134,12 +147,12 @@ async function fetchProjectEnvironments(
apiToken: string
): Promise<VercelEnvironment[]> {
try {
- return await fetchAllPages<VercelEnvironment>(
- `${IntegrationUrls.VERCEL_API_URL}/v9/projects/${projectId}/custom-environments?teamId=${teamId}`,
- apiToken,
- {},
- "environments"
- );
+ return await fetchAllPages<VercelEnvironment>({
+ apiUrl: `${IntegrationUrls.VERCEL_API_URL}/v10/projects/${projectId}/custom-environments?teamId=${teamId}`,
+ initialParams: {},
+ dataPath: "environments",
+ apiToken
+ });
} catch (error) {
return [];
}
@@ -179,11 +192,19 @@ type VercelUserResponse = {
};
};
-export const listProjects = async (appConnection: TVercelConnection): Promise<VercelOrgWithApps[]> => {
+export const listProjects = async (
+ appConnection: TVercelConnection,
+ projectSearch?: string
+): Promise<VercelOrgWithApps[]> => {
const { credentials } = appConnection;
const { apiToken } = credentials;
- const orgs = await fetchAllPages<VercelTeam>(`${IntegrationUrls.VERCEL_API_URL}/v2/teams`, apiToken, {}, "teams");
+ const orgs = await fetchAllPages<VercelTeam>({
+ apiUrl: `${IntegrationUrls.VERCEL_API_URL}/v2/teams`,
+ apiToken,
+ initialParams: {},
+ dataPath: "teams"
+ });
const personalAccountResponse = await request.get<VercelUserResponse>(`${IntegrationUrls.VERCEL_API_URL}/v2/user`, {
headers: {
@@ -205,7 +226,7 @@ export const listProjects = async (appConnection: TVercelConnection): Promise<Ve
const orgPromises = orgs.map(async (org) => {
try {
- const projects = await fetchOrgProjects(org.id, apiToken);
+ const projects = await fetchOrgProjects(org.id, apiToken, projectSearch);
const enhancedProjectsPromises = projects.map(async (project) => {
try {
diff --git a/backend/src/services/app-connection/vercel/vercel-connection-service.ts b/backend/src/services/app-connection/vercel/vercel-connection-service.ts
index 68e5215e9f..cffeac3ecd 100644
--- a/backend/src/services/app-connection/vercel/vercel-connection-service.ts
+++ b/backend/src/services/app-connection/vercel/vercel-connection-service.ts
@@ -12,10 +12,10 @@ type TGetAppConnectionFunc = (
) => Promise<TVercelConnection>;
export const vercelConnectionService = (getAppConnection: TGetAppConnectionFunc) => {
- const listProjects = async (connectionId: string, actor: OrgServiceActor) => {
+ const listProjects = async (connectionId: string, actor: OrgServiceActor, projectSearch?: string) => {
const appConnection = await getAppConnection(AppConnection.Vercel, connectionId, actor);
try {
- const projects = await getVercelProjects(appConnection);
+ const projects = await getVercelProjects(appConnection, projectSearch);
return projects;
} catch (error) {
logger.error(error, "Failed to establish connection with Vercel");
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx
index 61013483f4..33d555101d 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/VercelSyncFields.tsx
@@ -1,4 +1,4 @@
-import { useMemo } from "react";
+import { useMemo, useState } from "react";
import { Controller, useFormContext, useWatch } from "react-hook-form";
import { SingleValue } from "react-select";
import { faCircleInfo } from "@fortawesome/free-solid-svg-icons";
@@ -7,6 +7,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
import { FilterableSelect, FormControl, Tooltip } from "@app/components/v2";
import { CreatableSelect } from "@app/components/v2/CreatableSelect";
+import { useDebounce } from "@app/hooks";
import {
TVercelConnectionApp,
useVercelConnectionListOrganizations
@@ -26,12 +27,16 @@ export const VercelSyncFields = () => {
TSecretSyncForm & { destination: SecretSync.Vercel }
>();
+ const [projectSearch, setProjectSearch] = useState("");
+ const [debouncedProjectSearch] = useDebounce(projectSearch, 300);
+
const connectionId = useWatch({ name: "connection.id", control });
const currentApp = watch("destinationConfig.app");
const currentEnv = watch("destinationConfig.env");
const { data: projects, isLoading: isProjectsLoading } = useVercelConnectionListOrganizations(
connectionId,
+ debouncedProjectSearch,
{
enabled: Boolean(connectionId)
}
@@ -92,7 +97,18 @@ export const VercelSyncFields = () => {
helperText={
<Tooltip
className="max-w-md"
- content="Ensure the project exists and the API token scope for this connection includes the desired project."
+ content={
+ <div className="flex flex-col gap-2">
+ <span>
+ Ensure the project exists and the API token scope for this connection includes
+ the desired project.
+ </span>
+ <span>
+ Use the search bar to filter projects by name. By default only 10 projects are
+ shown, but you can search for more projects by name.
+ </span>
+ </div>
+ }
>
<div>
<span>Don&#39;t see the project you&#39;re looking for?</span>{" "}
@@ -119,6 +135,8 @@ export const VercelSyncFields = () => {
(option as SingleValue<TVercelConnectionApp>)?.name || ""
);
}}
+ onInputChange={(newValue) => setProjectSearch(newValue)}
+ filterOption={null}
options={allApps}
placeholder="Select a project..."
getOptionLabel={(option) => option.name}
diff --git a/frontend/src/hooks/api/appConnections/vercel/queries.tsx b/frontend/src/hooks/api/appConnections/vercel/queries.tsx
index fa66adcdb3..6f251970ca 100644
--- a/frontend/src/hooks/api/appConnections/vercel/queries.tsx
+++ b/frontend/src/hooks/api/appConnections/vercel/queries.tsx
@@ -7,12 +7,13 @@ import { TVercelConnectionOrganization } from "./types";
const vercelConnectionKeys = {
all: [...appConnectionKeys.all, "vercel"] as const,
- listOrganizations: (connectionId: string) =>
- [...vercelConnectionKeys.all, "organizations", connectionId] as const
+ listOrganizations: (connectionId: string, projectSearch?: string) =>
+ [...vercelConnectionKeys.all, "organizations", connectionId, { projectSearch }] as const
};
export const useVercelConnectionListOrganizations = (
connectionId: string,
+ projectSearch?: string,
options?: Omit<
UseQueryOptions<
TVercelConnectionOrganization[],
@@ -24,10 +25,15 @@ export const useVercelConnectionListOrganizations = (
>
) => {
return useQuery({
- queryKey: vercelConnectionKeys.listOrganizations(connectionId),
+ queryKey: vercelConnectionKeys.listOrganizations(connectionId, projectSearch),
queryFn: async () => {
const { data } = await apiRequest.get<TVercelConnectionOrganization[]>(
- `/api/v1/app-connections/vercel/${connectionId}/projects`
+ `/api/v1/app-connections/vercel/${connectionId}/projects`,
+ {
+ params: {
+ projectSearch
+ }
+ }
);
return data;