UNPKG

@boxyhq/svelte-ui

Version:

Svelte UI components from BoxyHQ

34 lines (33 loc) 1.54 kB
import { sendHTTPRequest, ApiResponse } from '../../shared/http'; export const saveConnection = async ({ formObj, isEditView, connectionIsSAML, connectionIsOIDC, callback, url }) => { const { rawMetadata, redirectUrl, oidcDiscoveryUrl, oidcMetadata, oidcClientId, oidcClientSecret, metadataUrl, ...rest } = formObj; const encodedRawMetadata = window.btoa(rawMetadata || ''); const res = await sendHTTPRequest(url, { method: isEditView ? 'PATCH' : 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...rest, encodedRawMetadata: connectionIsSAML ? encodedRawMetadata : undefined, oidcDiscoveryUrl: connectionIsOIDC ? oidcDiscoveryUrl : undefined, oidcMetadata: connectionIsOIDC ? oidcMetadata : undefined, oidcClientId: connectionIsOIDC ? oidcClientId : undefined, oidcClientSecret: connectionIsOIDC ? oidcClientSecret : undefined, redirectUrl: JSON.stringify(redirectUrl), // TODO: validate redirect url inside form to have atlease one entry metadataUrl: connectionIsSAML ? metadataUrl : undefined }) }); callback(res); }; export const deleteConnection = async ({ url, clientId, clientSecret, callback }) => { const queryParams = new URLSearchParams({ clientID: clientId, clientSecret }); const res = await sendHTTPRequest(`${url}?${queryParams}`, { method: 'DELETE' }); callback(res); };