@reliverse/rse
Version:
@reliverse/rse is your all-in-one companion for bootstrapping and improving any kind of projects (especially web apps built with frameworks like Next.js) — whether you're kicking off something new or upgrading an existing app. It is also a little AI-power
37 lines (36 loc) • 1.08 kB
JavaScript
import { relinka } from "@reliverse/relinka";
import { projectsGetProjectEnv } from "@vercel/sdk/funcs/projectsGetProjectEnv";
const MAX_RETRIES = 3;
const RETRY_DELAY = 5e3;
export async function getVercelEnvVar(vercelInstance, projectId, envVarId) {
try {
const res = await projectsGetProjectEnv(vercelInstance, {
idOrName: projectId,
id: envVarId
});
if (!res.ok) {
throw res.error;
}
const envVar = res.value;
return envVar;
} catch (error) {
relinka(
"error",
"Error getting Vercel env var:",
error instanceof Error ? error.message : String(error)
);
return void 0;
}
}
export async function withRateLimit(fn, retries = MAX_RETRIES) {
try {
return await fn();
} catch (error) {
if (error instanceof Error && error.message.includes("rate limit") && retries > 0) {
relinka("info", `Rate limit hit, retrying in ${RETRY_DELAY / 1e3}s...`);
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
return withRateLimit(fn, retries - 1);
}
throw error;
}
}