mirror of
https://github.com/documenso/documenso.git
synced 2025-11-17 18:21:32 +10:00
fix: wip
This commit is contained in:
@ -1,10 +1,6 @@
|
||||
import { posthog } from 'posthog-js';
|
||||
|
||||
import { useFeatureFlags } from '@documenso/lib/client-only/providers/feature-flag';
|
||||
import {
|
||||
FEATURE_FLAG_GLOBAL_SESSION_RECORDING,
|
||||
extractPostHogConfig,
|
||||
} from '@documenso/lib/constants/feature-flags';
|
||||
import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags';
|
||||
|
||||
export function useAnalytics() {
|
||||
// const featureFlags = useFeatureFlags();
|
||||
|
||||
@ -5,8 +5,13 @@ export const APP_DOCUMENT_UPLOAD_SIZE_LIMIT =
|
||||
|
||||
export const NEXT_PUBLIC_WEBAPP_URL = () =>
|
||||
env('NEXT_PUBLIC_WEBAPP_URL') ?? 'http://localhost:3000';
|
||||
export const NEXT_PUBLIC_MARKETING_URL = () => env('NEXT_PUBLIC_MARKETING_URL');
|
||||
|
||||
export const NEXT_PUBLIC_MARKETING_URL = () =>
|
||||
env('NEXT_PUBLIC_MARKETING_URL') ?? 'http://localhost:3001';
|
||||
|
||||
export const NEXT_PRIVATE_INTERNAL_WEBAPP_URL =
|
||||
env('NEXT_PRIVATE_INTERNAL_WEBAPP_URL') ?? NEXT_PUBLIC_WEBAPP_URL();
|
||||
|
||||
export const IS_BILLING_ENABLED = () => env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED') === 'true';
|
||||
|
||||
export const API_V2_BETA_URL = '/api/v2-beta';
|
||||
|
||||
@ -1,19 +1,24 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import { validateApiToken } from '@documenso/lib/server-only/webhooks/zapier/validateApiToken';
|
||||
|
||||
export const testCredentialsHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
export const testCredentialsHandler = async (req: Request) => {
|
||||
try {
|
||||
const { authorization } = req.headers;
|
||||
const authorization = req.headers.get('authorization');
|
||||
|
||||
if (!authorization) {
|
||||
throw new Error('Missing authorization header');
|
||||
}
|
||||
|
||||
const result = await validateApiToken({ authorization });
|
||||
|
||||
return res.status(200).json({
|
||||
return Response.json({
|
||||
name: result.team?.name ?? result.user.name,
|
||||
});
|
||||
} catch (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Internal Server Error',
|
||||
});
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Internal Server Error',
|
||||
},
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import { verify } from '../../crypto/verify';
|
||||
import { getAllWebhooksByEventTrigger } from '../get-all-webhooks-by-event-trigger';
|
||||
import { executeWebhook } from './execute-webhook';
|
||||
@ -15,29 +13,26 @@ export type HandlerTriggerWebhooksResponse =
|
||||
error: string;
|
||||
};
|
||||
|
||||
export const handlerTriggerWebhooks = async (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<HandlerTriggerWebhooksResponse>,
|
||||
) => {
|
||||
const signature = req.headers['x-webhook-signature'];
|
||||
export const handlerTriggerWebhooks = async (req: Request) => {
|
||||
const signature = req.headers.get('x-webhook-signature');
|
||||
|
||||
if (typeof signature !== 'string') {
|
||||
console.log('Missing signature');
|
||||
return res.status(400).json({ success: false, error: 'Missing signature' });
|
||||
return Response.json({ success: false, error: 'Missing signature' }, { status: 400 });
|
||||
}
|
||||
|
||||
const valid = verify(req.body, signature);
|
||||
|
||||
if (!valid) {
|
||||
console.log('Invalid signature');
|
||||
return res.status(400).json({ success: false, error: 'Invalid signature' });
|
||||
return Response.json({ success: false, error: 'Invalid signature' }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = ZTriggerWebhookBodySchema.safeParse(req.body);
|
||||
|
||||
if (!result.success) {
|
||||
console.log('Invalid request body');
|
||||
return res.status(400).json({ success: false, error: 'Invalid request body' });
|
||||
return Response.json({ success: false, error: 'Invalid request body' }, { status: 400 });
|
||||
}
|
||||
|
||||
const { event, data, userId, teamId } = result.data;
|
||||
@ -54,5 +49,8 @@ export const handlerTriggerWebhooks = async (
|
||||
),
|
||||
);
|
||||
|
||||
return res.status(200).json({ success: true, message: 'Webhooks executed successfully' });
|
||||
return Response.json(
|
||||
{ success: true, message: 'Webhooks executed successfully' },
|
||||
{ status: 200 },
|
||||
);
|
||||
};
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import type { Webhook } from '@prisma/client';
|
||||
|
||||
import { findDocuments } from '@documenso/lib/server-only/document/find-documents';
|
||||
@ -9,9 +7,14 @@ import { getWebhooksByTeamId } from '../get-webhooks-by-team-id';
|
||||
import { getWebhooksByUserId } from '../get-webhooks-by-user-id';
|
||||
import { validateApiToken } from './validateApiToken';
|
||||
|
||||
export const listDocumentsHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
export const listDocumentsHandler = async (req: Request) => {
|
||||
try {
|
||||
const { authorization } = req.headers;
|
||||
const authorization = req.headers.get('authorization');
|
||||
|
||||
if (!authorization) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const { user, userId, teamId } = await validateApiToken({ authorization });
|
||||
|
||||
let allWebhooks: Webhook[] = [];
|
||||
@ -56,13 +59,16 @@ export const listDocumentsHandler = async (req: NextApiRequest, res: NextApiResp
|
||||
},
|
||||
};
|
||||
|
||||
return res.status(200).json([testWebhook]);
|
||||
return Response.json([testWebhook]);
|
||||
}
|
||||
|
||||
return res.status(200).json([]);
|
||||
return Response.json([]);
|
||||
} catch (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Internal Server Error',
|
||||
});
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Internal Server Error',
|
||||
},
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { validateApiToken } from './validateApiToken';
|
||||
|
||||
export const subscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
export const subscribeHandler = async (req: Request) => {
|
||||
try {
|
||||
const { authorization } = req.headers;
|
||||
const authorization = req.headers.get('authorization');
|
||||
|
||||
const { webhookUrl, eventTrigger } = req.body;
|
||||
if (!authorization) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const { webhookUrl, eventTrigger } = await req.json();
|
||||
|
||||
const result = await validateApiToken({ authorization });
|
||||
|
||||
@ -23,10 +25,13 @@ export const subscribeHandler = async (req: NextApiRequest, res: NextApiResponse
|
||||
},
|
||||
});
|
||||
|
||||
return res.status(200).json(createdWebhook);
|
||||
return Response.json(createdWebhook);
|
||||
} catch (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Internal Server Error',
|
||||
});
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Internal Server Error',
|
||||
},
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { validateApiToken } from './validateApiToken';
|
||||
|
||||
export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
export const unsubscribeHandler = async (req: Request) => {
|
||||
try {
|
||||
const { authorization } = req.headers;
|
||||
const authorization = req.headers.get('authorization');
|
||||
|
||||
const { webhookId } = req.body;
|
||||
if (!authorization) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const { webhookId } = await req.json();
|
||||
|
||||
const result = await validateApiToken({ authorization });
|
||||
|
||||
@ -20,10 +22,13 @@ export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiRespon
|
||||
},
|
||||
});
|
||||
|
||||
return res.status(200).json(deletedWebhook);
|
||||
return Response.json(deletedWebhook);
|
||||
} catch (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Internal Server Error',
|
||||
});
|
||||
return Response.json(
|
||||
{
|
||||
message: 'Internal Server Error',
|
||||
},
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user