mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
The settings screen stores the installation url nested under the service name, while the embed matcher read a flat url, so a configured instance never matched. The server-side embeddability check also had no knowledge of team integrations and fell back to inspecting the instance headers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import { uniq } from "es-toolkit/compat";
|
|
import { IntegrationService, type IntegrationType } from "@shared/types";
|
|
import { getInstallationUrl } from "@shared/utils/integrations";
|
|
import { urlRegex } from "@shared/utils/urls";
|
|
import env from "@server/env";
|
|
import type Integration from "@server/models/Integration";
|
|
|
|
/**
|
|
* Helper class for working with integrations.
|
|
*/
|
|
export default class IntegrationHelper {
|
|
/**
|
|
* Whether a url is served by one of the given embed integrations, for example
|
|
* a self-hosted diagrams.net installation.
|
|
*
|
|
* @param url The url to check.
|
|
* @param integrations The team's embed integrations.
|
|
* @returns true if the url matches a configured installation.
|
|
*/
|
|
public static isConfiguredEmbedUrl(
|
|
url: string,
|
|
integrations: Integration<IntegrationType.Embed>[]
|
|
): boolean {
|
|
return integrations.some(
|
|
(integration) =>
|
|
!!urlRegex(getInstallationUrl(integration.settings))?.test(url)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns the script sources that must be allowed by the Content Security
|
|
* Policy for the given analytics integrations to load.
|
|
*
|
|
* @param integrations The analytics integrations.
|
|
* @returns A list of CSP script sources.
|
|
*/
|
|
public static getAnalyticsScriptSrc(
|
|
integrations: Integration<IntegrationType.Analytics>[] = []
|
|
): string[] {
|
|
// The cloud policy already allows the third-party services that are
|
|
// available to hosted teams.
|
|
if (env.isCloudHosted) {
|
|
return [];
|
|
}
|
|
|
|
return uniq(
|
|
integrations.flatMap((integration) =>
|
|
IntegrationHelper.scriptSrcForIntegration(integration)
|
|
)
|
|
);
|
|
}
|
|
|
|
private static scriptSrcForIntegration(
|
|
integration: Integration<IntegrationType.Analytics>
|
|
): string[] {
|
|
if (integration.service === IntegrationService.GoogleAnalytics) {
|
|
return ["www.googletagmanager.com", "www.google-analytics.com"];
|
|
}
|
|
|
|
// Self-hosted analytics services are loaded from the configured instance.
|
|
if (integration.settings?.instanceUrl) {
|
|
try {
|
|
return [new URL(integration.settings.instanceUrl).host];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
return [];
|
|
}
|
|
}
|