//native
type Persona = {
apiKey: string;
};
/**
* List all User Audit Logs
* Returns a list of your organization’s user audit logs for up to the most recent 6 months.
*/
export async function main(
auth: Persona,
page: any,
fields: string | undefined,
Key_Inflection?: string,
Idempotency_Key?: string,
Persona_Version?: string,
) {
const url = new URL(`https://api.withpersona.com/api/v1/user-audit-logs`);
for (const [k, v] of [["fields", fields]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
encodeParams({ page }).forEach((v, k) => {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
});
const headers: Record<string, string> = {
Authorization: `Bearer ${auth.apiKey}`,
};
if (Key_Inflection) {
headers["Key-Inflection"] = Key_Inflection;
}
if (Idempotency_Key) {
headers["Idempotency-Key"] = Idempotency_Key;
}
if (Persona_Version) {
headers["Persona-Version"] = Persona_Version;
}
const response = await fetch(url, {
method: "GET",
headers,
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
function encodeParams(o: any) {
function iter(o: any, path: string) {
if (Array.isArray(o)) {
o.forEach(function (a) {
iter(a, path + "[]");
});
return;
}
if (o !== null && typeof o === "object") {
Object.keys(o).forEach(function (k) {
iter(o[k], path + "[" + k + "]");
});
return;
}
data.push(path + "=" + o);
}
const data: string[] = [];
Object.keys(o).forEach(function (k) {
if (o[k] !== undefined) {
iter(o[k], k);
}
});
return new URLSearchParams(data.join("&"));
}
Submitted by hugo697 428 days ago