mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 09:26:47 +00:00
fix(integrations): paginate cloudflare pages projects
This commit is contained in:
@@ -775,20 +775,43 @@ const getAppsCheckly = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
* Return list of projects for the Cloudflare Pages integration
|
* Return list of projects for the Cloudflare Pages integration
|
||||||
*/
|
*/
|
||||||
const getAppsCloudflarePages = async ({ accessToken, accountId }: { accessToken: string; accountId?: string }) => {
|
const getAppsCloudflarePages = async ({ accessToken, accountId }: { accessToken: string; accountId?: string }) => {
|
||||||
const { data } = await request.get<{ result: { name: string; id: string }[] }>(
|
const apps: Array<{ name: string; appId: string }> = [];
|
||||||
`${IntegrationUrls.CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accountId}/pages/projects`,
|
let page = 1;
|
||||||
{
|
const perPage = 50;
|
||||||
|
let hasMorePages = true;
|
||||||
|
|
||||||
|
// paginate through all projects
|
||||||
|
while (hasMorePages) {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
page: String(page),
|
||||||
|
per_page: String(perPage)
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data } = await request.get<{
|
||||||
|
result: { name: string; id: string }[];
|
||||||
|
result_info?: { total_pages: number };
|
||||||
|
}>(`${IntegrationUrls.CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accountId}/pages/projects`, {
|
||||||
|
params,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
Accept: "application/json"
|
Accept: "application/json"
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
data.result.forEach((a) => {
|
||||||
|
apps.push({
|
||||||
|
name: a.name,
|
||||||
|
appId: a.id
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data.result.length < perPage || (data.result_info && page >= data.result_info.total_pages)) {
|
||||||
|
hasMorePages = false;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
page += 1;
|
||||||
|
}
|
||||||
|
|
||||||
const apps = data.result.map((a) => ({
|
|
||||||
name: a.name,
|
|
||||||
appId: a.id
|
|
||||||
}));
|
|
||||||
return apps;
|
return apps;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user