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.

fix(integrations): address review findings

Tin4189ece3a4d3
diff --git a/apps/api/src/discord-integration/index.ts b/apps/api/src/discord-integration/index.ts
index e9e05357e..6ff85d493 100644
--- a/apps/api/src/discord-integration/index.ts
+++ b/apps/api/src/discord-integration/index.ts
@@ -57,7 +57,9 @@ function toResponse(integration: {
channelName: config.channelName ?? null,
webhookConfigured: Boolean(config.webhookUrl),
webhookUrl: config.webhookUrl ?? "",
- maskedWebhookUrl: maskWebhookUrl(config.webhookUrl),
+ maskedWebhookUrl: config.webhookUrl
+ ? maskWebhookUrl(config.webhookUrl)
+ : "",
events: {
...defaultDiscordEvents,
...(config.events ?? {}),
@@ -158,30 +160,32 @@ discordIntegration
});
}
- const existing = await db.query.integrationTable.findFirst({
- where: and(
- eq(integrationTable.projectId, projectId),
- eq(integrationTable.type, "discord"),
- ),
- });
+ await db.transaction(async (tx) => {
+ const existing = await tx.query.integrationTable.findFirst({
+ where: and(
+ eq(integrationTable.projectId, projectId),
+ eq(integrationTable.type, "discord"),
+ ),
+ });
- if (existing) {
- await db
- .update(integrationTable)
- .set({
+ if (existing) {
+ await tx
+ .update(integrationTable)
+ .set({
+ config: JSON.stringify(config),
+ isActive: true,
+ updatedAt: new Date(),
+ })
+ .where(eq(integrationTable.id, existing.id));
+ } else {
+ await tx.insert(integrationTable).values({
+ projectId,
+ type: "discord",
config: JSON.stringify(config),
isActive: true,
- updatedAt: new Date(),
- })
- .where(eq(integrationTable.id, existing.id));
- } else {
- await db.insert(integrationTable).values({
- projectId,
- type: "discord",
- config: JSON.stringify(config),
- isActive: true,
- });
- }
+ });
+ }
+ });
const integration = await getDiscordIntegration(projectId);
return c.json(integration);
diff --git a/apps/api/src/plugins/discord/client.ts b/apps/api/src/plugins/discord/client.ts
index bbb293ed1..dbb926826 100644
--- a/apps/api/src/plugins/discord/client.ts
+++ b/apps/api/src/plugins/discord/client.ts
@@ -20,22 +20,40 @@ type DiscordMessage = {
embeds?: DiscordEmbed[];
};
+const DISCORD_TIMEOUT_MS = 10_000;
+
export async function postToDiscord(
webhookUrl: string,
message: DiscordMessage,
): Promise<void> {
- const response = await fetch(webhookUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(message),
- });
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), DISCORD_TIMEOUT_MS);
+
+ try {
+ const response = await fetch(webhookUrl, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(message),
+ signal: controller.signal,
+ });
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(
+ `Discord webhook request failed (${response.status}): ${errorText}`,
+ );
+ }
+ } catch (error) {
+ if (error instanceof Error && error.name === "AbortError") {
+ throw new Error(
+ `Discord webhook request timed out after ${DISCORD_TIMEOUT_MS}ms`,
+ );
+ }
- if (!response.ok) {
- const errorText = await response.text();
- throw new Error(
- `Discord webhook request failed (${response.status}): ${errorText}`,
- );
+ throw error;
+ } finally {
+ clearTimeout(timeoutId);
}
}
diff --git a/apps/api/src/plugins/discord/events.ts b/apps/api/src/plugins/discord/events.ts
index cdbd40df8..64939ebaf 100644
--- a/apps/api/src/plugins/discord/events.ts
+++ b/apps/api/src/plugins/discord/events.ts
@@ -30,8 +30,7 @@ type DiscordEventData = {
};
function isEnabled(config: DiscordConfig, key: DiscordEventKey): boolean {
- const normalized = normalizeDiscordConfig(config);
- return normalized.events?.[key] ?? false;
+ return config.events?.[key] ?? false;
}
function toSentenceCase(value: string | null): string {
@@ -106,44 +105,54 @@ async function sendDiscordMessage(
data.taskNumber !== null ? `#${data.taskNumber}` : "Task update";
const taskLabel = `${issueKey} ${data.taskTitle}`;
- await postToDiscord(config.webhookUrl, {
- content: `${title}: ${data.taskTitle}`,
- embeds: [
- {
- title,
- description: body,
- url: data.taskUrl ?? undefined,
- color: 0x5865f2,
- fields: [
- {
- name: "Task",
- value: data.taskUrl ? `[${taskLabel}](${data.taskUrl})` : taskLabel,
- inline: true,
+ try {
+ await postToDiscord(config.webhookUrl, {
+ content: `${title}: ${data.taskTitle}`,
+ embeds: [
+ {
+ title,
+ description: body,
+ url: data.taskUrl ?? undefined,
+ color: 0x5865f2,
+ fields: [
+ {
+ name: "Task",
+ value: data.taskUrl
+ ? `[${taskLabel}](${data.taskUrl})`
+ : taskLabel,
+ inline: true,
+ },
+ {
+ name: "Project",
+ value: data.projectName,
+ inline: true,
+ },
+ {
+ name: "Status",
+ value: toSentenceCase(data.status),
+ inline: true,
+ },
+ {
+ name: "Priority",
+ value: toSentenceCase(data.priority),
+ inline: true,
+ },
+ ],
+ footer: {
+ text: data.actorName
+ ? `Triggered by ${data.actorName}`
+ : "Triggered by Kaneo",
},
- {
- name: "Project",
- value: data.projectName,
- inline: true,
- },
- {
- name: "Status",
- value: toSentenceCase(data.status),
- inline: true,
- },
- {
- name: "Priority",
- value: toSentenceCase(data.priority),
- inline: true,
- },
- ],
- footer: {
- text: data.actorName
- ? `Triggered by ${data.actorName}`
- : "Triggered by Kaneo",
},
- },
- ],
- });
+ ],
+ });
+ } catch (error) {
+ console.error("sendDiscordMessage postToDiscord failed", {
+ error,
+ webhookUrl: config.webhookUrl,
+ taskUrl: data.taskUrl,
+ });
+ }
}
export async function handleTaskCreated(
diff --git a/apps/api/src/plugins/generic-webhook/client.ts b/apps/api/src/plugins/generic-webhook/client.ts
index 1e1415c6a..c1e6f21cc 100644
--- a/apps/api/src/plugins/generic-webhook/client.ts
+++ b/apps/api/src/plugins/generic-webhook/client.ts
@@ -1,12 +1,95 @@
import { createHmac } from "node:crypto";
+import { lookup } from "node:dns/promises";
+import net from "node:net";
type GenericWebhookPayload = Record<string, unknown>;
+const GENERIC_WEBHOOK_TIMEOUT_MS = 10_000;
+
+function isDisallowedIpv4(ip: string): boolean {
+ const parts = ip.split(".").map((part) => Number.parseInt(part, 10));
+ if (parts.length !== 4 || parts.some(Number.isNaN)) {
+ return true;
+ }
+
+ const [a, b] = parts;
+
+ return (
+ a === 0 ||
+ a === 10 ||
+ a === 127 ||
+ (a === 169 && b === 254) ||
+ (a === 172 && b >= 16 && b <= 31) ||
+ (a === 192 && b === 168)
+ );
+}
+
+function isDisallowedIpv6(ip: string): boolean {
+ const normalized = ip.toLowerCase();
+
+ return (
+ normalized === "::" ||
+ normalized === "::1" ||
+ normalized.startsWith("fe8") ||
+ normalized.startsWith("fe9") ||
+ normalized.startsWith("fea") ||
+ normalized.startsWith("feb") ||
+ normalized.startsWith("fc") ||
+ normalized.startsWith("fd")
+ );
+}
+
+function isDisallowedAddress(address: string): boolean {
+ if (address === "localhost") {
+ return true;
+ }
+
+ const version = net.isIP(address);
+ if (version === 4) {
+ return isDisallowedIpv4(address);
+ }
+
+ if (version === 6) {
+ return isDisallowedIpv6(address);
+ }
+
+ return false;
+}
+
+async function assertPublicWebhookDestination(
+ webhookUrl: string,
+): Promise<void> {
+ const url = new URL(webhookUrl);
+
+ if (!["http:", "https:"].includes(url.protocol)) {
+ throw new Error("Generic webhook URL must use http or https");
+ }
+
+ if (isDisallowedAddress(url.hostname)) {
+ throw new Error(
+ "Generic webhook destination resolves to a non-routable address",
+ );
+ }
+
+ const addresses = await lookup(url.hostname, { all: true, verbatim: true });
+ if (addresses.length === 0) {
+ throw new Error("Generic webhook destination could not be resolved");
+ }
+
+ if (addresses.some((entry) => isDisallowedAddress(entry.address))) {
+ throw new Error(
+ "Generic webhook destination resolves to a non-routable address",
+ );
+ }
+}
+
export async function postToGenericWebhook(
webhookUrl: string,
payload: GenericWebhookPayload,
secret?: string,
): Promise<void> {
+ await assertPublicWebhookDestination(webhookUrl);
+
const body = JSON.stringify(payload);
const headers: Record<string, string> = {
"Content-Type": "application/json",
@@ -18,16 +101,35 @@ export async function postToGenericWebhook(
.digest("hex");
}
- const response = await fetch(webhookUrl, {
- method: "POST",
- headers,
- body,
- });
+ const controller = new AbortController();
+ const timeoutId = setTimeout(
+ () => controller.abort(),
+ GENERIC_WEBHOOK_TIMEOUT_MS,
+ );
- if (!response.ok) {
- const errorText = await response.text();
- throw new Error(
- `Generic webhook request failed (${response.status}): ${errorText}`,
- );
+ try {
+ const response = await fetch(webhookUrl, {
+ method: "POST",
+ headers,
+ body,
+ signal: controller.signal,
+ });
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(
+ `Generic webhook request failed (${response.status}): ${errorText}`,
+ );
+ }
+ } catch (error) {
+ if (error instanceof Error && error.name === "AbortError") {
+ throw new Error(
+ `Generic webhook request timed out after ${GENERIC_WEBHOOK_TIMEOUT_MS}ms`,
+ );
+ }
+
+ throw error;
+ } finally {
+ clearTimeout(timeoutId);
}
}
diff --git a/apps/api/src/plugins/generic-webhook/config.ts b/apps/api/src/plugins/generic-webhook/config.ts
index 4b9b8106f..7284cee6f 100644
--- a/apps/api/src/plugins/generic-webhook/config.ts
+++ b/apps/api/src/plugins/generic-webhook/config.ts
@@ -60,7 +60,8 @@ export async function validateGenericWebhookConfig(
): Promise<{ valid: boolean; errors?: string[] }> {
try {
const parsed = v.parse(genericWebhookConfigSchema, config);
- normalizeGenericWebhookConfig(parsed);
+ const normalized = normalizeGenericWebhookConfig(parsed);
+ void normalized;
return { valid: true };
} catch (error) {
if (error instanceof v.ValiError) {
diff --git a/apps/api/src/plugins/generic-webhook/events.ts b/apps/api/src/plugins/generic-webhook/events.ts
index e6015c0e3..1414262ed 100644
--- a/apps/api/src/plugins/generic-webhook/events.ts
+++ b/apps/api/src/plugins/generic-webhook/events.ts
@@ -35,8 +35,7 @@ function isEnabled(
config: GenericWebhookConfig,
key: GenericWebhookEventKey,
): boolean {
- const normalized = normalizeGenericWebhookConfig(config);
- return normalized.events?.[key] ?? false;
+ return config.events?.[key] ?? false;
}
async function getTaskData(
@@ -108,32 +107,42 @@ async function sendEvent(
const actor = await getActor(userId);
- await postToGenericWebhook(
- config.webhookUrl,
- {
- event: eventName,
- timestamp: new Date().toISOString(),
- integration: {
- type: "generic-webhook",
- },
- project: {
- id: task.projectId,
- name: task.projectName,
- workspaceId: task.workspaceId,
- },
- task: {
- id: task.id,
- number: task.number,
- title: task.title,
- status: task.status,
- priority: task.priority,
- url: task.taskUrl,
+ try {
+ await postToGenericWebhook(
+ config.webhookUrl,
+ {
+ event: eventName,
+ timestamp: new Date().toISOString(),
+ integration: {
+ type: "generic-webhook",
+ },
+ project: {
+ id: task.projectId,
+ name: task.projectName,
+ workspaceId: task.workspaceId,
+ },
+ task: {
+ id: task.id,
+ number: task.number,
+ title: task.title,
+ status: task.status,
+ priority: task.priority,
+ url: task.taskUrl,
+ },
+ actor,
+ data,
},
- actor,
- data,
- },
- config.secret,
- );
+ config.secret,
+ );
+ } catch (error) {
+ console.error("sendEvent postToGenericWebhook failed", {
+ error,
+ eventName,
+ taskId,
+ projectId,
+ webhookUrl: config.webhookUrl,
+ });
+ }
}
export async function handleTaskCreated(
diff --git a/apps/api/src/plugins/slack/client.ts b/apps/api/src/plugins/slack/client.ts
index 1c7b3961f..5d6269d7e 100644
--- a/apps/api/src/plugins/slack/client.ts
+++ b/apps/api/src/plugins/slack/client.ts
@@ -1,9 +1,9 @@
-type SlackTextObject = {
+export type SlackTextObject = {
type: "mrkdwn" | "plain_text";
text: string;
};
-type SlackBlock =
+export type SlackBlock =
| {
type: "section";
text: SlackTextObject;
@@ -14,27 +14,45 @@ type SlackBlock =
elements: SlackTextObject[];
};
-type SlackMessage = {
+export type SlackMessage = {
text: string;
blocks?: SlackBlock[];
};
+const SLACK_TIMEOUT_MS = 10_000;
+
export async function postToSlack(
webhookUrl: string,
message: SlackMessage,
): Promise<void> {
- const response = await fetch(webhookUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(message),
- });
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), SLACK_TIMEOUT_MS);
+
+ try {
+ const response = await fetch(webhookUrl, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(message),
+ signal: controller.signal,
+ });
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(
+ `Slack webhook request failed (${response.status}): ${errorText}`,
+ );
+ }
+ } catch (error) {
+ if (error instanceof Error && error.name === "AbortError") {
+ throw new Error(
+ `Slack webhook request timed out after ${SLACK_TIMEOUT_MS}ms`,
+ );
+ }
- if (!response.ok) {
- const errorText = await response.text();
- throw new Error(
- `Slack webhook request failed (${response.status}): ${errorText}`,
- );
+ throw error;
+ } finally {
+ clearTimeout(timeoutId);
}
}
diff --git a/apps/api/src/plugins/slack/config.ts b/apps/api/src/plugins/slack/config.ts
index be8d6e034..c96ba31e6 100644
--- a/apps/api/src/plugins/slack/config.ts
+++ b/apps/api/src/plugins/slack/config.ts
@@ -1,5 +1,8 @@
import * as v from "valibot";
+const slackWebhookUrlPattern =
+ /^https:\/\/hooks\.slack\.com\/services\/[A-Za-z0-9]+\/[A-Za-z0-9]+\/[A-Za-z0-9]+$/;
+
export const slackEventKeys = [
"taskCreated",
"taskStatusChanged",
@@ -12,7 +15,10 @@ export const slackEventKeys = [
export type SlackEventKey = (typeof slackEventKeys)[number];
export const slackConfigSchema = v.object({
- webhookUrl: v.pipe(v.string(), v.url()),
+ webhookUrl: v.pipe(
+ v.string(),
+ v.regex(slackWebhookUrlPattern, "Invalid Slack webhook URL"),
+ ),
channelName: v.optional(v.string()),
events: v.optional(
v.object({
diff --git a/apps/api/src/plugins/slack/events.ts b/apps/api/src/plugins/slack/events.ts
index 3f55a7ce0..9a782d669 100644
--- a/apps/api/src/plugins/slack/events.ts
+++ b/apps/api/src/plugins/slack/events.ts
@@ -30,8 +30,14 @@ type SlackEventData = {
};
function isEnabled(config: SlackConfig, key: SlackEventKey): boolean {
- const normalized = normalizeSlackConfig(config);
- return normalized.events?.[key] ?? false;
+ return config.events?.[key] ?? false;
+}
+
+function escapeSlack(text: string): string {
+ return text
+ .replaceAll("&", "&amp;")
+ .replaceAll("<", "&lt;")
+ .replaceAll(">", "&gt;");
}
function toSentenceCase(value: string | null): string {
@@ -104,9 +110,13 @@ async function sendSlackMessage(
): Promise<void> {
const issueKey =
data.taskNumber !== null ? `#${data.taskNumber}` : "Task update";
+ const escapedIssueKey = escapeSlack(issueKey);
+ const escapedTaskTitle = escapeSlack(data.taskTitle);
const taskLabel = data.taskUrl
- ? `<${data.taskUrl}|${issueKey} ${data.taskTitle}>`
- : `${issueKey} ${data.taskTitle}`;
+ ? `<${data.taskUrl}|${escapedIssueKey} ${escapedTaskTitle}>`
+ : `${escapedIssueKey} ${escapedTaskTitle}`;
+ const escapedTitle = escapeSlack(title);
+ const escapedBody = escapeSlack(body);
await postToSlack(config.webhookUrl, {
text: `${title}: ${data.taskTitle}`,
@@ -115,7 +125,7 @@ async function sendSlackMessage(
type: "section",
text: {
type: "mrkdwn",
- text: `*${title}*\n${body}`,
+ text: `*${escapedTitle}*\n${escapedBody}`,
},
fields: [
{
@@ -124,15 +134,15 @@ async function sendSlackMessage(
},
{
type: "mrkdwn",
- text: `*Project*\n${data.projectName}`,
+ text: `*Project*\n${escapeSlack(data.projectName)}`,
},
{
type: "mrkdwn",
- text: `*Status*\n${toSentenceCase(data.status)}`,
+ text: `*Status*\n${escapeSlack(toSentenceCase(data.status))}`,
},
{
type: "mrkdwn",
- text: `*Priority*\n${toSentenceCase(data.priority)}`,
+ text: `*Priority*\n${escapeSlack(toSentenceCase(data.priority))}`,
},
],
},
@@ -142,7 +152,7 @@ async function sendSlackMessage(
{
type: "mrkdwn",
text: data.actorName
- ? `Triggered by ${data.actorName}`
+ ? `Triggered by ${escapeSlack(data.actorName)}`
: "Triggered by Kaneo",
},
],
diff --git a/apps/api/src/schemas.ts b/apps/api/src/schemas.ts
index 6baeeb442..c4dfaffbf 100644
--- a/apps/api/src/schemas.ts
+++ b/apps/api/src/schemas.ts
@@ -111,6 +111,15 @@ export const githubIntegrationSchema = v.object({
updatedAt: v.date(),
});
+export const integrationEventsSchema = v.object({
+ taskCreated: v.boolean(),
+ taskStatusChanged: v.boolean(),
+ taskPriorityChanged: v.boolean(),
+ taskTitleChanged: v.boolean(),
+ taskDescriptionChanged: v.boolean(),
+ taskCommentCreated: v.boolean(),
+});
+
export const slackIntegrationSchema = v.object({
id: v.string(),
projectId: v.string(),
@@ -118,14 +127,7 @@ export const slackIntegrationSchema = v.object({
webhookConfigured: v.boolean(),
webhookUrl: v.string(),
maskedWebhookUrl: v.string(),
- events: v.object({
- taskCreated: v.boolean(),
- taskStatusChanged: v.boolean(),
- taskPriorityChanged: v.boolean(),
- taskTitleChanged: v.boolean(),
- taskDescriptionChanged: v.boolean(),
- taskCommentCreated: v.boolean(),
- }),
+ events: integrationEventsSchema,
isActive: v.nullable(v.boolean()),
createdAt: v.date(),
updatedAt: v.date(),
@@ -138,14 +140,7 @@ export const discordIntegrationSchema = v.object({
webhookConfigured: v.boolean(),
webhookUrl: v.string(),
maskedWebhookUrl: v.string(),
- events: v.object({
- taskCreated: v.boolean(),
- taskStatusChanged: v.boolean(),
- taskPriorityChanged: v.boolean(),
- taskTitleChanged: v.boolean(),
- taskDescriptionChanged: v.boolean(),
- taskCommentCreated: v.boolean(),
- }),
+ events: integrationEventsSchema,
isActive: v.nullable(v.boolean()),
createdAt: v.date(),
updatedAt: v.date(),
@@ -158,14 +153,7 @@ export const genericWebhookIntegrationSchema = v.object({
webhookUrl: v.string(),
secretConfigured: v.boolean(),
maskedSecret: v.nullable(v.string()),
- events: v.object({
- taskCreated: v.boolean(),
- taskStatusChanged: v.boolean(),
- taskPriorityChanged: v.boolean(),
- taskTitleChanged: v.boolean(),
- taskDescriptionChanged: v.boolean(),
- taskCommentCreated: v.boolean(),
- }),
+ events: integrationEventsSchema,
isActive: v.nullable(v.boolean()),
createdAt: v.date(),
updatedAt: v.date(),
diff --git a/apps/web/src/components/project/discord-integration-settings.tsx b/apps/web/src/components/project/discord-integration-settings.tsx
index 76a806c8a..7c269f23a 100644
--- a/apps/web/src/components/project/discord-integration-settings.tsx
+++ b/apps/web/src/components/project/discord-integration-settings.tsx
@@ -135,10 +135,11 @@ export function DiscordIntegrationSettings({
taskCommentCreated: true,
},
});
+ const { reset } = form;
React.useEffect(() => {
- form.reset(normalizedValues);
- }, [form, normalizedValues]);
+ reset(normalizedValues);
+ }, [normalizedValues, reset]);
const isConnected = Boolean(integration?.webhookConfigured);
const isBusy = isCreating || isUpdating || isDeleting;
diff --git a/apps/web/src/components/project/generic-webhook-integration-settings.tsx b/apps/web/src/components/project/generic-webhook-integration-settings.tsx
index f3e96c947..7e07ae335 100644
--- a/apps/web/src/components/project/generic-webhook-integration-settings.tsx
+++ b/apps/web/src/components/project/generic-webhook-integration-settings.tsx
@@ -121,10 +121,11 @@ export function GenericWebhookIntegrationSettings({
resolver: standardSchemaResolver(schema),
defaultValues: normalizedValues,
});
+ const { reset } = form;
React.useEffect(() => {
- form.reset(normalizedValues);
- }, [form, normalizedValues]);
+ reset(normalizedValues);
+ }, [normalizedValues, reset]);
const isConnected = Boolean(integration?.webhookConfigured);
const isBusy = isCreating || isUpdating || isDeleting;
diff --git a/apps/web/src/fetchers/discord-integration/create-discord-integration.ts b/apps/web/src/fetchers/discord-integration/create-discord-integration.ts
index a7f4271fc..e9cda79fc 100644
--- a/apps/web/src/fetchers/discord-integration/create-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/create-discord-integration.ts
@@ -1,11 +1,6 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
import type { DiscordIntegration } from "./get-discord-integration";
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
export type CreateDiscordIntegrationRequest = {
webhookUrl: string;
channelName?: string;
diff --git a/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts b/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts
index 12951392c..256273e06 100644
--- a/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts
@@ -1,8 +1,4 @@
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
+import { getApiUrl } from "@/fetchers/get-api-url";
async function deleteDiscordIntegration(projectId: string) {
const response = await fetch(
diff --git a/apps/web/src/fetchers/discord-integration/get-discord-integration.ts b/apps/web/src/fetchers/discord-integration/get-discord-integration.ts
index e7729aa85..b9617e4ee 100644
--- a/apps/web/src/fetchers/discord-integration/get-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/get-discord-integration.ts
@@ -1,9 +1,12 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
+
export type DiscordIntegration = {
id: string;
projectId: string;
channelName: string | null;
webhookConfigured: boolean;
webhookUrl: string;
+ maskedWebhookUrl: string;
events: {
taskCreated: boolean;
taskStatusChanged: boolean;
@@ -17,20 +20,11 @@ export type DiscordIntegration = {
updatedAt: string;
} | null;
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
async function getDiscordIntegration(projectId: string) {
const response = await fetch(
getApiUrl(`/discord-integration/project/${projectId}`),
{
credentials: "include",
- headers: {
- "Content-Type": "application/json",
- },
},
);
diff --git a/apps/web/src/fetchers/discord-integration/update-discord-integration.ts b/apps/web/src/fetchers/discord-integration/update-discord-integration.ts
index 68fcb9444..f92b1d2c8 100644
--- a/apps/web/src/fetchers/discord-integration/update-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/update-discord-integration.ts
@@ -1,11 +1,6 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
import type { DiscordIntegration } from "./get-discord-integration";
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
export type UpdateDiscordIntegrationRequest = {
webhookUrl?: string;
channelName?: string | null;
diff --git a/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts
index 2af414be7..c0cc2869b 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts
@@ -1,11 +1,6 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
import type { GenericWebhookIntegration } from "./get-generic-webhook-integration";
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
export type CreateGenericWebhookIntegrationRequest = {
webhookUrl: string;
secret?: string;
diff --git a/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts
index 53f48cc44..2d284b11a 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts
@@ -1,8 +1,4 @@
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
+import { getApiUrl } from "@/fetchers/get-api-url";
async function deleteGenericWebhookIntegration(projectId: string) {
const response = await fetch(
diff --git a/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
index c50b5f2d3..0c81bb0ef 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
@@ -1,3 +1,5 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
+
export type GenericWebhookIntegration = {
id: string;
projectId: string;
@@ -16,22 +18,15 @@ export type GenericWebhookIntegration = {
isActive: boolean | null;
createdAt: string;
updatedAt: string;
-} | null;
-
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
+};
-async function getGenericWebhookIntegration(projectId: string) {
+async function getGenericWebhookIntegration(
+ projectId: string,
+): Promise<GenericWebhookIntegration | null> {
const response = await fetch(
getApiUrl(`/generic-webhook-integration/project/${projectId}`),
{
credentials: "include",
- headers: {
- "Content-Type": "application/json",
- },
},
);
@@ -40,7 +35,7 @@ async function getGenericWebhookIntegration(projectId: string) {
throw new Error(error);
}
- return (await response.json()) as GenericWebhookIntegration;
+ return (await response.json()) as GenericWebhookIntegration | null;
}
export default getGenericWebhookIntegration;
diff --git a/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts
index 370a4e02a..fce2f3b04 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts
@@ -1,11 +1,6 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
import type { GenericWebhookIntegration } from "./get-generic-webhook-integration";
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
export type UpdateGenericWebhookIntegrationRequest = {
webhookUrl?: string;
secret?: string | null;
diff --git a/apps/web/src/fetchers/get-api-url.ts b/apps/web/src/fetchers/get-api-url.ts
new file mode 100644
index 000000000..2794ef835
--- /dev/null
+++ b/apps/web/src/fetchers/get-api-url.ts
@@ -0,0 +1,6 @@
+export function getApiUrl(path: string) {
+ const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
+ const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
+
+ return `${apiUrl}${path}`;
+}
diff --git a/apps/web/src/fetchers/slack-integration/create-slack-integration.ts b/apps/web/src/fetchers/slack-integration/create-slack-integration.ts
index 6db006d25..be06daf8d 100644
--- a/apps/web/src/fetchers/slack-integration/create-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/create-slack-integration.ts
@@ -1,11 +1,6 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
import type { SlackIntegration } from "./get-slack-integration";
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
export type CreateSlackIntegrationRequest = {
webhookUrl: string;
channelName?: string;
diff --git a/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts b/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts
index 5b7186431..18f8c72e6 100644
--- a/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts
@@ -1,8 +1,4 @@
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
+import { getApiUrl } from "@/fetchers/get-api-url";
async function deleteSlackIntegration(projectId: string) {
const response = await fetch(
diff --git a/apps/web/src/fetchers/slack-integration/get-slack-integration.ts b/apps/web/src/fetchers/slack-integration/get-slack-integration.ts
index cdce95d14..72efba41d 100644
--- a/apps/web/src/fetchers/slack-integration/get-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/get-slack-integration.ts
@@ -1,9 +1,12 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
+
export type SlackIntegration = {
id: string;
projectId: string;
channelName: string | null;
webhookConfigured: boolean;
webhookUrl: string;
+ maskedWebhookUrl: string;
events: {
taskCreated: boolean;
taskStatusChanged: boolean;
@@ -17,20 +20,11 @@ export type SlackIntegration = {
updatedAt: string;
} | null;
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
async function getSlackIntegration(projectId: string) {
const response = await fetch(
getApiUrl(`/slack-integration/project/${projectId}`),
{
credentials: "include",
- headers: {
- "Content-Type": "application/json",
- },
},
);
diff --git a/apps/web/src/fetchers/slack-integration/update-slack-integration.ts b/apps/web/src/fetchers/slack-integration/update-slack-integration.ts
index 463b74ad0..c6c5e81b2 100644
--- a/apps/web/src/fetchers/slack-integration/update-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/update-slack-integration.ts
@@ -1,11 +1,6 @@
+import { getApiUrl } from "@/fetchers/get-api-url";
import type { SlackIntegration } from "./get-slack-integration";
-function getApiUrl(path: string) {
- const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:1337";
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
- return `${apiUrl}${path}`;
-}
-
export type UpdateSlackIntegrationRequest = {
webhookUrl?: string;
channelName?: string | null;
diff --git a/apps/web/src/hooks/queries/discord-integration/use-get-discord-integration.ts b/apps/web/src/hooks/queries/discord-integration/use-get-discord-integration.ts
index 36d7d0d01..bd064a6d8 100644
--- a/apps/web/src/hooks/queries/discord-integration/use-get-discord-integration.ts
+++ b/apps/web/src/hooks/queries/discord-integration/use-get-discord-integration.ts
@@ -5,6 +5,7 @@ function useGetDiscordIntegration(projectId: string) {
return useQuery({
queryKey: ["discord-integration", projectId],
queryFn: () => getDiscordIntegration(projectId),
+ enabled: Boolean(projectId),
});
}
diff --git a/apps/web/src/hooks/queries/generic-webhook-integration/use-get-generic-webhook-integration.ts b/apps/web/src/hooks/queries/generic-webhook-integration/use-get-generic-webhook-integration.ts
index c95764543..146c184da 100644
--- a/apps/web/src/hooks/queries/generic-webhook-integration/use-get-generic-webhook-integration.ts
+++ b/apps/web/src/hooks/queries/generic-webhook-integration/use-get-generic-webhook-integration.ts
@@ -5,6 +5,7 @@ function useGetGenericWebhookIntegration(projectId: string) {
return useQuery({
queryKey: ["generic-webhook-integration", projectId],
queryFn: () => getGenericWebhookIntegration(projectId),
+ enabled: Boolean(projectId),
});
}