Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

Merge origin/main into feat/add-user-notifications-integrations

Tin3a5744433e45
diff --cc apps/api/src/index.ts
index ce4c29909,d84341484..28052adb5
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@@ -321,147 -331,213 +332,218 @@@ export function createApp()
),
),
),
- ),
- );
- });
+ );
+ });
- api.on(["POST", "GET", "PUT", "DELETE"], "/auth/*", (c) => {
- const authHeader = c.req.header("Authorization");
+ api.on(["POST", "GET", "PUT", "DELETE"], "/auth/*", (c) => {
+ const authHeader = c.req.header("Authorization");
- if (authHeader?.startsWith("Bearer ")) {
- const apiKey = authHeader.substring(7).replace(/\s+/g, "").trim();
- const headers = new Headers(c.req.raw.headers);
+ if (authHeader?.startsWith("Bearer ")) {
+ const apiKey = authHeader.substring(7).replace(/\s+/g, "").trim();
+ const headers = new Headers(c.req.raw.headers);
- // Better Auth API key plugin validates from x-api-key by default.
- if (!headers.get("x-api-key")) {
- headers.set("x-api-key", apiKey);
- }
+ // Better Auth API key plugin validates from x-api-key by default.
+ if (!headers.get("x-api-key")) {
+ headers.set("x-api-key", apiKey);
+ }
- return auth.handler(
- new Request(c.req.raw, {
- headers,
- }),
- );
- }
+ return auth.handler(
+ new Request(c.req.raw, {
+ headers,
+ }),
+ );
+ }
- return auth.handler(c.req.raw);
- });
+ return auth.handler(c.req.raw);
+ });
- api.use("*", async (c, next) => {
- const authHeader = c.req.header("Authorization");
- if (authHeader?.startsWith("Bearer ")) {
- const apiKey = authHeader.substring(7).replace(/\s+/g, "").trim();
+ api.use("*", async (c, next) => {
+ const authHeader = c.req.header("Authorization");
+ if (authHeader?.startsWith("Bearer ")) {
+ const apiKey = authHeader.substring(7).replace(/\s+/g, "").trim();
+
+ try {
+ const result = await verifyApiKey(apiKey);
-
+ if (result?.valid && result.key) {
+ c.set("userId", result.key.userId);
+ c.set("user", null);
+ c.set("session", null);
+ c.set("apiKey", {
+ id: result.key.id,
+ userId: result.key.userId,
+ enabled: result.key.enabled,
+ });
+ return next();
+ }
- try {
- const result = await verifyApiKey(apiKey);
-
- if (result?.valid && result.key) {
- c.set("userId", result.key.userId);
- c.set("user", null);
- c.set("session", null);
- c.set("apiKey", {
- id: result.key.id,
- userId: result.key.userId,
- enabled: result.key.enabled,
+ throw new HTTPException(401, { message: "Invalid API key" });
+ } catch (error) {
+ if (error instanceof HTTPException) {
+ throw error;
+ }
+ console.error("API key verification failed:", error);
+ throw new HTTPException(401, {
+ message: "API key verification failed",
});
- return next();
}
+ }
- throw new HTTPException(401, { message: "Invalid API key" });
- } catch (error) {
- if (error instanceof HTTPException) {
- throw error;
- }
- console.error("API key verification failed:", error);
- throw new HTTPException(401, { message: "API key verification failed" });
+ const session = await auth.api.getSession({ headers: c.req.raw.headers });
+ c.set("user", session?.user || null);
+ c.set("session", session?.session || null);
+ c.set("userId", session?.user?.id || "");
+ c.set("userEmail", session?.user?.email || "");
+
+ if (!session?.user) {
+ throw new HTTPException(401, { message: "Unauthorized" });
}
- }
- const session = await auth.api.getSession({ headers: c.req.raw.headers });
- c.set("user", session?.user || null);
- c.set("session", session?.session || null);
- c.set("userId", session?.user?.id || "");
- c.set("userEmail", session?.user?.email || "");
+ return next();
+ });
+
+ const projectApi = api.route("/project", project);
+ const taskApi = api.route("/task", task);
+ const columnApi = api.route("/column", column);
+ const activityApi = api.route("/activity", activity);
+ const commentApi = api.route("/comment", comment);
+ const timeEntryApi = api.route("/time-entry", timeEntry);
+ const labelApi = api.route("/label", label);
+ const notificationApi = api.route("/notification", notification);
++ const notificationPreferencesApi = api.route(
++ "/notification-preferences",
++ notificationPreferences,
++ );
+ const searchApi = api.route("/search", search);
+ const githubIntegrationApi = api.route(
+ "/github-integration",
+ githubIntegration,
+ );
+ const giteaIntegrationApi = api.route("/gitea-integration", giteaIntegration);
+ const genericWebhookIntegrationApi = api.route(
+ "/generic-webhook-integration",
+ genericWebhookIntegration,
+ );
+ const discordIntegrationApi = api.route(
+ "/discord-integration",
+ discordIntegration,
+ );
+ const slackIntegrationApi = api.route("/slack-integration", slackIntegration);
+ const telegramIntegrationApi = api.route(
+ "/telegram-integration",
+ telegramIntegration,
+ );
+ const taskRelationApi = api.route("/task-relation", taskRelation);
+ const externalLinkApi = api.route("/external-link", externalLink);
+ const workflowRuleApi = api.route("/workflow-rule", workflowRule);
+ const invitationApi = api.route("/invitation", invitation);
+ const workspaceApi = api.route("/workspace", workspace);
+
+ app.route("/api", api);
+
+ return {
+ app,
+ api,
+ activityApi,
+ columnApi,
+ commentApi,
+ configApi,
+ discordIntegrationApi,
+ externalLinkApi,
+ genericWebhookIntegrationApi,
+ githubIntegrationApi,
+ giteaIntegrationApi,
+ invitationApi,
+ invitationPublicApi,
+ labelApi,
+ notificationApi,
++ notificationPreferencesApi,
+ projectApi,
+ publicProjectApi,
+ searchApi,
+ slackIntegrationApi,
+ taskApi,
+ taskRelationApi,
+ telegramIntegrationApi,
+ timeEntryApi,
+ workflowRuleApi,
+ workspaceApi,
+ };
+ }
- if (!session?.user) {
- throw new HTTPException(401, { message: "Unauthorized" });
- }
+ export async function runStartupTasks() {
+ await migrateWorkspaceUserEmail();
+ await migrateSessionColumn();
+ await migrateApiKeyReferenceId();
- return next();
- });
-
- const projectApi = api.route("/project", project);
- const taskApi = api.route("/task", task);
- const columnApi = api.route("/column", column);
- const activityApi = api.route("/activity", activity);
- const commentApi = api.route("/comment", comment);
- const timeEntryApi = api.route("/time-entry", timeEntry);
- const labelApi = api.route("/label", label);
- const notificationApi = api.route("/notification", notification);
- const notificationPreferencesApi = api.route(
- "/notification-preferences",
- notificationPreferences,
- );
- const searchApi = api.route("/search", search);
- const githubIntegrationApi = api.route(
- "/github-integration",
- githubIntegration,
- );
- const giteaIntegrationApi = api.route("/gitea-integration", giteaIntegration);
- const genericWebhookIntegrationApi = api.route(
- "/generic-webhook-integration",
- genericWebhookIntegration,
- );
- const discordIntegrationApi = api.route(
- "/discord-integration",
- discordIntegration,
- );
- const slackIntegrationApi = api.route("/slack-integration", slackIntegration);
- const telegramIntegrationApi = api.route(
- "/telegram-integration",
- telegramIntegration,
- );
- const taskRelationApi = api.route("/task-relation", taskRelation);
- const externalLinkApi = api.route("/external-link", externalLink);
- const workflowRuleApi = api.route("/workflow-rule", workflowRule);
- const invitationApi = api.route("/invitation", invitation);
- const workspaceApi = api.route("/workspace", workspace);
-
- app.route("/api", api);
-
- (async () => {
- try {
- await migrateWorkspaceUserEmail();
- await migrateSessionColumn();
- await migrateApiKeyReferenceId();
+ console.log("🔄 Migrating database...");
+ await migrate(db, {
+ migrationsFolder: `${process.cwd()}/drizzle`,
+ });
+ console.log("✅ Database migrated successfully!");
- console.log("🔄 Migrating database...");
- await migrate(db, {
- migrationsFolder: `${process.cwd()}/drizzle`,
- });
- console.log("✅ Database migrated successfully!");
+ await migrateGitHubIntegration();
+ await migrateColumns();
- await migrateGitHubIntegration();
- await migrateColumns();
+ initializePlugins();
+ }
- initializePlugins();
+ export async function startServer(port = 1337) {
+ try {
+ await runStartupTasks();
} catch (error) {
console.error("❌ Database migration failed!", error);
process.exit(1);
}
- })();
-
- serve(
- {
- fetch: app.fetch,
- port: 1337,
- },
- () => {
- console.log(
- `⚡ API is running at ${process.env.KANEO_API_URL || "http://localhost:1337"}`,
- );
- },
- );
+
+ serve(
+ {
+ fetch: app.fetch,
+ port,
+ },
+ () => {
+ console.log(
+ `⚡ API is running at ${process.env.KANEO_API_URL || "http://localhost:1337"}`,
+ );
+ },
+ );
+ }
+
+ const createdApp = createApp();
+ const {
+ app,
+ activityApi,
+ columnApi,
+ commentApi,
+ configApi,
+ discordIntegrationApi,
+ externalLinkApi,
+ genericWebhookIntegrationApi,
+ githubIntegrationApi,
+ giteaIntegrationApi,
+ invitationApi,
+ invitationPublicApi,
+ labelApi,
+ notificationApi,
++ notificationPreferencesApi,
+ projectApi,
+ publicProjectApi,
+ searchApi,
+ slackIntegrationApi,
+ taskApi,
+ taskRelationApi,
+ telegramIntegrationApi,
+ timeEntryApi,
+ workflowRuleApi,
+ workspaceApi,
+ } = createdApp;
+
+ const isMainModule =
+ Boolean(process.argv[1]) &&
+ import.meta.url === pathToFileURL(process.argv[1]).href;
+
+ if (isMainModule) {
+ void startServer();
+ }
export type AppType =
| typeof configApi
diff --cc apps/api/src/schemas.ts
index 52b6362c1,a906ca6d0..c7bd8b890
--- a/apps/api/src/schemas.ts
+++ b/apps/api/src/schemas.ts
@@@ -98,50 -98,6 +98,45 @@@ export const notificationSchema = v.obj
createdAt: v.date(),
});
+export const notificationPreferenceWorkspaceRuleSchema = v.object({
+ id: v.string(),
+ workspaceId: v.string(),
+ workspaceName: v.string(),
+ isActive: v.boolean(),
+ emailEnabled: v.boolean(),
+ ntfyEnabled: v.boolean(),
+ gotifyEnabled: v.boolean(),
+ webhookEnabled: v.boolean(),
+ projectMode: v.picklist(["all", "selected"] as const),
+ selectedProjectIds: v.array(v.string()),
- projectMode: v.picklist(["all", "selected"] as const),
- selectedProjectIds: v.array(v.string()),
- createdAt: v.date(),
- updatedAt: v.date(),
- });
++ createdAt: v.date(),
++ updatedAt: v.date(),
+});
+
+export const notificationPreferenceSchema = v.object({
+ emailAddress: v.nullable(v.string()),
+ emailEnabled: v.boolean(),
+ ntfyEnabled: v.boolean(),
+ ntfyConfigured: v.boolean(),
+ ntfyServerUrl: v.nullable(v.string()),
+ ntfyTopic: v.nullable(v.string()),
+ ntfyTokenConfigured: v.boolean(),
+ maskedNtfyToken: v.nullable(v.string()),
+ gotifyEnabled: v.boolean(),
+ gotifyConfigured: v.boolean(),
+ gotifyServerUrl: v.nullable(v.string()),
+ gotifyTokenConfigured: v.boolean(),
+ maskedGotifyToken: v.nullable(v.string()),
+ webhookEnabled: v.boolean(),
+ webhookConfigured: v.boolean(),
+ webhookUrl: v.nullable(v.string()),
+ webhookSecretConfigured: v.boolean(),
+ maskedWebhookSecret: v.nullable(v.string()),
+ workspaces: v.array(notificationPreferenceWorkspaceRuleSchema),
- workspaces: v.array(notificationPreferenceWorkspaceRuleSchema),
+ createdAt: v.nullable(v.date()),
+ updatedAt: v.nullable(v.date()),
+});
- });
+
export const githubIntegrationSchema = v.object({
id: v.string(),
projectId: v.string(),