//native
type Vercel = {
token: string;
};
/**
* Get a single secret
* Retrieves the information for a specific secret by passing either the secret id or name in the URL.
*/
export async function main(
auth: Vercel,
idOrName: string,
decrypt: "true" | "false" | undefined,
teamId: string | undefined,
slug: string | undefined,
) {
const url = new URL(`https://api.vercel.com/v3/secrets/${idOrName}`);
for (const [k, v] of [
["decrypt", decrypt],
["teamId", teamId],
["slug", slug],
]) {
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 428 days ago