mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 17:26:36 +00:00
Merge pull request #3180 from Infisical/daniel/fix-vercel-custom-envs
fix: vercel integration custom envs
This commit is contained in:
@@ -134,7 +134,15 @@ const getAppsHeroku = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
* Return list of names of apps for Vercel integration
|
* Return list of names of apps for Vercel integration
|
||||||
* This is re-used for getting custom environments for Vercel
|
* This is re-used for getting custom environments for Vercel
|
||||||
*/
|
*/
|
||||||
export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string | null; accessToken: string }) => {
|
export const getAppsVercel = async ({
|
||||||
|
accessToken,
|
||||||
|
teamId,
|
||||||
|
includeCustomEnvironments
|
||||||
|
}: {
|
||||||
|
teamId?: string | null;
|
||||||
|
accessToken: string;
|
||||||
|
includeCustomEnvironments?: boolean;
|
||||||
|
}) => {
|
||||||
const apps: Array<{ name: string; appId: string; customEnvironments: Array<{ slug: string; id: string }> }> = [];
|
const apps: Array<{ name: string; appId: string; customEnvironments: Array<{ slug: string; id: string }> }> = [];
|
||||||
|
|
||||||
const limit = "20";
|
const limit = "20";
|
||||||
@@ -145,12 +153,6 @@ export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string |
|
|||||||
projects: {
|
projects: {
|
||||||
name: string;
|
name: string;
|
||||||
id: string;
|
id: string;
|
||||||
customEnvironments?: {
|
|
||||||
id: string;
|
|
||||||
type: string;
|
|
||||||
description: string;
|
|
||||||
slug: string;
|
|
||||||
}[];
|
|
||||||
}[];
|
}[];
|
||||||
pagination: {
|
pagination: {
|
||||||
count: number;
|
count: number;
|
||||||
@@ -159,6 +161,20 @@ export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string |
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getProjectCustomEnvironments = async (projectId: string) => {
|
||||||
|
const { data } = await request.get<{ environments: { id: string; slug: string }[] }>(
|
||||||
|
`${IntegrationUrls.VERCEL_API_URL}/v9/projects/${projectId}/custom-environments`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
"Accept-Encoding": "application/json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return data.environments;
|
||||||
|
};
|
||||||
|
|
||||||
while (hasMorePages) {
|
while (hasMorePages) {
|
||||||
const params: { [key: string]: string } = {
|
const params: { [key: string]: string } = {
|
||||||
limit
|
limit
|
||||||
@@ -180,17 +196,38 @@ export const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string |
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
data.projects.forEach((a) => {
|
if (includeCustomEnvironments) {
|
||||||
apps.push({
|
const projectsWithCustomEnvironments = await Promise.all(
|
||||||
name: a.name,
|
data.projects.map(async (a) => {
|
||||||
appId: a.id,
|
const customEnvironments = await getProjectCustomEnvironments(a.id);
|
||||||
customEnvironments:
|
|
||||||
a.customEnvironments?.map((env) => ({
|
return {
|
||||||
slug: env.slug,
|
...a,
|
||||||
id: env.id
|
customEnvironments
|
||||||
})) ?? []
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
projectsWithCustomEnvironments.forEach((a) => {
|
||||||
|
apps.push({
|
||||||
|
name: a.name,
|
||||||
|
appId: a.id,
|
||||||
|
customEnvironments:
|
||||||
|
a.customEnvironments?.map((env) => ({
|
||||||
|
slug: env.slug,
|
||||||
|
id: env.id
|
||||||
|
})) ?? []
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
data.projects.forEach((a) => {
|
||||||
|
apps.push({
|
||||||
|
name: a.name,
|
||||||
|
appId: a.id,
|
||||||
|
customEnvironments: []
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
next = data.pagination.next;
|
next = data.pagination.next;
|
||||||
|
|
||||||
|
|||||||
@@ -1851,6 +1851,7 @@ export const integrationAuthServiceFactory = ({
|
|||||||
const { accessToken } = await getIntegrationAccessToken(integrationAuth, shouldUseSecretV2Bridge, botKey);
|
const { accessToken } = await getIntegrationAccessToken(integrationAuth, shouldUseSecretV2Bridge, botKey);
|
||||||
|
|
||||||
const vercelApps = await getAppsVercel({
|
const vercelApps = await getAppsVercel({
|
||||||
|
includeCustomEnvironments: true,
|
||||||
accessToken,
|
accessToken,
|
||||||
teamId
|
teamId
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user