chore: Decouple core plugins (#14340)

* chore: Move plugin-specific integration code into plugins

Core no longer imports from or names the settings of individual plugins.
Plugins now register mention providers, issue status icons, instance URLs,
settings keys, settings and import schemas, and OAuth clients through hooks.

* fix: Recompute embed instance URLs after plugins load and match legacy issue icons by URL

* fix: Skip logo upload jobs queued without a settings path

* chore: Choose issue status icons from the unfurl state
This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-02 19:42:48 -05:00
1 parent 5901b1213c
commit 6d7cd455e9
80 files changed
+1222 -856

No files matched your search

+1 -1
View File
@@ -8,7 +8,6 @@ import { toError } from "@shared/utils/error";
import { slugifyDomain } from "@shared/utils/domains";
import { parseEmail } from "@shared/utils/email";
import accountProvisioner from "@server/commands/accountProvisioner";
import { MicrosoftGraphError } from "@server/errors";
import passportMiddleware from "@server/middlewares/passport";
import type { User } from "@server/models";
import type { AuthenticationResult } from "@server/types";
@@ -30,6 +29,7 @@ import AttachmentHelper from "@server/models/helpers/AttachmentHelper";
import { AttachmentPreset } from "@shared/types";
import { UserFlag } from "@server/models/User";
import { getEmailVerified } from "./getEmailVerified";
import { MicrosoftGraphError } from "../errors";
const router = new Router();
const scopes: string[] = [];
+10
View File
@@ -0,0 +1,10 @@
import httpErrors from "http-errors";
export function MicrosoftGraphError(
message = "Microsoft Graph API did not return required fields"
) {
return httpErrors(400, message, {
id: "graph_error",
isReportable: false,
});
}
+7 -1
View File
@@ -1,5 +1,6 @@
import { Hook, PluginManager } from "@server/utils/PluginManager";
import config from "../plugin.json";
import AzureClient from "./azure";
import router from "./auth/azure";
import env from "./env";
@@ -9,6 +10,11 @@ if (enabled) {
PluginManager.add({
...config,
type: Hook.AuthProvider,
value: { router, id: config.id, allowEmailMatch: true },
value: {
router,
id: config.id,
allowEmailMatch: true,
oauthClient: () => new AzureClient(),
},
});
}
@@ -0,0 +1,3 @@
declare module "@outlinewiki/passport-azure-ad-oauth2" {
export { default as Strategy } from "passport-oauth2";
}
+9 -1
View File
@@ -1,4 +1,4 @@
import { UserRole } from "@shared/types";
import { IntegrationService, UserRole } from "@shared/types";
import { createLazyComponent } from "~/components/LazyLoad";
import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
@@ -17,4 +17,12 @@ PluginManager.add([
enabled: (_, user) => user.role === UserRole.Admin,
},
},
{
...config,
type: Hook.InstanceUrl,
value: {
service: IntegrationService.Diagrams,
url: (settings) => settings.diagrams?.url,
},
},
]);
+65
View File
@@ -0,0 +1,65 @@
import { IntegrationService, IntegrationType } from "@shared/types";
import {
buildAdmin,
buildGuestUser,
buildIntegration,
buildTeam,
} from "@server/test/factories";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("#integrations.create", () => {
it("should accept the settings of a diagrams integration", async () => {
const admin = await buildAdmin();
const res = await server.post("/api/integrations.create", admin, {
body: {
type: IntegrationType.Embed,
service: IntegrationService.Diagrams,
settings: { diagrams: { url: "https://diagrams.example.com/" } },
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.settings).toEqual({
diagrams: { url: "https://diagrams.example.com/" },
});
});
it("should fail with status 400 bad request for invalid diagrams settings", async () => {
const admin = await buildAdmin();
const res = await server.post("/api/integrations.create", admin, {
body: {
type: IntegrationType.Embed,
service: IntegrationService.Diagrams,
settings: { diagrams: { url: "not a url" } },
},
});
expect(res.status).toEqual(400);
});
});
describe("#integrations.list", () => {
it("should expose diagrams settings to guests", async () => {
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const guest = await buildGuestUser({ teamId: team.id });
await buildIntegration({
userId: admin.id,
teamId: team.id,
service: IntegrationService.Diagrams,
type: IntegrationType.Embed,
settings: { diagrams: { url: "https://diagrams.example.com/" } },
});
const res = await server.post("/api/integrations.list", guest);
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data[0].settings).toEqual({
diagrams: { url: "https://diagrams.example.com/" },
});
});
});
+15
View File
@@ -0,0 +1,15 @@
import { z } from "zod";
import { IntegrationService } from "@shared/types";
import { Hook, PluginManager } from "@server/utils/PluginManager";
PluginManager.add({
type: Hook.IntegrationSettings,
value: {
service: IntegrationService.Diagrams,
keys: ["diagrams"],
visibleToGuests: true,
schema: z.object({
diagrams: z.object({ url: z.url() }),
}),
},
});
+9
View File
@@ -0,0 +1,9 @@
declare module "@shared/types" {
interface EmbedIntegrationSettings {
diagrams?: {
url: string;
};
}
}
export {};
+6 -1
View File
@@ -1,5 +1,6 @@
import { PluginManager, Hook } from "@server/utils/PluginManager";
import config from "../plugin.json";
import DiscordClient from "./discord";
import router from "./auth/discord";
import env from "./env";
@@ -9,6 +10,10 @@ if (enabled) {
PluginManager.add({
...config,
type: Hook.AuthProvider,
value: { router, id: config.id },
value: {
router,
id: config.id,
oauthClient: () => new DiscordClient(),
},
});
}
+36
View File
@@ -1,3 +1,6 @@
import { IntegrationService, IntegrationType } from "@shared/types";
import type { User } from "@server/models";
import { Integration } from "@server/models";
import { buildUser } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
@@ -41,3 +44,36 @@ describe("#figma.callback", () => {
expect(res.status).toEqual(400);
});
});
describe("#integrations.info", () => {
const buildFigmaAccount = (owner: User) =>
Integration.create<Integration<IntegrationType.LinkedAccount>>({
userId: owner.id,
teamId: owner.teamId,
service: IntegrationService.Figma,
type: IntegrationType.LinkedAccount,
settings: {
figma: {
account: {
id: "123",
name: "owner",
email: "owner@example.com",
avatarUrl: "https://example.com/avatar.png",
},
},
},
});
it("should expose figma account settings to the owner", async () => {
const owner = await buildUser();
const integration = await buildFigmaAccount(owner);
const res = await server.post("/api/integrations.info", owner, {
body: { id: integration.id },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.settings.figma.account.email).toEqual("owner@example.com");
});
});
+1
View File
@@ -99,6 +99,7 @@ router.get(
new UploadIntegrationLogoTask().schedule({
integrationId: integration.id,
logoUrl: figmaAccount.img_url,
settingsPath: ["figma", "account", "avatarUrl"],
})
);
+6
View File
@@ -1,3 +1,4 @@
import { IntegrationService } from "@shared/types";
import { Hook, PluginManager } from "@server/utils/PluginManager";
import config from "../plugin.json";
import router from "./api/figma";
@@ -5,6 +6,11 @@ import env from "./env";
import { Figma } from "./figma";
import { Minute } from "@shared/utils/time";
PluginManager.add({
type: Hook.IntegrationSettings,
value: { service: IntegrationService.Figma, keys: ["figma"] },
});
const enabled = !!env.FIGMA_CLIENT_ID && !!env.FIGMA_CLIENT_SECRET;
if (enabled) {
+14
View File
@@ -0,0 +1,14 @@
declare module "@shared/types" {
interface LinkedAccountIntegrationSettings {
figma?: {
account: {
id: string;
name: string;
email: string;
avatarUrl: string;
};
};
}
}
export {};
+25
View File
@@ -1,6 +1,9 @@
import type { IntegrationSettings, IntegrationType } from "@shared/types";
import { IntegrationService } from "@shared/types";
import { createLazyComponent } from "~/components/LazyLoad";
import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import { GiteaUtils } from "../shared/GiteaUtils";
import Icon from "./components/Icon";
PluginManager.add([
@@ -15,4 +18,26 @@ PluginManager.add([
component: createLazyComponent(() => import("./Settings")),
},
},
{
...config,
type: Hook.MentionProvider,
value: {
service: IntegrationService.Gitea,
isMentionable: (url, integration) => {
const settings =
integration.settings as IntegrationSettings<IntegrationType.Embed>;
return (
!!settings.gitea?.installation &&
!!GiteaUtils.pathParts(url, settings.gitea.url)
);
},
mentionType: (url, integration) => {
const settings =
integration.settings as IntegrationSettings<IntegrationType.Embed>;
return settings.gitea?.installation
? GiteaUtils.mentionType(url, settings.gitea.url)
: undefined;
},
},
},
]);
+5
View File
@@ -1,3 +1,4 @@
import { IntegrationService } from "@shared/types";
import { Minute } from "@shared/utils/time";
import { PluginManager, Hook } from "@server/utils/PluginManager";
import config from "../plugin.json";
@@ -6,6 +7,10 @@ import router from "./api/gitea";
import { Gitea } from "./gitea";
PluginManager.add([
{
type: Hook.IntegrationSettings,
value: { service: IntegrationService.Gitea, keys: ["gitea"] },
},
{
...config,
type: Hook.API,
+31 -17
View File
@@ -148,6 +148,35 @@ export class GiteaUtils {
}
}
/**
* Returns the path segments of a URL relative to a Gitea instance.
*
* @param url - the URL to split.
* @param baseUrl - the URL of the Gitea instance, which may include a path.
* @returns the path segments, or undefined if the URL is not on the instance.
*/
public static pathParts(url: URL, baseUrl: string): string[] | undefined {
let base: URL;
try {
base = new URL(baseUrl);
} catch {
return;
}
if (url.host !== base.host) {
return;
}
// Instances can be served from a sub-path, e.g. https://example.com/gitea
const basePath = base.pathname.replace(/\/+$/, "");
if (basePath && !url.pathname.startsWith(`${basePath}/`)) {
return;
}
return url.pathname.slice(basePath.length).split("/").filter(Boolean);
}
/**
* Parses a Gitea URL and extracts resource identifiers.
*
@@ -160,30 +189,15 @@ export class GiteaUtils {
baseUrl: string
): GiteaResource | undefined {
let parsed: URL;
let base: URL;
try {
parsed = new URL(url);
base = new URL(baseUrl);
} catch {
return;
}
if (parsed.host !== base.host) {
return;
}
// Instances can be served from a sub-path, e.g. https://example.com/gitea
const basePath = base.pathname.replace(/\/+$/, "");
if (basePath && !parsed.pathname.startsWith(`${basePath}/`)) {
return;
}
const parts = parsed.pathname
.slice(basePath.length)
.split("/")
.filter(Boolean);
if (parts.length < 2 || this.systemPaths.has(parts[0])) {
const parts = this.pathParts(parsed, baseUrl);
if (!parts || parts.length < 2 || this.systemPaths.has(parts[0])) {
return;
}
+13
View File
@@ -0,0 +1,13 @@
declare module "@shared/types" {
interface EmbedIntegrationSettings {
gitea?: {
url: string;
installation?: {
id: number;
account: { id: number; name: string; avatarUrl: string };
};
};
}
}
export {};
+11
View File
@@ -1,6 +1,8 @@
import { IntegrationService } from "@shared/types";
import { createLazyComponent } from "~/components/LazyLoad";
import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import { GitHubUtils } from "../shared/GitHubUtils";
import Icon from "./Icon";
PluginManager.add([
@@ -15,4 +17,13 @@ PluginManager.add([
component: createLazyComponent(() => import("./Settings")),
},
},
{
...config,
type: Hook.MentionProvider,
value: {
service: IntegrationService.GitHub,
isMentionable: (url) => url.hostname === "github.com",
mentionType: (url) => GitHubUtils.mentionType(url),
},
},
]);
+66 -2
View File
@@ -1,6 +1,13 @@
import { IntegrationService } from "@shared/types";
import { IntegrationService, IntegrationType } from "@shared/types";
import { Integration } from "@server/models";
import { buildAdmin, buildUser, buildViewer } from "@server/test/factories";
import {
buildAdmin,
buildGuestUser,
buildIntegration,
buildTeam,
buildUser,
buildViewer,
} from "@server/test/factories";
import { getTestServer } from "@server/test/support";
import { GitHub, InstallationAccess } from "../github";
import { SetupAction } from "./schema";
@@ -136,3 +143,60 @@ describe("#github.callback", () => {
expect(res.status).toEqual(403);
});
});
describe("#integrations.list", () => {
it("should expose the github settings of the integration", async () => {
const team = await buildTeam();
const member = await buildUser({ teamId: team.id });
const installation = {
id: 1,
account: { id: 2, name: "outline", avatarUrl: "https://example.com" },
};
await buildIntegration({
userId: member.id,
teamId: team.id,
service: IntegrationService.GitHub,
type: IntegrationType.Embed,
settings: {
github: { installation },
url: "https://example.com",
},
});
const res = await server.post("/api/integrations.list", member);
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data[0].settings).toEqual({
url: "https://example.com",
github: { installation },
});
});
it("should not expose github settings to guests", async () => {
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const guest = await buildGuestUser({ teamId: team.id });
await buildIntegration({
userId: admin.id,
teamId: team.id,
service: IntegrationService.GitHub,
type: IntegrationType.Embed,
settings: {
url: "https://example.com",
github: {
installation: {
id: 123,
account: { id: 456, name: "acme", avatarUrl: "" },
},
},
},
});
const res = await server.post("/api/integrations.list", guest);
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data[0].settings).toEqual({ url: "https://example.com" });
});
});
+6
View File
@@ -1,3 +1,4 @@
import { IntegrationService } from "@shared/types";
import { Minute } from "@shared/utils/time";
import { PluginManager, Hook } from "@server/utils/PluginManager";
import config from "../plugin.json";
@@ -9,6 +10,11 @@ import { GitHub } from "./github";
import GitHubWebhookTask from "./tasks/GitHubWebhookTask";
import { uninstall } from "./uninstall";
PluginManager.add({
type: Hook.IntegrationSettings,
value: { service: IntegrationService.GitHub, keys: ["github"] },
});
const enabled =
!!env.GITHUB_CLIENT_ID &&
!!env.GITHUB_CLIENT_SECRET &&
+12
View File
@@ -0,0 +1,12 @@
declare module "@shared/types" {
interface EmbedIntegrationSettings {
github?: {
installation: {
id: number;
account: { id: number; name: string; avatarUrl: string };
};
};
}
}
export {};
+26
View File
@@ -1,6 +1,9 @@
import type { IntegrationSettings, IntegrationType } from "@shared/types";
import { IntegrationService } from "@shared/types";
import { createLazyComponent } from "~/components/LazyLoad";
import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import { GitLabUtils } from "../shared/GitLabUtils";
import Icon from "./components/Icon";
PluginManager.add([
@@ -15,4 +18,27 @@ PluginManager.add([
component: createLazyComponent(() => import("./Settings")),
},
},
{
...config,
type: Hook.MentionProvider,
value: {
service: IntegrationService.GitLab,
isMentionable: (url, integration) => {
const settings =
integration.settings as IntegrationSettings<IntegrationType.Embed>;
let hostname: string | undefined;
try {
hostname = settings.gitlab?.url
? new URL(settings.gitlab.url).hostname
: undefined;
} catch {
return false;
}
return url.hostname === "gitlab.com" || url.hostname === hostname;
},
// The host is already checked by isMentionable.
mentionType: (url) => GitLabUtils.mentionType(url, url.origin),
},
},
]);
+21 -1
View File
@@ -1,4 +1,5 @@
import { buildUser, buildViewer } from "@server/test/factories";
import { IntegrationService, IntegrationType } from "@shared/types";
import { buildAdmin, buildUser, buildViewer } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
@@ -58,3 +59,22 @@ describe("#gitlab.callback", () => {
expect(res.status).toEqual(403);
});
});
describe("#integrations.create", () => {
it("should accept the settings of a gitlab integration", async () => {
const admin = await buildAdmin();
const res = await server.post("/api/integrations.create", admin, {
body: {
type: IntegrationType.Embed,
service: IntegrationService.GitLab,
settings: { gitlab: { url: "https://gitlab.example.com" } },
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.settings).toEqual({
gitlab: { url: "https://gitlab.example.com" },
});
});
});
+16
View File
@@ -39,3 +39,19 @@ export const GitLabConnectSchema = BaseSchema.extend({
});
export type GitLabConnectReq = z.infer<typeof GitLabConnectSchema>;
export const GitLabSettingsSchema = z.object({
gitlab: z.object({
url: z.url().optional(),
installation: z
.object({
id: z.number(),
account: z.object({
id: z.number(),
name: z.string(),
avatarUrl: z.string(),
}),
})
.optional(),
}),
});
+10
View File
@@ -1,13 +1,23 @@
import { IntegrationService } from "@shared/types";
import { Minute } from "@shared/utils/time";
import { PluginManager, Hook } from "@server/utils/PluginManager";
import config from "../plugin.json";
import { GitLabUtils } from "../shared/GitLabUtils";
import { GitLabIssueProvider } from "./GitLabIssueProvider";
import router from "./api/gitlab";
import { GitLabSettingsSchema } from "./api/schema";
import { GitLab } from "./gitlab";
import GitLabWebhookTask from "./tasks/GitLabWebhookTask";
PluginManager.add([
{
type: Hook.IntegrationSettings,
value: {
service: IntegrationService.GitLab,
keys: ["gitlab"],
schema: GitLabSettingsSchema,
},
},
{
...config,
type: Hook.API,
+13
View File
@@ -0,0 +1,13 @@
declare module "@shared/types" {
interface EmbedIntegrationSettings {
gitlab?: {
url?: string;
installation?: {
id: number;
account: { id: number; name: string; avatarUrl: string };
};
};
}
}
export {};
+2 -4
View File
@@ -8,10 +8,7 @@ import { toError } from "@shared/utils/error";
import { languages } from "@shared/i18n";
import { slugifyDomain } from "@shared/utils/domains";
import accountProvisioner from "@server/commands/accountProvisioner";
import {
GmailAccountCreationError,
TeamDomainRequiredError,
} from "@server/errors";
import { TeamDomainRequiredError } from "@server/errors";
import passportMiddleware from "@server/middlewares/passport";
import { AuthenticationProvider, User } from "@server/models";
import type { AuthenticationResult } from "@server/types";
@@ -26,6 +23,7 @@ import {
import config from "../../plugin.json";
import env from "../env";
import { createContext } from "@server/context";
import { GmailAccountCreationError } from "../errors";
const router = new Router();
+10
View File
@@ -0,0 +1,10 @@
import httpErrors from "http-errors";
export function GmailAccountCreationError(
message = "Cannot create account using personal Gmail address"
) {
return httpErrors(400, message, {
id: "gmail_account_creation",
isReportable: false,
});
}
+7 -1
View File
@@ -1,5 +1,6 @@
import { PluginManager, Hook } from "@server/utils/PluginManager";
import config from "../plugin.json";
import GoogleClient from "./google";
import router from "./auth/google";
import env from "./env";
@@ -10,7 +11,12 @@ if (enabled) {
{
...config,
type: Hook.AuthProvider,
value: { router, id: config.id, allowEmailMatch: true },
value: {
router,
id: config.id,
allowEmailMatch: true,
oauthClient: () => new GoogleClient(),
},
},
]);
}
@@ -0,0 +1,3 @@
declare module "passport-google-oauth2" {
export { default as Strategy } from "passport-oauth2";
}
@@ -0,0 +1,23 @@
type Props = {
/** The size of the icon, 24px is default to match standard icons */
size?: number;
/** The color of the icon, defaults to the current text color */
color?: string;
};
export default function GoogleIcon({
size = 24,
color = "currentColor",
}: Props) {
return (
<svg
fill={color}
width={size}
height={size}
viewBox="-8 -8 48 48"
version="1.1"
>
<path d="M32.6162791,13.9090909 L16.8837209,13.9090909 L16.8837209,20.4772727 L25.9395349,20.4772727 C25.0953488,24.65 21.5651163,27.0454545 16.8837209,27.0454545 C11.3581395,27.0454545 6.90697674,22.5636364 6.90697674,17 C6.90697674,11.4363636 11.3581395,6.95454545 16.8837209,6.95454545 C19.2627907,6.95454545 21.4116279,7.80454545 23.1,9.19545455 L28.0116279,4.25 C25.0186047,1.62272727 21.1813953,0 16.8837209,0 C7.52093023,0 0,7.57272727 0,17 C0,26.4272727 7.52093023,34 16.8837209,34 C25.3255814,34 33,27.8181818 33,17 C33,15.9954545 32.8465116,14.9136364 32.6162791,13.9090909 Z" />
</svg>
);
}
+1 -1
View File
@@ -11,7 +11,7 @@ import { IntegrationScene } from "~/scenes/Settings/components/IntegrationScene"
import SettingRow from "~/scenes/Settings/components/SettingRow";
import Button from "~/components/Button";
import Heading from "~/components/Heading";
import GoogleIcon from "~/components/Icons/GoogleIcon";
import GoogleIcon from "./GoogleIcon";
import Input from "~/components/Input";
import Text from "~/components/Text";
import useStores from "~/hooks/useStores";
+150
View File
@@ -0,0 +1,150 @@
// @vitest-isolate true
import type { Mock } from "vitest";
import { randomString } from "@shared/random";
import { UnfurlResourceType } from "@shared/types";
import { Hour } from "@shared/utils/time";
import type { User } from "@server/models";
import Redis from "@server/storage/redis";
import { buildGuestUser, buildUser } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
import { RedisPrefixHelper } from "@server/utils/RedisPrefixHelper";
import Iframely from "./iframely";
vi.spyOn(Iframely, "requestResource").mockImplementation(() =>
Promise.resolve({})
);
const server = getTestServer();
describe("#urls.unfurl", () => {
let user: User;
beforeEach(async () => {
user = await buildUser();
});
it("should succeed with status 200 ok for a valid external url", async () => {
(Iframely.requestResource as Mock).mockResolvedValue(
Promise.resolve({
url: "https://www.flickr.com",
type: "rich",
meta: {
title: "Flickr",
description:
"The safest and most inclusive global community of photography enthusiasts. The best place for inspiration, connection, and sharing!",
},
links: {
thumbnail: [
{
href: "https://combo.staticflickr.com/66a031f9fc343c5e42d965ca/671aaf5d51c929e483e8b26d_Open%20Graph%20Home.jpg",
type: "image/jpg",
rel: ["twitter", "thumbnail", "ssl", "og"],
content_length: 412824,
media: {
width: 1200,
height: 630,
},
},
],
icon: [
{
href: "https://combo.staticflickr.com/66a031f9fc343c5e42d965ca/67167dd041b0982f0f230dab_flickr-webclip.png",
rel: ["apple-touch-icon", "icon", "ssl"],
type: "image/png",
},
],
},
})
);
const res = await server.post("/api/urls.unfurl", user, {
body: {
url: "https://www.flickr.com",
},
});
expect(res.status).toEqual(200);
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.url).toEqual("https://www.flickr.com");
expect(body.type).toEqual(UnfurlResourceType.URL);
expect(body.title).toEqual("Flickr");
expect(body.description).toEqual(
"The safest and most inclusive global community of photography enthusiasts. The best place for inspiration, connection, and sharing!"
);
expect(body.thumbnailUrl).toEqual(
"https://combo.staticflickr.com/66a031f9fc343c5e42d965ca/671aaf5d51c929e483e8b26d_Open%20Graph%20Home.jpg"
);
});
it("should succeed with status 204 no content for a non-existing external url", async () => {
(Iframely.requestResource as Mock).mockResolvedValue(
Promise.resolve({
status: 404,
error:
"Iframely could not fetch the given URL. The content is no longer available at the origin.",
})
);
const res = await server.post("/api/urls.unfurl", user, {
body: {
url: "https://random.url",
},
});
expect(res.status).toEqual(204);
});
it("should cache a permanent external url error for a day", async () => {
(Iframely.requestResource as Mock).mockResolvedValue({
status: 403,
error: "Iframely could not fetch the given URL.",
});
const url = `https://${randomString(8)}.example.com`;
const res = await server.post("/api/urls.unfurl", user, {
body: { url },
});
expect(res.status).toEqual(204);
const ttl = await Redis.defaultClient.ttl(
RedisPrefixHelper.getUnfurlKey(user.teamId, user.id, url)
);
expect(ttl).toBeGreaterThan(Hour.seconds);
});
it("should cache a transient external url error for a minute", async () => {
(Iframely.requestResource as Mock).mockResolvedValue({
status: 418,
error: "Iframely timed out fetching the given URL.",
});
const url = `https://${randomString(8)}.example.com`;
const res = await server.post("/api/urls.unfurl", user, {
body: { url },
});
expect(res.status).toEqual(204);
const ttl = await Redis.defaultClient.ttl(
RedisPrefixHelper.getUnfurlKey(user.teamId, user.id, url)
);
expect(ttl).toBeGreaterThan(0);
expect(ttl).toBeLessThanOrEqual(60);
});
it("should not unfurl external urls for guests", async () => {
const guest = await buildGuestUser({ teamId: user.teamId });
const callCount = (Iframely.requestResource as Mock).mock.calls.length;
const res = await server.post("/api/urls.unfurl", guest, {
body: {
url: "https://github.com/acme/private/issues/1",
},
});
expect(res.status).toEqual(204);
expect((Iframely.requestResource as Mock).mock.calls.length).toEqual(
callCount
);
});
});
+21
View File
@@ -1,6 +1,9 @@
import type { IntegrationSettings, IntegrationType } from "@shared/types";
import { IntegrationService } from "@shared/types";
import { createLazyComponent } from "~/components/LazyLoad";
import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import { LinearUtils } from "../shared/LinearUtils";
import Icon from "./Icon";
PluginManager.add([
@@ -15,4 +18,22 @@ PluginManager.add([
component: createLazyComponent(() => import("./Settings")),
},
},
{
...config,
type: Hook.MentionProvider,
value: {
service: IntegrationService.Linear,
isMentionable: (url, integration) => {
const settings =
integration.settings as IntegrationSettings<IntegrationType.Embed>;
// Ensure the installed workspace key matches the URL.
return (
url.hostname === "linear.app" &&
settings.linear?.workspace.key === url.pathname.split("/")[1]
);
},
mentionType: (url) => LinearUtils.mentionType(url),
},
},
]);
+1
View File
@@ -105,6 +105,7 @@ router.get(
await new UploadIntegrationLogoTask().schedule({
integrationId: integration.id,
logoUrl: workspace.logoUrl,
settingsPath: ["linear", "workspace", "logoUrl"],
});
}
});
+6
View File
@@ -1,3 +1,4 @@
import { IntegrationService } from "@shared/types";
import { Minute } from "@shared/utils/time";
import { Hook, PluginManager } from "@server/utils/PluginManager";
import config from "../plugin.json";
@@ -8,6 +9,11 @@ import { Linear } from "./linear";
import UploadIntegrationLogoTask from "@server/queues/tasks/UploadIntegrationLogoTask";
import { uninstall } from "./uninstall";
PluginManager.add({
type: Hook.IntegrationSettings,
value: { service: IntegrationService.Linear, keys: ["linear"] },
});
const enabled = !!env.LINEAR_CLIENT_ID && !!env.LINEAR_CLIENT_SECRET;
if (enabled) {
+9
View File
@@ -0,0 +1,9 @@
declare module "@shared/types" {
interface EmbedIntegrationSettings {
linear?: {
workspace: { id: string; name: string; key: string; logoUrl?: string };
};
}
}
export {};
+84 -1
View File
@@ -1,5 +1,19 @@
import { buildUser, buildViewer } from "@server/test/factories";
import {
CollectionPermission,
ImportState,
IntegrationService,
IntegrationType,
} from "@shared/types";
import { Integration } from "@server/models";
import {
buildAdmin,
buildImport,
buildIntegration,
buildUser,
buildViewer,
} from "@server/test/factories";
import { getTestServer } from "@server/test/support";
import type { NotionImportInput } from "../../shared/schema";
const server = getTestServer();
@@ -58,3 +72,72 @@ describe("#notion.callback", () => {
expect(res.status).toEqual(403);
});
});
describe("#imports.create", () => {
it("should create an import", async () => {
const admin = await buildAdmin();
const integration = await Integration.create<
Integration<IntegrationType.Import>
>({
service: IntegrationService.Notion,
type: IntegrationType.Import,
userId: admin.id,
teamId: admin.teamId,
settings: {
externalWorkspace: {
id: "testId",
name: "testWorkspaceName",
},
},
});
const input: NotionImportInput = [{ permission: undefined }];
const res = await server.post("/api/imports.create", admin, {
body: {
integrationId: integration.id,
service: IntegrationService.Notion,
input,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.id).toBeTruthy();
expect(body.data.name).toEqual("testWorkspaceName");
expect(body.data.state).toEqual(ImportState.Created);
expect(body.data.service).toEqual(IntegrationService.Notion);
expect(body.data.createdById).toEqual(admin.id);
});
it("should not allow more than one active import at a time", async () => {
const admin = await buildAdmin();
const integration = await buildIntegration({
userId: admin.id,
teamId: admin.teamId,
service: IntegrationService.Notion,
type: IntegrationType.Import,
settings: {
externalWorkspace: { id: "ws-1", name: "Test Workspace" },
// oxlint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
});
const input: NotionImportInput = [
{ permission: CollectionPermission.Read },
];
await buildImport({
createdById: admin.id,
teamId: admin.teamId,
integrationId: integration.id,
});
const res = await server.post("/api/imports.create", admin, {
body: {
integrationId: integration.id,
service: IntegrationService.Notion,
input,
},
});
expect(res.status).toEqual(422);
});
});
+12
View File
@@ -1,10 +1,22 @@
import { z } from "zod";
import { IntegrationService } from "@shared/types";
import { IntegrationImportBodySchema } from "@server/routes/api/imports/schema";
import { Hook, PluginManager } from "@server/utils/PluginManager";
import config from "../plugin.json";
import router from "./api/notion";
import { NotionImportInputItemSchema } from "../shared/schema";
import env from "./env";
import { NotionImportsProcessor } from "./processors/NotionImportsProcessor";
import NotionAPIImportTask from "./tasks/NotionAPIImportTask";
PluginManager.add({
type: Hook.ImportSchema,
value: IntegrationImportBodySchema.extend({
service: z.literal(IntegrationService.Notion),
input: z.array(NotionImportInputItemSchema),
}),
});
const enabled = !!env.NOTION_CLIENT_ID && !!env.NOTION_CLIENT_SECRET;
if (enabled) {
@@ -1,5 +1,8 @@
import type { Transaction } from "sequelize";
import type { NotionImportInput, NotionImportTaskInput } from "@shared/schema";
import type {
NotionImportInput,
NotionImportTaskInput,
} from "../../shared/schema";
import { IntegrationService } from "@shared/types";
import type { Import, ImportTask } from "@server/models";
import { Integration } from "@server/models";
+33
View File
@@ -0,0 +1,33 @@
import { z } from "zod";
import {
BaseImportInputItemSchema,
BaseImportTaskInputItemSchema,
} from "@shared/schema";
import type { IntegrationService } from "@shared/types";
import { PageType } from "./types";
export const NotionImportInputItemSchema = BaseImportInputItemSchema.extend({
type: z.enum(PageType).optional(),
externalId: z.string().optional(),
});
export type NotionImportInput = z.infer<typeof NotionImportInputItemSchema>[];
export const NotionImportTaskInputItemSchema =
BaseImportTaskInputItemSchema.extend({
type: z.enum(PageType),
});
export type NotionImportTaskInput = z.infer<
typeof NotionImportTaskInputItemSchema
>[];
declare module "@shared/schema" {
interface ImportInputMap {
[IntegrationService.Notion]: NotionImportInput;
}
interface ImportTaskInputMap {
[IntegrationService.Notion]: NotionImportTaskInput;
}
}
+2 -4
View File
@@ -9,10 +9,7 @@ import { parseEmail } from "@shared/utils/email";
import { getSupportedLanguage } from "@shared/utils/language";
import { isBase64Url } from "@shared/utils/urls";
import accountProvisioner from "@server/commands/accountProvisioner";
import {
OIDCMalformedUserInfoError,
AuthenticationError,
} from "@server/errors";
import { AuthenticationError } from "@server/errors";
import Logger from "@server/logging/Logger";
import passportMiddleware from "@server/middlewares/passport";
import type { User } from "@server/models";
@@ -32,6 +29,7 @@ import env from "../env";
import { OIDCStrategy } from "./OIDCStrategy";
import { resolveProviderId } from "./resolveProviderId";
import { createContext } from "@server/context";
import { OIDCMalformedUserInfoError } from "../errors";
export interface OIDCEndpoints {
authorizationURL: string;
+10
View File
@@ -0,0 +1,10 @@
import httpErrors from "http-errors";
export function OIDCMalformedUserInfoError(
message = "User profile information malformed"
) {
return httpErrors(400, message, {
id: "malformed_user_info",
isReportable: false,
});
}
+6 -1
View File
@@ -1,6 +1,7 @@
import Logger from "@server/logging/Logger";
import { PluginManager, Hook } from "@server/utils/PluginManager";
import config from "../plugin.json";
import OIDCClient from "./oidc";
import router from "./auth/oidc";
import env from "./env";
@@ -27,7 +28,11 @@ if (enabled) {
{
...config,
type: Hook.AuthProvider,
value: { router, id: config.id },
value: {
router,
id: config.id,
oauthClient: () => new OIDCClient(),
},
name: env.OIDC_DISPLAY_NAME || config.name,
},
]);
+9
View File
@@ -1,9 +1,18 @@
import { z } from "zod";
import { IntegrationService } from "@shared/types";
import { AttachmentImportBodySchema } from "@server/routes/api/imports/schema";
import { Hook, PluginManager } from "@server/utils/PluginManager";
import config from "../plugin.json";
import { SlabImportsProcessor } from "./processors/SlabImportsProcessor";
import SlabAPIImportTask from "./tasks/SlabAPIImportTask";
PluginManager.add([
{
type: Hook.ImportSchema,
value: AttachmentImportBodySchema.extend({
service: z.literal(IntegrationService.Slab),
}),
},
{
...config,
type: Hook.Processor,
+27
View File
@@ -0,0 +1,27 @@
import { ImportState, IntegrationService } from "@shared/types";
import { buildAdmin, buildAttachment } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("#imports.create", () => {
it("should create a slab import from an uploaded file", async () => {
const admin = await buildAdmin();
const attachment = await buildAttachment({
teamId: admin.teamId,
userId: admin.id,
});
const res = await server.post("/api/imports.create", admin, {
body: {
attachmentId: attachment.id,
service: IntegrationService.Slab,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.state).toEqual(ImportState.Created);
expect(body.data.service).toEqual(IntegrationService.Slab);
});
});
+21
View File
@@ -0,0 +1,21 @@
import type {
MarkdownImportInput,
MarkdownImportScratch,
MarkdownImportTaskInput,
} from "@shared/schema";
import type { IntegrationService } from "@shared/types";
// Slab exports are imported through the Markdown importer.
declare module "@shared/schema" {
interface ImportInputMap {
[IntegrationService.Slab]: MarkdownImportInput;
}
interface ImportScratchMap {
[IntegrationService.Slab]: MarkdownImportScratch;
}
interface ImportTaskInputMap {
[IntegrationService.Slab]: MarkdownImportTaskInput;
}
}
@@ -0,0 +1,3 @@
declare module "passport-slack-oauth2" {
export { default as Strategy } from "passport-oauth2";
}
+7
View File
@@ -0,0 +1,7 @@
declare module "@shared/types" {
interface LinkedAccountIntegrationSettings {
slack?: { serviceTeamId: string; serviceUserId: string };
}
}
export {};
+11
View File
@@ -0,0 +1,11 @@
import "react";
// React 19 resolves intrinsic elements from React.JSX rather than the global
// JSX namespace, so custom elements must be declared here.
declare module "react" {
namespace JSX {
interface IntrinsicElements {
"zapier-app-directory": any;
}
}
}