* wip * stash * fix: make authenticationId nullable fk * fix: apply generics to resolve compile time type errors * fix: loosen integration settings * chore: refactor into functional component * feat: pass integrations all the way to embeds * perf: avoid re-fetching integrations * fix: change attr name to avoid type overlap * feat: use hostname from embed settings in matcher * Revert "feat: use hostname from embed settings in matcher" This reverts commit e7485d9cda4dcf45104e460465ca104a56c67ddc. * feat: refactor into a class * chore: refactor url regex formation as a util * fix: escape regex special chars * fix: remove in-house escapeRegExp in favor of lodash's * fix: sanitize url * perf: memoize embeds * fix: rename hostname to url and allow spreading entire settings instead of just url * fix: replace diagrams with drawio * fix: rename * fix: support self-hosted and saas both * fix: assert on settings url * fix: move embed integrations loading to hook * fix: address review comments * fix: use observer in favor of explicit state setters * fix: refactor useEmbedIntegrations into useEmbeds * fix: use translations for toasts Co-authored-by: Tom Moor <tom.moor@gmail.com>
89 lines
1.9 KiB
TypeScript
89 lines
1.9 KiB
TypeScript
import {
|
|
ForeignKey,
|
|
BelongsTo,
|
|
Column,
|
|
Table,
|
|
DataType,
|
|
Scopes,
|
|
IsIn,
|
|
} from "sequelize-typescript";
|
|
import { IntegrationType } from "@shared/types";
|
|
import type { IntegrationSettings } from "@shared/types";
|
|
import Collection from "./Collection";
|
|
import IntegrationAuthentication from "./IntegrationAuthentication";
|
|
import Team from "./Team";
|
|
import User from "./User";
|
|
import IdModel from "./base/IdModel";
|
|
import Fix from "./decorators/Fix";
|
|
|
|
export enum IntegrationService {
|
|
Diagrams = "diagrams",
|
|
Slack = "slack",
|
|
}
|
|
|
|
export enum UserCreatableIntegrationService {
|
|
Diagrams = "diagrams",
|
|
}
|
|
|
|
@Scopes(() => ({
|
|
withAuthentication: {
|
|
include: [
|
|
{
|
|
model: IntegrationAuthentication,
|
|
as: "authentication",
|
|
required: true,
|
|
},
|
|
],
|
|
},
|
|
}))
|
|
@Table({ tableName: "integrations", modelName: "integration" })
|
|
@Fix
|
|
class Integration<T = unknown> extends IdModel {
|
|
@IsIn([Object.values(IntegrationType)])
|
|
@Column
|
|
type: string;
|
|
|
|
@IsIn([Object.values(IntegrationService)])
|
|
@Column
|
|
service: string;
|
|
|
|
@Column(DataType.JSONB)
|
|
settings: IntegrationSettings<T>;
|
|
|
|
@IsIn([["documents.update", "documents.publish"]])
|
|
@Column(DataType.ARRAY(DataType.STRING))
|
|
events: string[];
|
|
|
|
// associations
|
|
|
|
@BelongsTo(() => User, "userId")
|
|
user: User;
|
|
|
|
@ForeignKey(() => User)
|
|
@Column(DataType.UUID)
|
|
userId: string;
|
|
|
|
@BelongsTo(() => Team, "teamId")
|
|
team: Team;
|
|
|
|
@ForeignKey(() => Team)
|
|
@Column(DataType.UUID)
|
|
teamId: string;
|
|
|
|
@BelongsTo(() => Collection, "collectionId")
|
|
collection: Collection;
|
|
|
|
@ForeignKey(() => Collection)
|
|
@Column(DataType.UUID)
|
|
collectionId: string;
|
|
|
|
@BelongsTo(() => IntegrationAuthentication, "authenticationId")
|
|
authentication: IntegrationAuthentication;
|
|
|
|
@ForeignKey(() => IntegrationAuthentication)
|
|
@Column(DataType.UUID)
|
|
authenticationId: string;
|
|
}
|
|
|
|
export default Integration;
|