mirror of https://github.com/buster-so/buster.git
fix: apply formatting fixes to Slack endpoint files
Co-Authored-By: Dallin Bentley <dallinbentley98@gmail.com>
This commit is contained in:
parent
eec4066e83
commit
6ef457d336
|
@ -1,5 +1,9 @@
|
|||
import { getUserOrganizationId } from '@buster/database';
|
||||
import { type GetChannelsResponse, SlackError } from '@buster/server-shared/slack';
|
||||
import {
|
||||
type GetChannelsResponse,
|
||||
GetChannelsResponseSchema,
|
||||
SlackError,
|
||||
} from '@buster/server-shared/slack';
|
||||
import { SlackChannelService } from '@buster/slack';
|
||||
import type { Context } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
|
@ -35,15 +39,19 @@ export async function getChannelsHandler(c: Context): Promise<Response> {
|
|||
const channelService = new SlackChannelService();
|
||||
const channels = await channelService.getAvailableChannels(accessToken);
|
||||
|
||||
return c.json<GetChannelsResponse>({
|
||||
const response: GetChannelsResponse = {
|
||||
channels: channels.map((channel) => ({
|
||||
id: channel.id,
|
||||
name: channel.name,
|
||||
is_private: channel.is_private,
|
||||
is_archived: channel.is_archived,
|
||||
is_member: channel.is_member,
|
||||
})),
|
||||
});
|
||||
};
|
||||
|
||||
const validatedResponse = GetChannelsResponseSchema.safeParse(response);
|
||||
if (!validatedResponse.success) {
|
||||
throw new HTTPException(500, { message: 'Invalid response format' });
|
||||
}
|
||||
|
||||
return c.json<GetChannelsResponse>(validatedResponse.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to get channels:', error);
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { getUserOrganizationId } from '@buster/database';
|
||||
import type { GetIntegrationResponse } from '@buster/server-shared/slack';
|
||||
import {
|
||||
type GetIntegrationResponse,
|
||||
GetIntegrationResponseSchema,
|
||||
} from '@buster/server-shared/slack';
|
||||
import type { Context } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
import { createSlackOAuthService } from './services/slack-oauth-service';
|
||||
|
@ -36,7 +39,13 @@ export async function getIntegrationHandler(c: Context): Promise<Response> {
|
|||
}),
|
||||
};
|
||||
|
||||
return c.json<GetIntegrationResponse>(response);
|
||||
const validatedResponse = GetIntegrationResponseSchema.safeParse(response);
|
||||
if (!validatedResponse.success) {
|
||||
console.error('Invalid response format:', validatedResponse.error);
|
||||
throw new HTTPException(500, { message: 'Invalid response format' });
|
||||
}
|
||||
|
||||
return c.json<GetIntegrationResponse>(validatedResponse.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to get integration status:', error);
|
||||
throw new HTTPException(500, { message: 'Failed to get integration status' });
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import { SlackError } from '@buster/server-shared/slack';
|
||||
import {
|
||||
InitiateOAuthSchema,
|
||||
SlackError,
|
||||
UpdateIntegrationSchema,
|
||||
} from '@buster/server-shared/slack';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
import { Hono } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
import { z } from 'zod';
|
||||
import { requireAuth } from '../../../middleware/auth';
|
||||
import { slackWebhookValidator } from '../../../middleware/slack-webhook-validator';
|
||||
import { handleSlackEventsEndpoint } from './events';
|
||||
|
@ -13,11 +19,16 @@ import { updateIntegrationHandler } from './update-integration';
|
|||
|
||||
const app = new Hono()
|
||||
// Public endpoints (no auth required for OAuth flow)
|
||||
.post('/auth/init', requireAuth, initiateOAuthHandler)
|
||||
.post('/auth/init', requireAuth, zValidator('json', InitiateOAuthSchema), initiateOAuthHandler)
|
||||
.get('/auth/callback', handleOAuthCallbackHandler)
|
||||
// Protected endpoints
|
||||
.get('/integration', requireAuth, getIntegrationHandler)
|
||||
.put('/integration', requireAuth, updateIntegrationHandler)
|
||||
.put(
|
||||
'/integration',
|
||||
requireAuth,
|
||||
zValidator('json', UpdateIntegrationSchema),
|
||||
updateIntegrationHandler
|
||||
)
|
||||
.get('/channels', requireAuth, getChannelsHandler)
|
||||
.delete('/integration', requireAuth, removeIntegrationHandler)
|
||||
// Events endpoint (no auth required for Slack webhooks)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { getUserOrganizationId } from '@buster/database';
|
||||
import {
|
||||
type InitiateOAuthRequest,
|
||||
type InitiateOAuthResponse,
|
||||
InitiateOAuthSchema,
|
||||
InitiateOAuthResponseSchema,
|
||||
SlackError,
|
||||
type SlackErrorResponse,
|
||||
} from '@buster/server-shared/slack';
|
||||
|
@ -45,10 +46,8 @@ export async function initiateOAuthHandler(c: Context): Promise<Response> {
|
|||
throw new HTTPException(400, { message: 'Organization not found' });
|
||||
}
|
||||
|
||||
const body: unknown = await c.req.json().catch(() => ({}));
|
||||
const parsed = InitiateOAuthSchema.safeParse(body);
|
||||
|
||||
const metadata = parsed.success ? parsed.data?.metadata : undefined;
|
||||
const request = c.req.valid('json');
|
||||
const metadata = request?.metadata;
|
||||
|
||||
const enrichedMetadata = {
|
||||
...metadata,
|
||||
|
@ -61,10 +60,17 @@ export async function initiateOAuthHandler(c: Context): Promise<Response> {
|
|||
metadata: enrichedMetadata,
|
||||
});
|
||||
|
||||
return c.json<InitiateOAuthResponse>({
|
||||
const response: InitiateOAuthResponse = {
|
||||
auth_url: result.authUrl,
|
||||
state: result.state,
|
||||
});
|
||||
};
|
||||
|
||||
const validatedResponse = InitiateOAuthResponseSchema.safeParse(response);
|
||||
if (!validatedResponse.success) {
|
||||
throw new SlackError('Invalid response format', 500, 'INVALID_RESPONSE');
|
||||
}
|
||||
|
||||
return c.json<InitiateOAuthResponse>(validatedResponse.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to initiate OAuth:', error);
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import { getUserOrganizationId } from '@buster/database';
|
||||
import { type RemoveIntegrationResponse, SlackError } from '@buster/server-shared/slack';
|
||||
import {
|
||||
type RemoveIntegrationResponse,
|
||||
RemoveIntegrationResponseSchema,
|
||||
SlackError,
|
||||
} from '@buster/server-shared/slack';
|
||||
import type { Context } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
import { createSlackOAuthService } from './services/slack-oauth-service';
|
||||
|
@ -32,9 +36,16 @@ export async function removeIntegrationHandler(c: Context): Promise<Response> {
|
|||
);
|
||||
}
|
||||
|
||||
return c.json<RemoveIntegrationResponse>({
|
||||
const response: RemoveIntegrationResponse = {
|
||||
message: 'Slack integration removed successfully',
|
||||
});
|
||||
};
|
||||
|
||||
const validatedResponse = RemoveIntegrationResponseSchema.safeParse(response);
|
||||
if (!validatedResponse.success) {
|
||||
throw new HTTPException(500, { message: 'Invalid response format' });
|
||||
}
|
||||
|
||||
return c.json<RemoveIntegrationResponse>(validatedResponse.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to remove integration:', error);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
SlackError,
|
||||
type UpdateIntegrationRequest,
|
||||
type UpdateIntegrationResponse,
|
||||
UpdateIntegrationSchema,
|
||||
UpdateIntegrationResponseSchema,
|
||||
} from '@buster/server-shared/slack';
|
||||
import type { Context } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
|
@ -23,23 +23,34 @@ export async function updateIntegrationHandler(c: Context): Promise<Response> {
|
|||
}
|
||||
|
||||
try {
|
||||
const body: unknown = await c.req.json();
|
||||
const parsed = UpdateIntegrationSchema.safeParse(body);
|
||||
const request = c.req.valid('json');
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new HTTPException(400, { message: 'Invalid request body' });
|
||||
const updateData: {
|
||||
defaultChannel?: { id: string; name: string };
|
||||
defaultSharingPermissions?: 'shareWithWorkspace' | 'shareWithChannel' | 'noSharing';
|
||||
} = {};
|
||||
|
||||
if (request.default_channel) {
|
||||
updateData.defaultChannel = request.default_channel;
|
||||
}
|
||||
if (request.default_sharing_permissions) {
|
||||
updateData.defaultSharingPermissions = request.default_sharing_permissions;
|
||||
}
|
||||
|
||||
const request: UpdateIntegrationRequest = parsed.data;
|
||||
await updateIntegrationSettings(organizationGrant.organizationId, updateData);
|
||||
|
||||
await updateIntegrationSettings(organizationGrant.organizationId, {
|
||||
defaultChannel: request.default_channel,
|
||||
defaultSharingPermissions: request.default_sharing_permissions,
|
||||
});
|
||||
|
||||
return c.json<UpdateIntegrationResponse>({
|
||||
const response: UpdateIntegrationResponse = {
|
||||
message: 'Integration settings updated successfully',
|
||||
});
|
||||
default_channel: request.default_channel,
|
||||
default_sharing_permissions: request.default_sharing_permissions,
|
||||
};
|
||||
|
||||
const validatedResponse = UpdateIntegrationResponseSchema.safeParse(response);
|
||||
if (!validatedResponse.success) {
|
||||
throw new HTTPException(500, { message: 'Invalid response format' });
|
||||
}
|
||||
|
||||
return c.json<UpdateIntegrationResponse>(validatedResponse.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to update integration:', error);
|
||||
|
||||
|
|
Loading…
Reference in New Issue