Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.3 KB
Raw Blame
export const takeNewSourceIds = (sourceIds: string[], seenSourceIds: Set<string>) =>
  sourceIds.filter((sourceId) => {
    if (seenSourceIds.has(sourceId)) return false;
    seenSourceIds.add(sourceId);
    return true;
  });

export const resolveDiscoveredAppUrl = (
  override: string | undefined,
  suggestedUrl: string | null,
  generatedUrl: string | null,
  serverAddressEdited = false,
) => {
  if (override !== undefined) return override;
  if (serverAddressEdited && generatedUrl) return generatedUrl;
  return suggestedUrl || generatedUrl || "";
};

export const resolveIntegrationDraftUrl = ({
  currentUrl,
  overridden,
  serverUrl,
  fallbackUrl,
}: {
  currentUrl: string;
  overridden: boolean;
  serverUrl: string | null;
  fallbackUrl: string | null;
}) => (overridden ? currentUrl : serverUrl || fallbackUrl || "");

export const normalizeServiceUrl = (value: string) => {
  try {
    const trimmed = value.trim();
    if (!trimmed) return null;
    const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//iu.test(trimmed) ? trimmed : `http://${trimmed}`);
    if (url.protocol !== "http:" && url.protocol !== "https:") return null;
    if (!url.hostname || /[\s%]/u.test(url.hostname)) return null;
    return url.toString().replace(/\/$/u, "");
  } catch {
    return null;
  }
};

export const isHttpUrl = (value: string) => normalizeServiceUrl(value) !== null;