- {pagesWithPermission?.map((page) => (
+ {pagesWithPermission.map((page) => (
extends IdModel<
+ InferAttributes>,
+ Partial>>
+> {
+ @IsIn([Object.values(IntegrationService)])
+ @Column(DataType.STRING)
+ service: IntegrationService;
+
+ @IsIn([Object.values(ImportState)])
+ @Column(DataType.STRING)
+ state: ImportState;
+
+ @Column(DataType.JSONB)
+ data: ImportData;
+
+ @Default(0)
+ @Column(DataType.INTEGER)
+ pendingTaskCount: number;
+
+ // associations
+
+ @BelongsTo(() => User, "createdById")
+ createdBy: User;
+
+ @ForeignKey(() => User)
+ @Column(DataType.UUID)
+ createdById: string;
+
+ @BelongsTo(() => Integration, "integrationId")
+ integration: Integration;
+
+ @ForeignKey(() => Integration)
+ @Column(DataType.UUID)
+ integrationId: string;
+}
+
+export default Import;
diff --git a/server/models/index.ts b/server/models/index.ts
index 3edc7b7fdb..1ba5dc1df3 100644
--- a/server/models/index.ts
+++ b/server/models/index.ts
@@ -24,6 +24,8 @@ export { default as Group } from "./Group";
export { default as GroupUser } from "./GroupUser";
+export { default as Import } from "./Import";
+
export { default as Integration } from "./Integration";
export { default as IntegrationAuthentication } from "./IntegrationAuthentication";
diff --git a/server/routes/api/imports/imports.ts b/server/routes/api/imports/imports.ts
new file mode 100644
index 0000000000..9a9dd2de93
--- /dev/null
+++ b/server/routes/api/imports/imports.ts
@@ -0,0 +1,36 @@
+import Router from "koa-router";
+import { ImportState, UserRole } from "@shared/types";
+import auth from "@server/middlewares/authentication";
+import validate from "@server/middlewares/validate";
+import Import from "@server/models/Import";
+import { authorize } from "@server/policies";
+import { APIContext } from "@server/types";
+import * as T from "./schema";
+
+const router = new Router();
+
+router.post(
+ "imports.create",
+ auth({ role: UserRole.Admin }),
+ validate(T.ImportsCreateSchema),
+ async (ctx: APIContext) => {
+ const { integrationId, service, data } = ctx.input.body;
+ const { user } = ctx.state.auth;
+
+ authorize(user, "createImport", user.team);
+
+ await Import.create({
+ service,
+ state: ImportState.Created,
+ data,
+ createdById: user.id,
+ integrationId,
+ });
+
+ ctx.body = {
+ success: true,
+ };
+ }
+);
+
+export default router;
diff --git a/server/routes/api/imports/index.ts b/server/routes/api/imports/index.ts
new file mode 100644
index 0000000000..01e8fb8633
--- /dev/null
+++ b/server/routes/api/imports/index.ts
@@ -0,0 +1 @@
+export { default } from "./imports";
diff --git a/server/routes/api/imports/schema.ts b/server/routes/api/imports/schema.ts
new file mode 100644
index 0000000000..dbfb257113
--- /dev/null
+++ b/server/routes/api/imports/schema.ts
@@ -0,0 +1,20 @@
+import { z } from "zod";
+import { CollectionPermission, IntegrationService } from "@shared/types";
+import { BaseSchema } from "../schema";
+
+export const ImportsCreateSchema = BaseSchema.extend({
+ body: z.object({
+ integrationId: z.string().uuid(),
+ service: z.nativeEnum(IntegrationService),
+ data: z.object({
+ collection: z.array(
+ z.object({
+ externalId: z.string(),
+ permission: z.nativeEnum(CollectionPermission).optional(),
+ })
+ ),
+ }),
+ }),
+});
+
+export type ImportsCreateReq = z.infer;
diff --git a/server/routes/api/index.ts b/server/routes/api/index.ts
index 2ca9bd2085..65e36e35a3 100644
--- a/server/routes/api/index.ts
+++ b/server/routes/api/index.ts
@@ -20,6 +20,7 @@ import events from "./events";
import fileOperationsRoute from "./fileOperations";
import groupMemberships from "./groupMemberships";
import groups from "./groups";
+import imports from "./imports";
import installation from "./installation";
import integrations from "./integrations";
import apiErrorHandler from "./middlewares/apiErrorHandler";
@@ -97,6 +98,7 @@ router.use("/", fileOperationsRoute.routes());
router.use("/", urls.routes());
router.use("/", userMemberships.routes());
router.use("/", reactions.routes());
+router.use("/", imports.routes());
if (!env.isCloudHosted) {
router.use("/", installation.routes());
diff --git a/shared/types.ts b/shared/types.ts
index 431639ebad..52f486b481 100644
--- a/shared/types.ts
+++ b/shared/types.ts
@@ -54,6 +54,18 @@ export enum FileOperationState {
Expired = "expired",
}
+export enum ImportState {
+ Created = "created",
+ InProgress = "in_progress",
+ Processed = "processed",
+ Completed = "completed",
+ Errored = "errored",
+}
+
+export type ImportData = {
+ collection: { externalId: string; permission?: CollectionPermission }[];
+};
+
export enum MentionType {
User = "user",
Document = "document",