mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 20:27:12 +00:00
Add pagination to getAppsVercel
This commit is contained in:
@@ -129,26 +129,55 @@ const getAppsHeroku = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
* Return list of names of apps for Vercel integration
|
* Return list of names of apps for Vercel integration
|
||||||
*/
|
*/
|
||||||
const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string | null; accessToken: string }) => {
|
const getAppsVercel = async ({ accessToken, teamId }: { teamId?: string | null; accessToken: string }) => {
|
||||||
const res = (
|
const apps: Array<{ name: string; appId: string }> = [];
|
||||||
await request.get<{ projects: { name: string; id: string }[] }>(`${IntegrationUrls.VERCEL_API_URL}/v9/projects`, {
|
|
||||||
|
const limit = "20";
|
||||||
|
let hasMorePages = true;
|
||||||
|
let next: number | null = null;
|
||||||
|
|
||||||
|
interface Response {
|
||||||
|
projects: { name: string; id: string }[];
|
||||||
|
pagination: {
|
||||||
|
count: number;
|
||||||
|
next: number | null;
|
||||||
|
prev: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
while (hasMorePages) {
|
||||||
|
const params: { [key: string]: string } = {
|
||||||
|
limit
|
||||||
|
};
|
||||||
|
|
||||||
|
if (teamId) {
|
||||||
|
params.teamId = teamId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
params.until = String(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await request.get<Response>(`${IntegrationUrls.VERCEL_API_URL}/v9/projects`, {
|
||||||
|
params: new URLSearchParams(params),
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
"Accept-Encoding": "application/json"
|
"Accept-Encoding": "application/json"
|
||||||
},
|
}
|
||||||
...(teamId
|
});
|
||||||
? {
|
|
||||||
params: {
|
|
||||||
teamId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
: {})
|
|
||||||
})
|
|
||||||
).data;
|
|
||||||
|
|
||||||
const apps = res.projects.map((a) => ({
|
data.projects.forEach((a) => {
|
||||||
name: a.name,
|
apps.push({
|
||||||
appId: a.id
|
name: a.name,
|
||||||
}));
|
appId: a.id
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
next = data.pagination.next;
|
||||||
|
|
||||||
|
if (data.pagination.next === null) {
|
||||||
|
hasMorePages = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return apps;
|
return apps;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user