export type GetApiSamlEnvironmentIdArgs = {environmentId: string}; export type GetApiSamlEnvironmentIdOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Get the contents of the saml.xml configuration file * * GET /saml/{environmentId} * * Also accepts auth: jwtAuth, oauth2, oauth2 */ export const getApiSamlEnvironmentId = async (args: GetApiSamlEnvironmentIdArgs, options: GetApiSamlEnvironmentIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/saml/${encodeURIComponent(String(args.environmentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };