mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
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:
1 parent
5901b1213c
commit
6d7cd455e9
80 files changed
+1222
-856
No files matched your search
@@ -5,7 +5,6 @@ import { Backticks } from "@shared/components/Backticks";
|
||||
import { IssueStatusIcon } from "@shared/components/IssueStatusIcon";
|
||||
import { richExtensions } from "@shared/editor/nodes";
|
||||
import type { UnfurlResourceType, UnfurlResponse } from "@shared/types";
|
||||
import { IntegrationService } from "@shared/types";
|
||||
import { Avatar } from "~/components/Avatar";
|
||||
import Editor from "~/components/Editor";
|
||||
import Flex from "~/components/Flex";
|
||||
@@ -37,13 +36,6 @@ function HoverPreviewIssue({
|
||||
ref,
|
||||
}: Props) {
|
||||
const authorName = author.name;
|
||||
const urlObj = new URL(url);
|
||||
const service =
|
||||
urlObj.hostname === "linear.app"
|
||||
? IntegrationService.Linear
|
||||
: urlObj.hostname === "github.com"
|
||||
? IntegrationService.GitHub
|
||||
: IntegrationService.GitLab;
|
||||
|
||||
return (
|
||||
<Preview as="a" href={url} target="_blank" rel="noopener noreferrer">
|
||||
@@ -52,11 +44,7 @@ function HoverPreviewIssue({
|
||||
<CardContent>
|
||||
<Flex gap={2} column>
|
||||
<Title>
|
||||
<StyledIssueStatusIcon
|
||||
service={service}
|
||||
state={state}
|
||||
size={18}
|
||||
/>
|
||||
<StyledIssueStatusIcon state={state} size={18} />
|
||||
<span>
|
||||
<Backticks content={title} />
|
||||
<Text type="tertiary">{id}</Text>
|
||||
|
||||
@@ -5,6 +5,7 @@ import embeds from "@shared/editor/embeds";
|
||||
import { IntegrationType, TeamPreference } from "@shared/types";
|
||||
import type Integration from "~/models/Integration";
|
||||
import Logger from "~/utils/Logger";
|
||||
import { Hook, PluginManager } from "~/utils/PluginManager";
|
||||
import useCurrentTeam from "./useCurrentTeam";
|
||||
import useStores from "./useStores";
|
||||
|
||||
@@ -34,6 +35,8 @@ export default function useEmbeds(loadIfMissing = false) {
|
||||
}
|
||||
}, [integrations, loadIfMissing]);
|
||||
|
||||
// Plugins may register instance URL resolvers after integrations load.
|
||||
const pluginsLoaded = PluginManager.isLoaded;
|
||||
const disabledEmbeds =
|
||||
(team?.getPreference(TeamPreference.DisabledEmbeds) as string[]) || [];
|
||||
|
||||
@@ -46,6 +49,9 @@ export default function useEmbeds(loadIfMissing = false) {
|
||||
|
||||
if (integration?.settings) {
|
||||
e.settings = integration.settings;
|
||||
e.instanceUrl = PluginManager.getHooks(Hook.InstanceUrl)
|
||||
.find((hook) => hook.value.service === e.name)
|
||||
?.value.url(integration.settings);
|
||||
}
|
||||
|
||||
e.disabled = disabledEmbeds.includes(e.id);
|
||||
@@ -53,6 +59,6 @@ export default function useEmbeds(loadIfMissing = false) {
|
||||
return e;
|
||||
}),
|
||||
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
||||
[integrations.orderedData, team?.preferences]
|
||||
[integrations.orderedData, team?.preferences, pluginsLoaded]
|
||||
);
|
||||
}
|
||||
Vendored
-1
@@ -5,7 +5,6 @@ import "react";
|
||||
declare module "react" {
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
"zapier-app-directory": any;
|
||||
"em-emoji": any;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { isArray, sortBy } from "es-toolkit/compat";
|
||||
import { action, makeObservable, observable, runInAction } from "mobx";
|
||||
import type { IObservableArray } from "mobx";
|
||||
import type {
|
||||
IntegrationService,
|
||||
IntegrationSettings,
|
||||
IntegrationType,
|
||||
MentionType,
|
||||
} from "@shared/types";
|
||||
import type Integration from "~/models/Integration";
|
||||
import type Team from "~/models/Team";
|
||||
import type User from "~/models/User";
|
||||
import type { LazyComponent } from "~/components/LazyLoad";
|
||||
@@ -15,6 +22,8 @@ export enum Hook {
|
||||
Settings = "settings",
|
||||
Imports = "imports",
|
||||
Icon = "icon",
|
||||
MentionProvider = "mentionProvider",
|
||||
InstanceUrl = "instanceUrl",
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +55,25 @@ type PluginValueMap = {
|
||||
action: React.ReactElement;
|
||||
};
|
||||
[Hook.Icon]: React.ElementType;
|
||||
[Hook.MentionProvider]: {
|
||||
/** The integration service that this provider handles. */
|
||||
service: IntegrationService;
|
||||
/** Whether the URL belongs to the integration. */
|
||||
isMentionable: (url: URL, integration: Integration) => boolean;
|
||||
/** The mention type of the URL, or undefined if it cannot be mentioned. */
|
||||
mentionType: (
|
||||
url: URL,
|
||||
integration: Integration
|
||||
) => MentionType | undefined;
|
||||
};
|
||||
[Hook.InstanceUrl]: {
|
||||
/** The integration service that this resolver is used for. */
|
||||
service: IntegrationService;
|
||||
/** Returns the URL of the instance that the integration is configured with. */
|
||||
url: (
|
||||
settings: IntegrationSettings<IntegrationType.Embed>
|
||||
) => string | undefined;
|
||||
};
|
||||
};
|
||||
|
||||
export type Plugin<T extends Hook> = {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { IntegrationService, MentionType } from "@shared/types";
|
||||
import type Integration from "~/models/Integration";
|
||||
import { determineMentionType, isURLMentionable } from "./mention";
|
||||
import { Hook, PluginManager } from "./PluginManager";
|
||||
|
||||
const buildIntegration = (service: IntegrationService) =>
|
||||
({ service, settings: {} }) as unknown as Integration;
|
||||
|
||||
describe("mention", () => {
|
||||
beforeAll(() => {
|
||||
PluginManager.add({
|
||||
id: "test-mention-provider",
|
||||
name: "Test mention provider",
|
||||
type: Hook.MentionProvider,
|
||||
value: {
|
||||
service: IntegrationService.GitHub,
|
||||
isMentionable: (url) => url.hostname === "example.com",
|
||||
mentionType: (url) =>
|
||||
url.pathname.startsWith("/issues/") ? MentionType.Issue : undefined,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the provider registered for the integration service", () => {
|
||||
const integration = buildIntegration(IntegrationService.GitHub);
|
||||
const url = new URL("https://example.com/issues/1");
|
||||
|
||||
expect(isURLMentionable({ url, integration })).toBe(true);
|
||||
expect(determineMentionType({ url, integration })).toBe(MentionType.Issue);
|
||||
});
|
||||
|
||||
it("returns the provider result for URLs it does not recognize", () => {
|
||||
const integration = buildIntegration(IntegrationService.GitHub);
|
||||
|
||||
expect(
|
||||
isURLMentionable({ url: new URL("https://other.com/"), integration })
|
||||
).toBe(false);
|
||||
expect(
|
||||
determineMentionType({
|
||||
url: new URL("https://example.com/about"),
|
||||
integration,
|
||||
})
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not mention URLs for services without a provider", () => {
|
||||
const integration = buildIntegration(IntegrationService.Slack);
|
||||
const url = new URL("https://example.com/issues/1");
|
||||
|
||||
expect(isURLMentionable({ url, integration })).toBe(false);
|
||||
expect(determineMentionType({ url, integration })).toBeUndefined();
|
||||
});
|
||||
});
|
||||
+13
-180
@@ -1,74 +1,17 @@
|
||||
import type { IntegrationSettings, IntegrationType } from "@shared/types";
|
||||
import { IntegrationService, MentionType } from "@shared/types";
|
||||
import type { MentionType } from "@shared/types";
|
||||
import type Integration from "~/models/Integration";
|
||||
|
||||
const gitlabSystemPaths = new Set([
|
||||
"explore",
|
||||
"help",
|
||||
"admin",
|
||||
"dashboard",
|
||||
"users",
|
||||
"groups",
|
||||
"projects",
|
||||
"snippets",
|
||||
"search",
|
||||
"-",
|
||||
]);
|
||||
|
||||
const giteaSystemPaths = new Set([
|
||||
"-",
|
||||
".well-known",
|
||||
"admin",
|
||||
"api",
|
||||
"assets",
|
||||
"attachments",
|
||||
"avatars",
|
||||
"explore",
|
||||
"issues",
|
||||
"login",
|
||||
"milestones",
|
||||
"notifications",
|
||||
"org",
|
||||
"pulls",
|
||||
"repo",
|
||||
"user",
|
||||
]);
|
||||
import { Hook, PluginManager } from "~/utils/PluginManager";
|
||||
|
||||
/**
|
||||
* Returns the path segments of a URL relative to a connected Gitea instance,
|
||||
* which can be served from a sub-path.
|
||||
* Returns the mention provider registered for the service of an integration.
|
||||
*
|
||||
* @param url the URL to split.
|
||||
* @param integration the Gitea integration.
|
||||
* @returns the path segments, or undefined if the URL is not on the instance.
|
||||
* @param integration the integration to find a provider for.
|
||||
* @returns the provider, or undefined if no plugin handles the service.
|
||||
*/
|
||||
const giteaPathParts = (
|
||||
url: URL,
|
||||
integration: Integration
|
||||
): string[] | undefined => {
|
||||
const settings =
|
||||
integration.settings as IntegrationSettings<IntegrationType.Embed>;
|
||||
if (!settings.gitea?.installation) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let base: URL;
|
||||
try {
|
||||
base = new URL(settings.gitea.url);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const basePath = base.pathname.replace(/\/+$/, "");
|
||||
if (
|
||||
url.host !== base.host ||
|
||||
(basePath && !url.pathname.startsWith(`${basePath}/`))
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return url.pathname.slice(basePath.length).split("/").filter(Boolean);
|
||||
};
|
||||
const getMentionProvider = (integration: Integration) =>
|
||||
PluginManager.getHooks(Hook.MentionProvider).find(
|
||||
(hook) => hook.value.service === integration.service
|
||||
)?.value;
|
||||
|
||||
/**
|
||||
* Checks whether a URL can be converted to a mention for the given
|
||||
@@ -83,49 +26,8 @@ export const isURLMentionable = ({
|
||||
}: {
|
||||
url: URL;
|
||||
integration: Integration;
|
||||
}): boolean => {
|
||||
const { hostname, pathname } = url;
|
||||
|
||||
switch (integration.service) {
|
||||
case IntegrationService.GitHub: {
|
||||
return hostname === "github.com";
|
||||
}
|
||||
|
||||
case IntegrationService.Linear: {
|
||||
const pathParts = pathname.split("/");
|
||||
const settings =
|
||||
integration.settings as IntegrationSettings<IntegrationType.Embed>;
|
||||
|
||||
return (
|
||||
hostname === "linear.app" &&
|
||||
settings.linear?.workspace.key === pathParts[1] // ensure installed workspace key matches with the provided url.
|
||||
);
|
||||
}
|
||||
|
||||
case IntegrationService.GitLab: {
|
||||
const settings =
|
||||
integration.settings as IntegrationSettings<IntegrationType.Embed>;
|
||||
let gitlabHostname: string | undefined;
|
||||
try {
|
||||
gitlabHostname = settings.gitlab?.url
|
||||
? new URL(settings.gitlab.url).hostname
|
||||
: undefined;
|
||||
} catch {
|
||||
// Invalid URL stored in settings
|
||||
return false;
|
||||
}
|
||||
|
||||
return hostname === "gitlab.com" || hostname === gitlabHostname;
|
||||
}
|
||||
|
||||
case IntegrationService.Gitea: {
|
||||
return !!giteaPathParts(url, integration);
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}): boolean =>
|
||||
getMentionProvider(integration)?.isMentionable(url, integration) ?? false;
|
||||
|
||||
/**
|
||||
* Determines the type of mention a URL represents for the given integration,
|
||||
@@ -140,74 +42,5 @@ export const determineMentionType = ({
|
||||
}: {
|
||||
url: URL;
|
||||
integration: Integration;
|
||||
}): MentionType | undefined => {
|
||||
const { pathname } = url;
|
||||
const pathParts = pathname.split("/");
|
||||
|
||||
switch (integration.service) {
|
||||
case IntegrationService.GitHub: {
|
||||
const type = pathParts[3];
|
||||
return type === "pull"
|
||||
? MentionType.PullRequest
|
||||
: type === "issues"
|
||||
? MentionType.Issue
|
||||
: type === "projects"
|
||||
? MentionType.Project
|
||||
: undefined;
|
||||
}
|
||||
|
||||
case IntegrationService.Linear: {
|
||||
const type = pathParts[2];
|
||||
return type === "issue"
|
||||
? MentionType.Issue
|
||||
: type === "project"
|
||||
? MentionType.Project
|
||||
: undefined;
|
||||
}
|
||||
|
||||
case IntegrationService.GitLab: {
|
||||
const hasShowParam = url.searchParams.has("show");
|
||||
|
||||
if (
|
||||
/\/-\/merge_requests\/\d+/.test(pathname) ||
|
||||
(/\/-\/merge_requests\/?$/.test(pathname) && hasShowParam)
|
||||
) {
|
||||
return MentionType.PullRequest;
|
||||
}
|
||||
if (
|
||||
/\/-\/(issues|work_items)\/\d+/.test(pathname) ||
|
||||
(/\/-\/(issues|work_items)\/?$/.test(pathname) && hasShowParam)
|
||||
) {
|
||||
return MentionType.Issue;
|
||||
}
|
||||
if (!pathname.includes("/-/")) {
|
||||
const parts = pathname.split("/").filter(Boolean);
|
||||
if (parts.length >= 2 && !gitlabSystemPaths.has(parts[0])) {
|
||||
return MentionType.Project;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
case IntegrationService.Gitea: {
|
||||
const parts = giteaPathParts(url, integration);
|
||||
if (!parts || parts.length < 2 || giteaSystemPaths.has(parts[0])) {
|
||||
return undefined;
|
||||
}
|
||||
if (parts.length === 2) {
|
||||
return MentionType.Project;
|
||||
}
|
||||
if (!/^\d+$/.test(parts[3] ?? "")) {
|
||||
return undefined;
|
||||
}
|
||||
return parts[2] === "pulls"
|
||||
? MentionType.PullRequest
|
||||
: parts[2] === "issues"
|
||||
? MentionType.Issue
|
||||
: undefined;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
};
|
||||
}): MentionType | undefined =>
|
||||
getMentionProvider(integration)?.mentionType(url, integration);
|
||||
@@ -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[] = [];
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
@@ -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(),
|
||||
},
|
||||
});
|
||||
}
|
||||
File renamed without changes.
@@ -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,
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -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/" },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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() }),
|
||||
}),
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
declare module "@shared/types" {
|
||||
interface EmbedIntegrationSettings {
|
||||
diagrams?: {
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -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(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -99,6 +99,7 @@ router.get(
|
||||
new UploadIntegrationLogoTask().schedule({
|
||||
integrationId: integration.id,
|
||||
logoUrl: figmaAccount.img_url,
|
||||
settingsPath: ["figma", "account", "avatarUrl"],
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
declare module "@shared/types" {
|
||||
interface LinkedAccountIntegrationSettings {
|
||||
figma?: {
|
||||
account: {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatarUrl: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -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;
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
declare module "@shared/types" {
|
||||
interface EmbedIntegrationSettings {
|
||||
gitea?: {
|
||||
url: string;
|
||||
installation?: {
|
||||
id: number;
|
||||
account: { id: number; name: string; avatarUrl: string };
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -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),
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -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" });
|
||||
});
|
||||
});
|
||||
@@ -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 &&
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
declare module "@shared/types" {
|
||||
interface EmbedIntegrationSettings {
|
||||
github?: {
|
||||
installation: {
|
||||
id: number;
|
||||
account: { id: number; name: string; avatarUrl: string };
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -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),
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -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" },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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(),
|
||||
}),
|
||||
});
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
declare module "@shared/types" {
|
||||
interface EmbedIntegrationSettings {
|
||||
gitlab?: {
|
||||
url?: string;
|
||||
installation?: {
|
||||
id: number;
|
||||
account: { id: number; name: string; avatarUrl: string };
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
@@ -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(),
|
||||
},
|
||||
},
|
||||
]);
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -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";
|
||||
|
||||
@@ -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
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -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),
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -105,6 +105,7 @@ router.get(
|
||||
await new UploadIntegrationLogoTask().schedule({
|
||||
integrationId: integration.id,
|
||||
logoUrl: workspace.logoUrl,
|
||||
settingsPath: ["linear", "workspace", "logoUrl"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
declare module "@shared/types" {
|
||||
interface EmbedIntegrationSettings {
|
||||
linear?: {
|
||||
workspace: { id: string; name: string; key: string; logoUrl?: string };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Vendored
File renamed without changes.
@@ -0,0 +1,7 @@
|
||||
declare module "@shared/types" {
|
||||
interface LinkedAccountIntegrationSettings {
|
||||
slack?: { serviceTeamId: string; serviceUserId: string };
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
Vendored
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,16 +40,7 @@ describe("errors", () => {
|
||||
name: "EmailAuthenticationRequiredError",
|
||||
fn: errors.EmailAuthenticationRequiredError,
|
||||
},
|
||||
{ name: "MicrosoftGraphError", fn: errors.MicrosoftGraphError },
|
||||
{ name: "TeamDomainRequiredError", fn: errors.TeamDomainRequiredError },
|
||||
{
|
||||
name: "GmailAccountCreationError",
|
||||
fn: errors.GmailAccountCreationError,
|
||||
},
|
||||
{
|
||||
name: "OIDCMalformedUserInfoError",
|
||||
fn: errors.OIDCMalformedUserInfoError,
|
||||
},
|
||||
{
|
||||
name: "AuthenticationProviderDisabledError",
|
||||
fn: errors.AuthenticationProviderDisabledError,
|
||||
|
||||
@@ -195,15 +195,6 @@ export function EmailAuthenticationRequiredError(
|
||||
});
|
||||
}
|
||||
|
||||
export function MicrosoftGraphError(
|
||||
message = "Microsoft Graph API did not return required fields"
|
||||
) {
|
||||
return httpErrors(400, message, {
|
||||
id: "graph_error",
|
||||
isReportable: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function TeamDomainRequiredError(
|
||||
message = "Unable to determine workspace from current domain or subdomain"
|
||||
) {
|
||||
@@ -213,24 +204,6 @@ export function TeamDomainRequiredError(
|
||||
});
|
||||
}
|
||||
|
||||
export function GmailAccountCreationError(
|
||||
message = "Cannot create account using personal Gmail address"
|
||||
) {
|
||||
return httpErrors(400, message, {
|
||||
id: "gmail_account_creation",
|
||||
isReportable: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function OIDCMalformedUserInfoError(
|
||||
message = "User profile information malformed"
|
||||
) {
|
||||
return httpErrors(400, message, {
|
||||
id: "malformed_user_info",
|
||||
isReportable: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function AuthenticationProviderDisabledError(
|
||||
message = "Authentication method has been disabled by an admin",
|
||||
redirectPath = "/"
|
||||
|
||||
@@ -72,7 +72,6 @@ function loadSentry(dsn: string): typeof SentryNode {
|
||||
// Authentication
|
||||
"UnauthorizedError",
|
||||
"TeamDomainRequiredError",
|
||||
"GmailAccountCreationError",
|
||||
"AuthRedirectError",
|
||||
"UserSuspendedError",
|
||||
"TooManyRequestsError",
|
||||
|
||||
@@ -26,11 +26,6 @@ import Team from "./Team";
|
||||
import UserAuthentication from "./UserAuthentication";
|
||||
import Length from "./validators/Length";
|
||||
|
||||
// TODO: Avoid this hardcoding of plugins
|
||||
import AzureClient from "plugins/azure/server/azure";
|
||||
import DiscordClient from "plugins/discord/server/discord";
|
||||
import GoogleClient from "plugins/google/server/google";
|
||||
import OIDCClient from "plugins/oidc/server/oidc";
|
||||
import type { APIContext } from "@server/types";
|
||||
import type { DestroyOptions } from "sequelize";
|
||||
|
||||
@@ -119,18 +114,9 @@ class AuthenticationProvider extends Model<
|
||||
* @returns A configured OAuthClient instance
|
||||
*/
|
||||
get oauthClient() {
|
||||
switch (this.name) {
|
||||
case "google":
|
||||
return new GoogleClient();
|
||||
case "azure":
|
||||
return new AzureClient();
|
||||
case "oidc":
|
||||
return new OIDCClient();
|
||||
case "discord":
|
||||
return new DiscordClient();
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
return AuthenticationHelper.providers
|
||||
.find((p) => p.value.id === this.name)
|
||||
?.value.oauthClient?.();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ import IntegrationAuthentication from "@server/models/IntegrationAuthentication"
|
||||
import Team from "@server/models/Team";
|
||||
import User from "@server/models/User";
|
||||
import ParanoidModel from "@server/models/base/ParanoidModel";
|
||||
import { Hook, PluginManager } from "@server/utils/PluginManager";
|
||||
|
||||
@Scopes(() => ({
|
||||
withAuthentication: {
|
||||
@@ -118,19 +119,7 @@ class Integration<T = unknown> extends ParanoidModel<
|
||||
case IntegrationType.Embed: {
|
||||
const settings = this
|
||||
.settings as IntegrationSettings<IntegrationType.Embed>;
|
||||
|
||||
// Guests only need the URLs used to render and edit embeds.
|
||||
if (viewer?.isGuest) {
|
||||
return { url: settings?.url, diagrams: settings?.diagrams };
|
||||
}
|
||||
return {
|
||||
url: settings?.url,
|
||||
github: settings?.github,
|
||||
gitlab: settings?.gitlab,
|
||||
gitea: settings?.gitea,
|
||||
linear: settings?.linear,
|
||||
diagrams: settings?.diagrams,
|
||||
};
|
||||
return { url: settings?.url, ...this.presentPluginSettings(viewer) };
|
||||
}
|
||||
case IntegrationType.Analytics: {
|
||||
const settings = this
|
||||
@@ -151,15 +140,31 @@ class Integration<T = unknown> extends ParanoidModel<
|
||||
if (!viewer || viewer.id !== this.userId) {
|
||||
return undefined;
|
||||
}
|
||||
const settings = this
|
||||
.settings as IntegrationSettings<IntegrationType.LinkedAccount>;
|
||||
return { figma: settings?.figma };
|
||||
return this.presentPluginSettings();
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Picks the settings keys that plugins registered for this service.
|
||||
*
|
||||
* @param viewer the user the settings are presented to, if any.
|
||||
* @returns the registered settings, keyed by name.
|
||||
*/
|
||||
private presentPluginSettings(viewer?: User) {
|
||||
const settings = this.settings as Record<string, unknown> | null;
|
||||
const keys = PluginManager.getHooks(Hook.IntegrationSettings)
|
||||
.filter(
|
||||
(hook) =>
|
||||
hook.value.service === this.service &&
|
||||
(!viewer?.isGuest || hook.value.visibleToGuests)
|
||||
)
|
||||
.flatMap((hook) => hook.value.keys);
|
||||
return Object.fromEntries(keys.map((key) => [key, settings?.[key]]));
|
||||
}
|
||||
|
||||
// hooks
|
||||
|
||||
@AfterDestroy
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import { buildIntegration, buildUser } from "@server/test/factories";
|
||||
import UploadIntegrationLogoTask from "./UploadIntegrationLogoTask";
|
||||
|
||||
describe("UploadIntegrationLogoTask", () => {
|
||||
it("should not change settings for jobs without a settings path", async () => {
|
||||
const user = await buildUser();
|
||||
const settings = { url: "https://example.com" };
|
||||
const integration = await buildIntegration({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
service: IntegrationService.Linear,
|
||||
type: IntegrationType.Embed,
|
||||
settings,
|
||||
});
|
||||
|
||||
await new UploadIntegrationLogoTask().perform({
|
||||
integrationId: integration.id,
|
||||
logoUrl: "https://example.com/logo.png",
|
||||
});
|
||||
|
||||
await integration.reload();
|
||||
expect(integration.settings).toEqual(settings);
|
||||
});
|
||||
});
|
||||
@@ -1,20 +1,17 @@
|
||||
import type { IntegrationType } from "@shared/types";
|
||||
import { IntegrationService, AttachmentPreset } from "@shared/types";
|
||||
import { cloneDeep, set } from "es-toolkit/compat";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import attachmentCreator from "@server/commands/attachmentCreator";
|
||||
import { createContext } from "@server/context";
|
||||
import { Integration, User } from "@server/models";
|
||||
import { BaseTask, TaskPriority } from "@server/queues/tasks/base/BaseTask";
|
||||
|
||||
const SupportedIntegrations = [
|
||||
IntegrationService.Linear,
|
||||
IntegrationService.Figma,
|
||||
];
|
||||
|
||||
type Props = {
|
||||
/** The integrationId to operate on */
|
||||
integrationId: string;
|
||||
/** The original logoUrl from third-party service */
|
||||
logoUrl: string;
|
||||
/** The path in the integration settings to store the uploaded url at, missing on older jobs */
|
||||
settingsPath?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -23,10 +20,15 @@ type Props = {
|
||||
*/
|
||||
export default class UploadIntegrationLogoTask extends BaseTask<Props> {
|
||||
public async perform(props: Props) {
|
||||
const { settingsPath } = props;
|
||||
if (!settingsPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
const integration = await Integration.scope("withAuthentication").findByPk(
|
||||
props.integrationId
|
||||
);
|
||||
if (!integration || !SupportedIntegrations.includes(integration.service)) {
|
||||
if (!integration) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,23 +54,11 @@ export default class UploadIntegrationLogoTask extends BaseTask<Props> {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (integration.service) {
|
||||
case IntegrationService.Linear:
|
||||
(
|
||||
integration as Integration<IntegrationType.Embed>
|
||||
).settings.linear!.workspace.logoUrl = attachment.url;
|
||||
break;
|
||||
case IntegrationService.Figma:
|
||||
(
|
||||
integration as Integration<IntegrationType.LinkedAccount>
|
||||
).settings.figma!.account.avatarUrl = attachment.url;
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unsupported integration service: ${integration.service}`
|
||||
); // This should never happen
|
||||
}
|
||||
|
||||
integration.settings = set(
|
||||
cloneDeep(integration.settings ?? {}),
|
||||
settingsPath,
|
||||
attachment.url
|
||||
);
|
||||
integration.changed("settings", true);
|
||||
await integration.save();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import type { NotionImportInput } from "@shared/schema";
|
||||
import {
|
||||
CollectionPermission,
|
||||
ImportableIntegrationService,
|
||||
ImportState,
|
||||
IntegrationService,
|
||||
IntegrationType,
|
||||
} from "@shared/types";
|
||||
import { ImportState, IntegrationService } from "@shared/types";
|
||||
import type { Import } from "@server/models";
|
||||
import { Integration } from "@server/models";
|
||||
import {
|
||||
buildAdmin,
|
||||
buildAttachment,
|
||||
buildImport,
|
||||
buildIntegration,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
@@ -19,71 +11,41 @@ import { getTestServer } from "@server/test/support";
|
||||
const server = getTestServer();
|
||||
|
||||
describe("#imports.create", () => {
|
||||
it("should create an import", async () => {
|
||||
it("should create an import from an uploaded file", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const integration = await Integration.create<
|
||||
Integration<IntegrationType.Import>
|
||||
>({
|
||||
service: IntegrationService.Notion,
|
||||
type: IntegrationType.Import,
|
||||
userId: admin.id,
|
||||
const attachment = await buildAttachment({
|
||||
teamId: admin.teamId,
|
||||
settings: {
|
||||
externalWorkspace: {
|
||||
id: "testId",
|
||||
name: "testWorkspaceName",
|
||||
},
|
||||
},
|
||||
userId: admin.id,
|
||||
});
|
||||
const input: NotionImportInput = [{ permission: undefined }];
|
||||
|
||||
const res = await server.post("/api/imports.create", admin, {
|
||||
body: {
|
||||
integrationId: integration.id,
|
||||
service: IntegrationService.Notion,
|
||||
input,
|
||||
attachmentId: attachment.id,
|
||||
service: IntegrationService.Markdown,
|
||||
},
|
||||
});
|
||||
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);
|
||||
expect(body.data.service).toEqual(IntegrationService.Markdown);
|
||||
});
|
||||
|
||||
it("should not allow more than one active import at a time", async () => {
|
||||
it("should reject an unknown service", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const integration = await buildIntegration({
|
||||
const attachment = await buildAttachment({
|
||||
teamId: admin.teamId,
|
||||
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: ImportableIntegrationService.Notion,
|
||||
input,
|
||||
attachmentId: attachment.id,
|
||||
service: "unknown",
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(422);
|
||||
expect(res.status).toEqual(400);
|
||||
});
|
||||
|
||||
it("should require authentication", async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { truncate } from "es-toolkit/compat";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import type { IntegrationType } from "@shared/types";
|
||||
import { ImportState, IntegrationService, UserRole } from "@shared/types";
|
||||
import { ImportState, UserRole } from "@shared/types";
|
||||
import { ImportValidation } from "@shared/validations";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { rateLimiter } from "@server/middlewares/rateLimiter";
|
||||
@@ -32,12 +32,7 @@ router.post(
|
||||
|
||||
authorize(user, "createImport", user.team);
|
||||
|
||||
if (
|
||||
body.service === IntegrationService.Markdown ||
|
||||
body.service === IntegrationService.Slab ||
|
||||
body.service === IntegrationService.OKF ||
|
||||
body.service === IntegrationService.JSON
|
||||
) {
|
||||
if ("attachmentId" in body) {
|
||||
const attachment = await Attachment.findByPk(body.attachmentId, {
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
|
||||
@@ -1,12 +1,40 @@
|
||||
import { z } from "zod";
|
||||
import { NotionImportInputItemSchema } from "@shared/schema";
|
||||
import { BaseImportInputItemSchema } from "@shared/schema";
|
||||
import {
|
||||
CollectionPermission,
|
||||
ImportableIntegrationService,
|
||||
IntegrationService,
|
||||
} from "@shared/types";
|
||||
import { Hook, PluginManager } from "@server/utils/PluginManager";
|
||||
import { BaseSchema } from "../schema";
|
||||
|
||||
/** The body to import an uploaded file. */
|
||||
export const AttachmentImportBodySchema = z.object({
|
||||
service: z.enum(ImportableIntegrationService),
|
||||
attachmentId: z.uuid(),
|
||||
permission: z.enum(CollectionPermission).optional(),
|
||||
});
|
||||
|
||||
/** The body to import from a connected integration. */
|
||||
export const IntegrationImportBodySchema = z.object({
|
||||
service: z.enum(ImportableIntegrationService),
|
||||
integrationId: z.uuid(),
|
||||
input: z.array(BaseImportInputItemSchema),
|
||||
});
|
||||
|
||||
/** A body that an import plugin accepts in imports.create. */
|
||||
export type ImportsCreateBody =
|
||||
| z.infer<typeof AttachmentImportBodySchema>
|
||||
| z.infer<typeof IntegrationImportBodySchema>;
|
||||
|
||||
// Resolved on first parse, after plugins have registered their schemas.
|
||||
const pluginBodies = z.lazy((): z.ZodType<ImportsCreateBody> => {
|
||||
const schemas = PluginManager.getHooks(Hook.ImportSchema).map(
|
||||
(hook) => hook.value
|
||||
);
|
||||
return schemas.length ? z.union(schemas) : z.never();
|
||||
});
|
||||
|
||||
const BaseIdSchema = z.object({
|
||||
/** Id of the import */
|
||||
id: z.uuid(),
|
||||
@@ -28,36 +56,16 @@ const ImportsSortParamsSchema = z.object({
|
||||
.transform((val) => (val !== "ASC" ? "DESC" : val)),
|
||||
});
|
||||
|
||||
const BaseBodySchema = z.object({
|
||||
integrationId: z.uuid(),
|
||||
});
|
||||
|
||||
export const ImportsCreateSchema = BaseSchema.extend({
|
||||
body: z.discriminatedUnion("service", [
|
||||
BaseBodySchema.extend({
|
||||
service: z.literal(IntegrationService.Notion),
|
||||
input: z.array(NotionImportInputItemSchema),
|
||||
}),
|
||||
z.object({
|
||||
service: z.literal(IntegrationService.Markdown),
|
||||
attachmentId: z.uuid(),
|
||||
permission: z.enum(CollectionPermission).optional(),
|
||||
}),
|
||||
z.object({
|
||||
service: z.literal(IntegrationService.Slab),
|
||||
attachmentId: z.uuid(),
|
||||
permission: z.enum(CollectionPermission).optional(),
|
||||
}),
|
||||
z.object({
|
||||
service: z.literal(IntegrationService.OKF),
|
||||
attachmentId: z.uuid(),
|
||||
permission: z.enum(CollectionPermission).optional(),
|
||||
}),
|
||||
z.object({
|
||||
service: z.literal(IntegrationService.JSON),
|
||||
attachmentId: z.uuid(),
|
||||
permission: z.enum(CollectionPermission).optional(),
|
||||
body: z.union([
|
||||
AttachmentImportBodySchema.extend({
|
||||
service: z.enum([
|
||||
IntegrationService.Markdown,
|
||||
IntegrationService.OKF,
|
||||
IntegrationService.JSON,
|
||||
]),
|
||||
}),
|
||||
pluginBodies,
|
||||
]),
|
||||
});
|
||||
|
||||
|
||||
@@ -283,16 +283,10 @@ describe("#integrations.list", () => {
|
||||
await buildIntegration({
|
||||
userId: admin.id,
|
||||
teamId: team.id,
|
||||
service: IntegrationService.GitHub,
|
||||
service: IntegrationService.Diagrams,
|
||||
type: IntegrationType.Embed,
|
||||
settings: {
|
||||
url: "https://example.com",
|
||||
github: {
|
||||
installation: {
|
||||
id: 123,
|
||||
account: { id: 456, name: "acme", avatarUrl: "" },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
await buildIntegration({
|
||||
@@ -314,32 +308,22 @@ describe("#integrations.list", () => {
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].type).toEqual(IntegrationType.Embed);
|
||||
expect(body.data[0].settings.url).toEqual("https://example.com");
|
||||
expect(body.data[0].settings.github).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#integrations.info", () => {
|
||||
const buildFigmaAccount = (owner: User) =>
|
||||
const buildLinkedAccount = (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",
|
||||
},
|
||||
},
|
||||
},
|
||||
settings: {},
|
||||
});
|
||||
|
||||
it("should expose linked account settings to the owner", async () => {
|
||||
const owner = await buildUser();
|
||||
const integration = await buildFigmaAccount(owner);
|
||||
const integration = await buildLinkedAccount(owner);
|
||||
|
||||
const res = await server.post("/api/integrations.info", owner, {
|
||||
body: { id: integration.id },
|
||||
@@ -347,13 +331,13 @@ describe("#integrations.info", () => {
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.settings.figma.account.email).toEqual("owner@example.com");
|
||||
expect(body.data.settings).toEqual({});
|
||||
});
|
||||
|
||||
it("should not allow other users to read a linked account", async () => {
|
||||
const owner = await buildUser();
|
||||
const admin = await buildAdmin({ teamId: owner.teamId });
|
||||
const integration = await buildFigmaAccount(owner);
|
||||
const integration = await buildLinkedAccount(owner);
|
||||
|
||||
const res = await server.post("/api/integrations.info", admin, {
|
||||
body: { id: integration.id },
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import { z } from "zod";
|
||||
import type { EmbedIntegrationSettings } from "@shared/types";
|
||||
import {
|
||||
IntegrationService,
|
||||
IntegrationType,
|
||||
UserCreatableIntegrationService,
|
||||
} from "@shared/types";
|
||||
import { Integration } from "@server/models";
|
||||
import { Hook, PluginManager } from "@server/utils/PluginManager";
|
||||
import { BaseSchema } from "../schema";
|
||||
|
||||
// Resolved on first parse, after plugins have registered their schemas.
|
||||
const pluginSettings = z.lazy((): z.ZodType<EmbedIntegrationSettings> => {
|
||||
const schemas = PluginManager.getHooks(Hook.IntegrationSettings).flatMap(
|
||||
(hook) => (hook.value.schema ? [hook.value.schema] : [])
|
||||
);
|
||||
return schemas.length ? z.union(schemas) : z.never();
|
||||
});
|
||||
|
||||
export const IntegrationsListSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
/** Integrations sorting direction */
|
||||
@@ -58,29 +68,8 @@ export const IntegrationsCreateSchema = BaseSchema.extend({
|
||||
scriptName: z.string().optional(),
|
||||
})
|
||||
)
|
||||
.or(
|
||||
z.object({
|
||||
diagrams: z.object({ url: z.url() }),
|
||||
})
|
||||
)
|
||||
.or(
|
||||
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(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.or(z.object({ serviceTeamId: z.string() }))
|
||||
.or(pluginSettings)
|
||||
.optional(),
|
||||
}),
|
||||
});
|
||||
@@ -109,29 +98,8 @@ export const IntegrationsUpdateSchema = BaseSchema.extend({
|
||||
scriptName: z.string().optional(),
|
||||
})
|
||||
)
|
||||
.or(
|
||||
z.object({
|
||||
diagrams: z.object({ url: z.url() }),
|
||||
})
|
||||
)
|
||||
.or(
|
||||
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(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.or(z.object({ serviceTeamId: z.string() }))
|
||||
.or(pluginSettings)
|
||||
.optional(),
|
||||
|
||||
/** Integration events */
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// @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 { createContext } from "@server/context";
|
||||
import env from "@server/env";
|
||||
import type { User } from "@server/models";
|
||||
@@ -12,13 +10,9 @@ import {
|
||||
buildDocument,
|
||||
buildShare,
|
||||
buildTeam,
|
||||
buildGuestUser,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import Redis from "@server/storage/redis";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
import { RedisPrefixHelper } from "@server/utils/RedisPrefixHelper";
|
||||
import Iframely from "plugins/iframely/server/iframely";
|
||||
|
||||
const resolveCname = vi.hoisted(
|
||||
() =>
|
||||
@@ -49,10 +43,6 @@ vi.mock("dns", () => ({
|
||||
resolveCname,
|
||||
}));
|
||||
|
||||
vi.spyOn(Iframely, "requestResource").mockImplementation(() =>
|
||||
Promise.resolve({})
|
||||
);
|
||||
|
||||
const server = getTestServer();
|
||||
|
||||
describe("#urls.unfurl", () => {
|
||||
@@ -504,132 +494,6 @@ Install instructions here.`
|
||||
});
|
||||
expect(res.status).toEqual(204);
|
||||
});
|
||||
|
||||
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 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
|
||||
);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#urls.checkEmbed", () => {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import type { IssueSource } from "@shared/schema";
|
||||
import type {
|
||||
IntegrationType,
|
||||
IssueTrackerIntegrationService,
|
||||
} from "@shared/types";
|
||||
import type { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import type { Integration } from "@server/models";
|
||||
|
||||
export abstract class BaseIssueProvider {
|
||||
service: IssueTrackerIntegrationService;
|
||||
service: IntegrationService;
|
||||
|
||||
constructor(service: IssueTrackerIntegrationService) {
|
||||
constructor(service: IntegrationService) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,15 @@ import path from "node:path";
|
||||
import { glob } from "glob";
|
||||
import type Router from "@koa/router";
|
||||
import { isArray, sortBy } from "es-toolkit/compat";
|
||||
import type { Concrete } from "@shared/types";
|
||||
import type { z } from "zod";
|
||||
import type {
|
||||
Concrete,
|
||||
EmbedIntegrationSettings,
|
||||
IntegrationService,
|
||||
LinkedAccountIntegrationSettings,
|
||||
} from "@shared/types";
|
||||
import type BaseEmail from "@server/emails/templates/BaseEmail";
|
||||
import type { ImportsCreateBody } from "@server/routes/api/imports/schema";
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import type BaseProcessor from "@server/queues/processors/BaseProcessor";
|
||||
@@ -13,6 +20,7 @@ import type {
|
||||
UnfurlSignature,
|
||||
UninstallSignature,
|
||||
} from "@server/types";
|
||||
import type OAuthClient from "./oauth";
|
||||
import type { BaseIssueProvider } from "./BaseIssueProvider";
|
||||
import type { GroupSyncProvider } from "./GroupSyncProvider";
|
||||
import type { BaseSearchProvider } from "./BaseSearchProvider";
|
||||
@@ -36,6 +44,8 @@ export enum Hook {
|
||||
API = "api",
|
||||
AuthProvider = "authProvider",
|
||||
EmailTemplate = "emailTemplate",
|
||||
ImportSchema = "importSchema",
|
||||
IntegrationSettings = "integrationSettings",
|
||||
IssueProvider = "issueProvider",
|
||||
Processor = "processor",
|
||||
SearchProvider = "searchProvider",
|
||||
@@ -60,9 +70,25 @@ type PluginValueMap = {
|
||||
* different Google Workspace domain, can sign in to a matching account.
|
||||
*/
|
||||
allowEmailMatch?: boolean;
|
||||
/** Creates a client to validate and refresh the provider's access tokens. */
|
||||
oauthClient?: () => OAuthClient;
|
||||
};
|
||||
// oxlint-disable-next-line @typescript-eslint/no-explicit-any -- typeof BaseEmail<EmailProps> isn't assignable from BaseEmail<Subtype>; plugins register heterogeneous template Props.
|
||||
[Hook.EmailTemplate]: Concrete<typeof BaseEmail<any>>;
|
||||
[Hook.ImportSchema]: z.ZodType<ImportsCreateBody>;
|
||||
[Hook.IntegrationSettings]: {
|
||||
/** The integration service that the settings belong to. */
|
||||
service: IntegrationService;
|
||||
/** The settings keys that are presented to clients. */
|
||||
keys: (
|
||||
| keyof EmbedIntegrationSettings
|
||||
| keyof LinkedAccountIntegrationSettings
|
||||
)[];
|
||||
/** Whether guests can see the keys, which only render and edit embeds. */
|
||||
visibleToGuests?: boolean;
|
||||
/** A schema to validate settings given through the integrations API. */
|
||||
schema?: z.ZodType<EmbedIntegrationSettings>;
|
||||
};
|
||||
[Hook.IssueProvider]: BaseIssueProvider;
|
||||
[Hook.MentionProvider]: MentionSignature;
|
||||
[Hook.Processor]: Concrete<typeof BaseProcessor>;
|
||||
|
||||
+8
-1
@@ -1,10 +1,17 @@
|
||||
import React from "react";
|
||||
import type { BaseIconProps } from ".";
|
||||
|
||||
export function GitHubIssueStatusIcon(props: BaseIconProps) {
|
||||
/**
|
||||
* A status icon for issue trackers that do not register their own.
|
||||
*
|
||||
* @param props the issue state and display options.
|
||||
* @returns the icon, or null for an unknown state.
|
||||
*/
|
||||
export function DefaultIssueStatusIcon(props: BaseIconProps) {
|
||||
const { state, className, size = 16 } = props;
|
||||
|
||||
switch (state.name) {
|
||||
case "opened":
|
||||
case "open":
|
||||
return (
|
||||
<svg
|
||||
@@ -1,38 +0,0 @@
|
||||
import React from "react";
|
||||
import type { BaseIconProps } from ".";
|
||||
|
||||
export function GitLabIssueStatusIcon(props: BaseIconProps) {
|
||||
const { state, className, size = 16 } = props;
|
||||
|
||||
switch (state.name) {
|
||||
case "opened":
|
||||
case "open":
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 16 16"
|
||||
width={size}
|
||||
height={size}
|
||||
fill={state.color}
|
||||
className={className}
|
||||
>
|
||||
<path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z" />
|
||||
<path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z" />
|
||||
</svg>
|
||||
);
|
||||
case "closed":
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 16 16"
|
||||
width={size}
|
||||
height={size}
|
||||
fill={state.color}
|
||||
className={className}
|
||||
>
|
||||
<path d="M11.28 6.78a.75.75 0 0 0-1.06-1.06L7.25 8.69 5.78 7.22a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.06 0l3.5-3.5Z" />
|
||||
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0Zm-1.5 0a6.5 6.5 0 1 0-13 0 6.5 6.5 0 0 0 13 0Z" />
|
||||
</svg>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -12,7 +12,13 @@ enum StateType {
|
||||
Canceled = "canceled",
|
||||
}
|
||||
|
||||
export function LinearIssueStatusIcon(props: BaseIconProps) {
|
||||
/**
|
||||
* A status icon for issues in a workflow, which shows the state type and progress.
|
||||
*
|
||||
* @param props the issue state and display options.
|
||||
* @returns the icon.
|
||||
*/
|
||||
export function WorkflowStatusIcon(props: BaseIconProps) {
|
||||
const theme = useTheme();
|
||||
const { state, size = 16 } = props;
|
||||
const percentage =
|
||||
@@ -1,14 +1,8 @@
|
||||
import * as React from "react";
|
||||
import styled from "styled-components";
|
||||
import type {
|
||||
IssueTrackerIntegrationService,
|
||||
UnfurlResourceType,
|
||||
UnfurlResponse,
|
||||
} from "../../types";
|
||||
import { IntegrationService } from "../../types";
|
||||
import { GitHubIssueStatusIcon } from "./GitHubIssueStatusIcon";
|
||||
import { LinearIssueStatusIcon } from "./LinearIssueStatusIcon";
|
||||
import { GitLabIssueStatusIcon } from "./GitLabIssueStatusIcon";
|
||||
import type { UnfurlResourceType, UnfurlResponse } from "../../types";
|
||||
import { DefaultIssueStatusIcon } from "./DefaultIssueStatusIcon";
|
||||
import { WorkflowStatusIcon } from "./WorkflowStatusIcon";
|
||||
|
||||
export type BaseIconProps = {
|
||||
state: UnfurlResponse[UnfurlResourceType.Issue]["state"];
|
||||
@@ -16,30 +10,25 @@ export type BaseIconProps = {
|
||||
size?: number;
|
||||
};
|
||||
|
||||
type Props = BaseIconProps & {
|
||||
service: IssueTrackerIntegrationService;
|
||||
};
|
||||
|
||||
export function IssueStatusIcon(props: Props) {
|
||||
/**
|
||||
* Renders the status icon of an issue. Issues with a workflow state type show
|
||||
* its progress, others show whether they are open or closed.
|
||||
*
|
||||
* @param props the issue state and display options.
|
||||
* @returns the icon.
|
||||
*/
|
||||
export function IssueStatusIcon(props: BaseIconProps) {
|
||||
return (
|
||||
<Icon size={props.size} className={props.className}>
|
||||
{getIcon(props)}
|
||||
{props.state.type ? (
|
||||
<WorkflowStatusIcon {...props} />
|
||||
) : (
|
||||
<DefaultIssueStatusIcon {...props} />
|
||||
)}
|
||||
</Icon>
|
||||
);
|
||||
}
|
||||
|
||||
function getIcon(props: Props) {
|
||||
switch (props.service) {
|
||||
case IntegrationService.GitHub:
|
||||
case IntegrationService.Gitea:
|
||||
return <GitHubIssueStatusIcon {...props} />;
|
||||
case IntegrationService.Linear:
|
||||
return <LinearIssueStatusIcon {...props} />;
|
||||
case IntegrationService.GitLab:
|
||||
return <GitLabIssueStatusIcon {...props} />;
|
||||
}
|
||||
}
|
||||
|
||||
const Icon = styled.span<{ size?: number }>`
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
|
||||
@@ -27,7 +27,6 @@ import useShare from "../../hooks/useShare";
|
||||
import env from "../../env";
|
||||
import theme from "../../styles/theme";
|
||||
import {
|
||||
IntegrationService,
|
||||
UnfurlResourceType,
|
||||
type JSONValue,
|
||||
type UnfurlResponse,
|
||||
@@ -362,19 +361,6 @@ export const MentionIssue = observer((props: IssuePrProps) => {
|
||||
|
||||
const issue = unfurl as UnfurlResponse[UnfurlResourceType.Issue];
|
||||
|
||||
let service = IntegrationService.GitLab;
|
||||
try {
|
||||
const parsedUrl = new URL(issue.url);
|
||||
service =
|
||||
parsedUrl.hostname === "github.com"
|
||||
? IntegrationService.GitHub
|
||||
: parsedUrl.hostname === "linear.app"
|
||||
? IntegrationService.Linear
|
||||
: IntegrationService.GitLab;
|
||||
} catch {
|
||||
// Invalid URL in unfurl data, default to GitLab
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
{...attrs}
|
||||
@@ -386,7 +372,7 @@ export const MentionIssue = observer((props: IssuePrProps) => {
|
||||
rel="noopener noreferrer nofollow"
|
||||
>
|
||||
<Flex align="center" gap={6}>
|
||||
<IssueStatusIcon size={14} service={service} state={issue.state} />
|
||||
<IssueStatusIcon size={14} state={issue.state} />
|
||||
<Flex align="center" gap={4}>
|
||||
<Text>
|
||||
<Backticks content={issue.title} />
|
||||
|
||||
@@ -90,6 +90,8 @@ export class EmbedDescriptor {
|
||||
component?: React.FunctionComponent<EmbedProps>;
|
||||
/** The integration settings, if any */
|
||||
settings?: IntegrationSettings<IntegrationType.Embed>;
|
||||
/** The URL of the instance that the integration is configured with, if any */
|
||||
instanceUrl?: string;
|
||||
/** Whether this embed has been disabled by the team admin */
|
||||
disabled?: boolean;
|
||||
|
||||
|
||||
@@ -272,9 +272,8 @@ export default class Diagrams extends Extension {
|
||||
);
|
||||
const uiTheme = this.editor.props.theme.isDark ? "dark" : "atlas";
|
||||
return (
|
||||
sanitizeUrl(
|
||||
integration?.settings?.diagrams?.url ?? "https://embed.diagrams.net/"
|
||||
) + `?embed=1&ui=${uiTheme}&spin=1&modified=unsavedChanges&proto=json`
|
||||
sanitizeUrl(integration?.instanceUrl ?? "https://embed.diagrams.net/") +
|
||||
`?embed=1&ui=${uiTheme}&spin=1&modified=unsavedChanges&proto=json`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+30
-53
@@ -1,29 +1,17 @@
|
||||
import { z } from "zod";
|
||||
import type {
|
||||
IntegrationService,
|
||||
ProsemirrorData,
|
||||
ProsemirrorDoc,
|
||||
} from "./types";
|
||||
import type { ProsemirrorData, ProsemirrorDoc } from "./types";
|
||||
import {
|
||||
CollectionPermission,
|
||||
type ImportableIntegrationService,
|
||||
IssueTrackerIntegrationService,
|
||||
IntegrationService,
|
||||
} from "./types";
|
||||
import { PageType } from "plugins/notion/shared/types";
|
||||
|
||||
const BaseImportInputItemSchema = z.object({
|
||||
export const BaseImportInputItemSchema = z.object({
|
||||
permission: z.enum(CollectionPermission).optional(),
|
||||
});
|
||||
|
||||
export type BaseImportInput = z.infer<typeof BaseImportInputItemSchema>[];
|
||||
|
||||
export const NotionImportInputItemSchema = BaseImportInputItemSchema.extend({
|
||||
type: z.enum(PageType).optional(),
|
||||
externalId: z.string().optional(),
|
||||
});
|
||||
|
||||
export type NotionImportInput = z.infer<typeof NotionImportInputItemSchema>[];
|
||||
|
||||
export const MarkdownImportInputItemSchema = BaseImportInputItemSchema.extend({
|
||||
externalId: z.string(),
|
||||
});
|
||||
@@ -38,17 +26,15 @@ export const JSONImportInputItemSchema = BaseImportInputItemSchema.extend({
|
||||
|
||||
export type JSONImportInput = z.infer<typeof JSONImportInputItemSchema>[];
|
||||
|
||||
/** The import input by service, plugins augment it with their importers. */
|
||||
export interface ImportInputMap {
|
||||
[IntegrationService.Markdown]: MarkdownImportInput;
|
||||
[IntegrationService.OKF]: MarkdownImportInput;
|
||||
[IntegrationService.JSON]: JSONImportInput;
|
||||
}
|
||||
|
||||
export type ImportInput<T extends ImportableIntegrationService> =
|
||||
T extends IntegrationService.Notion
|
||||
? NotionImportInput
|
||||
: T extends
|
||||
| IntegrationService.Markdown
|
||||
| IntegrationService.Slab
|
||||
| IntegrationService.OKF
|
||||
? MarkdownImportInput
|
||||
: T extends IntegrationService.JSON
|
||||
? JSONImportInput
|
||||
: BaseImportInput;
|
||||
T extends keyof ImportInputMap ? ImportInputMap[T] : BaseImportInput;
|
||||
|
||||
export const BaseImportTaskInputItemSchema = z.object({
|
||||
externalId: z.string(),
|
||||
@@ -60,15 +46,6 @@ export type BaseImportTaskInput = z.infer<
|
||||
typeof BaseImportTaskInputItemSchema
|
||||
>[];
|
||||
|
||||
export const NotionImportTaskInputItemSchema =
|
||||
BaseImportTaskInputItemSchema.extend({
|
||||
type: z.enum(PageType),
|
||||
});
|
||||
|
||||
export type NotionImportTaskInput = z.infer<
|
||||
typeof NotionImportTaskInputItemSchema
|
||||
>[];
|
||||
|
||||
/**
|
||||
* Manifest entry describing a single attachment discovered during the
|
||||
* Markdown zip bootstrap phase. The `id` is a pre-assigned UUID used both
|
||||
@@ -134,14 +111,14 @@ export interface JSONImportScratch {
|
||||
* isn't part of any single task's input. Cleared when the import flips to
|
||||
* `Completed`.
|
||||
*/
|
||||
export type ImportScratch<T extends ImportableIntegrationService> = T extends
|
||||
| IntegrationService.Markdown
|
||||
| IntegrationService.Slab
|
||||
| IntegrationService.OKF
|
||||
? MarkdownImportScratch
|
||||
: T extends IntegrationService.JSON
|
||||
? JSONImportScratch
|
||||
: never;
|
||||
export interface ImportScratchMap {
|
||||
[IntegrationService.Markdown]: MarkdownImportScratch;
|
||||
[IntegrationService.OKF]: MarkdownImportScratch;
|
||||
[IntegrationService.JSON]: JSONImportScratch;
|
||||
}
|
||||
|
||||
export type ImportScratch<T extends ImportableIntegrationService> =
|
||||
T extends keyof ImportScratchMap ? ImportScratchMap[T] : never;
|
||||
|
||||
/**
|
||||
* Per-page task input. Generated by the bootstrap task and consumed by
|
||||
@@ -215,17 +192,17 @@ export type JSONImportTaskInput = (
|
||||
| JSONPageImportTaskInputItem
|
||||
)[];
|
||||
|
||||
/** The import task input by service, plugins augment it with their importers. */
|
||||
export interface ImportTaskInputMap {
|
||||
[IntegrationService.Markdown]: MarkdownImportTaskInput;
|
||||
[IntegrationService.OKF]: MarkdownImportTaskInput;
|
||||
[IntegrationService.JSON]: JSONImportTaskInput;
|
||||
}
|
||||
|
||||
export type ImportTaskInput<T extends ImportableIntegrationService> =
|
||||
T extends IntegrationService.Notion
|
||||
? NotionImportTaskInput
|
||||
: T extends
|
||||
| IntegrationService.Markdown
|
||||
| IntegrationService.Slab
|
||||
| IntegrationService.OKF
|
||||
? MarkdownImportTaskInput
|
||||
: T extends IntegrationService.JSON
|
||||
? JSONImportTaskInput
|
||||
: BaseImportTaskInput;
|
||||
T extends keyof ImportTaskInputMap
|
||||
? ImportTaskInputMap[T]
|
||||
: BaseImportTaskInput;
|
||||
|
||||
// No reason to be here except for co-location with import task input.
|
||||
export type ImportTaskOutput = {
|
||||
@@ -252,7 +229,7 @@ export const IssueSource = z.object({
|
||||
id: z.string().nonempty(),
|
||||
name: z.string().nonempty(),
|
||||
}),
|
||||
service: z.enum(IssueTrackerIntegrationService),
|
||||
service: z.enum(IntegrationService),
|
||||
});
|
||||
|
||||
export type IssueSource = z.infer<typeof IssueSource>;
|
||||
@@ -53,23 +53,6 @@ export const ImportableIntegrationService = {
|
||||
JSON: IntegrationService.JSON,
|
||||
} as const;
|
||||
|
||||
/** Integration services that are issue trackers. */
|
||||
export type IssueTrackerIntegrationService = Extract<
|
||||
IntegrationService,
|
||||
| IntegrationService.GitHub
|
||||
| IntegrationService.GitLab
|
||||
| IntegrationService.Gitea
|
||||
| IntegrationService.Linear
|
||||
>;
|
||||
|
||||
/** Runtime values of `IssueTrackerIntegrationService`. */
|
||||
export const IssueTrackerIntegrationService = {
|
||||
GitHub: IntegrationService.GitHub,
|
||||
GitLab: IntegrationService.GitLab,
|
||||
Gitea: IntegrationService.Gitea,
|
||||
Linear: IntegrationService.Linear,
|
||||
} as const;
|
||||
|
||||
/** Integration services that can be created through the API. */
|
||||
export type UserCreatableIntegrationService = Extract<
|
||||
IntegrationService,
|
||||
@@ -91,37 +74,28 @@ export const UserCreatableIntegrationService = {
|
||||
GitLab: IntegrationService.GitLab,
|
||||
} as const;
|
||||
|
||||
/** The settings stored on an embed integration, plugins augment it with their keys. */
|
||||
export interface EmbedIntegrationSettings {
|
||||
url?: string;
|
||||
}
|
||||
|
||||
/** The settings stored on a linked account integration, plugins augment it with their keys. */
|
||||
// oxlint-disable-next-line typescript/no-empty-object-type -- populated by module augmentation.
|
||||
export interface LinkedAccountIntegrationSettings {}
|
||||
|
||||
// Mapped copies, because interfaces are not assignable to JSON index signatures.
|
||||
type EmbedSettings = Pick<
|
||||
EmbedIntegrationSettings,
|
||||
keyof EmbedIntegrationSettings
|
||||
>;
|
||||
type LinkedAccountSettings = Pick<
|
||||
LinkedAccountIntegrationSettings,
|
||||
keyof LinkedAccountIntegrationSettings
|
||||
>;
|
||||
|
||||
/** The settings stored on an integration, by integration type. */
|
||||
export type IntegrationSettings<T> = T extends IntegrationType.Embed
|
||||
? {
|
||||
url?: string;
|
||||
github?: {
|
||||
installation: {
|
||||
id: number;
|
||||
account: { id: number; name: string; avatarUrl: string };
|
||||
};
|
||||
};
|
||||
gitlab?: {
|
||||
url?: string;
|
||||
installation?: {
|
||||
id: number;
|
||||
account: { id: number; name: string; avatarUrl: string };
|
||||
};
|
||||
};
|
||||
gitea?: {
|
||||
url: string;
|
||||
installation?: {
|
||||
id: number;
|
||||
account: { id: number; name: string; avatarUrl: string };
|
||||
};
|
||||
};
|
||||
linear?: {
|
||||
workspace: { id: string; name: string; key: string; logoUrl?: string };
|
||||
};
|
||||
diagrams?: {
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
? EmbedSettings
|
||||
: T extends IntegrationType.Analytics
|
||||
? { measurementId: string; instanceUrl?: string; scriptName?: string }
|
||||
: T extends IntegrationType.Post
|
||||
@@ -133,56 +107,10 @@ export type IntegrationSettings<T> = T extends IntegrationType.Embed
|
||||
externalWorkspace: { id: string; name: string; iconUrl?: string };
|
||||
}
|
||||
: T extends IntegrationType.LinkedAccount
|
||||
? {
|
||||
slack?: { serviceTeamId: string; serviceUserId: string };
|
||||
figma?: {
|
||||
account: {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatarUrl: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
? LinkedAccountSettings
|
||||
:
|
||||
| { url: string }
|
||||
| {
|
||||
github?: {
|
||||
installation: {
|
||||
id: number;
|
||||
account: {
|
||||
id?: number;
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
gitlab?: {
|
||||
url?: string;
|
||||
installation?: {
|
||||
id: number;
|
||||
account: {
|
||||
id?: number;
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
gitea?: {
|
||||
url: string;
|
||||
installation?: {
|
||||
id: number;
|
||||
account: {
|
||||
id?: number;
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
diagrams?: {
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
| EmbedSettings
|
||||
| { serviceTeamId: string }
|
||||
| {
|
||||
measurementId: string;
|
||||
|
||||
Reference in new issue
Block a user