//native
type Netlify = {
token: string;
};
/**
* Get site env vars
* Returns all environment variables for a site. This convenience method behaves the same as `getEnvVars` but doesn't require an `account_id` as input.
*/
export async function main(
auth: Netlify,
site_id: string,
context_name:
| "all"
| "dev"
| "branch-deploy"
| "deploy-preview"
| "production"
| undefined,
scope: "builds" | "functions" | "runtime" | "post_processing" | undefined,
) {
const url = new URL(
`https://api.netlify.com/api/v1/api/v1/sites/${site_id}/env`,
);
for (const [k, v] of [
["context_name", context_name],
["scope", scope],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago