diff --git a/web/pages/api/v0/bet/cancel/[betId].ts b/web/pages/api/v0/bet/cancel/[betId].ts deleted file mode 100644 index 878b9349..00000000 --- a/web/pages/api/v0/bet/cancel/[betId].ts +++ /dev/null @@ -1,27 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { - CORS_ORIGIN_MANIFOLD, - CORS_ORIGIN_LOCALHOST, -} from 'common/envs/constants' -import { applyCorsHeaders } from 'web/lib/api/cors' -import { fetchBackend, forwardResponse } from 'web/lib/api/proxy' - -export const config = { api: { bodyParser: true } } - -export default async function route(req: NextApiRequest, res: NextApiResponse) { - await applyCorsHeaders(req, res, { - origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST], - methods: 'POST', - }) - - const { betId } = req.query as { betId: string } - - if (req.body) req.body.betId = betId - try { - const backendRes = await fetchBackend(req, 'cancelbet') - await forwardResponse(res, backendRes) - } catch (err) { - console.error('Error talking to cloud function: ', err) - res.status(500).json({ message: 'Error communicating with backend.' }) - } -} diff --git a/web/pages/api/v0/bet/index.ts b/web/pages/api/v0/bet/index.ts deleted file mode 100644 index ab7d78aa..00000000 --- a/web/pages/api/v0/bet/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { - CORS_ORIGIN_MANIFOLD, - CORS_ORIGIN_LOCALHOST, -} from 'common/envs/constants' -import { applyCorsHeaders } from 'web/lib/api/cors' -import { fetchBackend, forwardResponse } from 'web/lib/api/proxy' - -export const config = { api: { bodyParser: false } } - -export default async function route(req: NextApiRequest, res: NextApiResponse) { - await applyCorsHeaders(req, res, { - origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST], - methods: 'POST', - }) - try { - const backendRes = await fetchBackend(req, 'placebet') - await forwardResponse(res, backendRes) - } catch (err) { - console.error('Error talking to cloud function: ', err) - res.status(500).json({ message: 'Error communicating with backend.' }) - } -} diff --git a/web/pages/api/v0/bets.ts b/web/pages/api/v0/bets.ts deleted file mode 100644 index c3de3e97..00000000 --- a/web/pages/api/v0/bets.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' -import { Bet, getBets } from 'web/lib/firebase/bets' -import { getContractFromSlug } from 'web/lib/firebase/contracts' -import { getUserByUsername } from 'web/lib/firebase/users' -import { ApiError, ValidationError } from './_types' -import { z } from 'zod' -import { validate } from './_validate' - -const queryParams = z - .object({ - username: z.string().optional(), - market: z.string().optional(), - limit: z - .number() - .default(1000) - .or(z.string().regex(/\d+/).transform(Number)) - .refine((n) => n >= 0 && n <= 1000, 'Limit must be between 0 and 1000'), - before: z.string().optional(), - }) - .strict() - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - - let params: z.infer - try { - params = validate(queryParams, req.query) - } catch (e) { - if (e instanceof ValidationError) { - return res.status(400).json(e) - } - console.error(`Unknown error during validation: ${e}`) - return res.status(500).json({ error: 'Unknown error during validation' }) - } - - const { username, market, limit, before } = params - - let userId: string | undefined - if (username) { - const user = await getUserByUsername(username) - if (!user) { - res.status(404).json({ error: 'User not found' }) - return - } - userId = user.id - } - - let contractId: string | undefined - if (market) { - const contract = await getContractFromSlug(market) - if (!contract) { - res.status(404).json({ error: 'Contract not found' }) - return - } - contractId = contract.id - } - - const bets = await getBets({ userId, contractId, limit, before }) - - res.setHeader('Cache-Control', 'max-age=0') - return res.status(200).json(bets) -} diff --git a/web/pages/api/v0/group/[slug].ts b/web/pages/api/v0/group/[slug].ts deleted file mode 100644 index f9271591..00000000 --- a/web/pages/api/v0/group/[slug].ts +++ /dev/null @@ -1,18 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { getGroupBySlug } from 'web/lib/firebase/groups' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - const { slug } = req.query - const group = await getGroupBySlug(slug as string) - if (!group) { - res.status(404).json({ error: 'Group not found' }) - return - } - res.setHeader('Cache-Control', 'no-cache') - return res.status(200).json(group) -} diff --git a/web/pages/api/v0/group/by-id/[id].ts b/web/pages/api/v0/group/by-id/[id].ts deleted file mode 100644 index 3260302b..00000000 --- a/web/pages/api/v0/group/by-id/[id].ts +++ /dev/null @@ -1,18 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { getGroup } from 'web/lib/firebase/groups' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - const { id } = req.query - const group = await getGroup(id as string) - if (!group) { - res.status(404).json({ error: 'Group not found' }) - return - } - res.setHeader('Cache-Control', 'no-cache') - return res.status(200).json(group) -} diff --git a/web/pages/api/v0/groups.ts b/web/pages/api/v0/groups.ts deleted file mode 100644 index 84b773b3..00000000 --- a/web/pages/api/v0/groups.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import { listAllGroups } from 'web/lib/firebase/groups' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' - -type Data = any[] - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - const groups = await listAllGroups() - res.setHeader('Cache-Control', 'max-age=0') - res.status(200).json(groups) -} diff --git a/web/pages/api/v0/market/[id]/sell.ts b/web/pages/api/v0/market/[id]/sell.ts deleted file mode 100644 index 431121f2..00000000 --- a/web/pages/api/v0/market/[id]/sell.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { - CORS_ORIGIN_MANIFOLD, - CORS_ORIGIN_LOCALHOST, -} from 'common/envs/constants' -import { applyCorsHeaders } from 'web/lib/api/cors' -import { fetchBackend, forwardResponse } from 'web/lib/api/proxy' - -export const config = { api: { bodyParser: true } } - -export default async function route(req: NextApiRequest, res: NextApiResponse) { - await applyCorsHeaders(req, res, { - origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST], - methods: 'POST', - }) - - const { id } = req.query - const contractId = id as string - - if (req.body) req.body.contractId = contractId - try { - const backendRes = await fetchBackend(req, 'sellshares') - await forwardResponse(res, backendRes) - } catch (err) { - console.error('Error talking to cloud function: ', err) - res.status(500).json({ message: 'Error communicating with backend.' }) - } -} diff --git a/web/pages/api/v0/user/[username]/bets/index.ts b/web/pages/api/v0/user/[username]/bets/index.ts deleted file mode 100644 index 464af52c..00000000 --- a/web/pages/api/v0/user/[username]/bets/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' -import { Bet, getUserBets } from 'web/lib/firebase/bets' -import { getUserByUsername } from 'web/lib/firebase/users' -import { ApiError } from '../../../_types' - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - const { username } = req.query - - const user = await getUserByUsername(username as string) - - if (!user) { - res.status(404).json({ error: 'User not found' }) - return - } - - const bets = await getUserBets(user.id, { includeRedemptions: false }) - - res.setHeader('Cache-Control', 'max-age=0') - return res.status(200).json(bets) -} diff --git a/web/pages/api/v0/user/[username]/index.ts b/web/pages/api/v0/user/[username]/index.ts deleted file mode 100644 index 58daffcd..00000000 --- a/web/pages/api/v0/user/[username]/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { getUserByUsername } from 'web/lib/firebase/users' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' -import { LiteUser, ApiError, toLiteUser } from '../../_types' - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - const { username } = req.query - const user = await getUserByUsername(username as string) - if (!user) { - res.status(404).json({ error: 'User not found' }) - return - } - res.setHeader('Cache-Control', 'no-cache') - return res.status(200).json(toLiteUser(user)) -} diff --git a/web/pages/api/v0/user/by-id/[id].ts b/web/pages/api/v0/user/by-id/[id].ts deleted file mode 100644 index 6ed67d1c..00000000 --- a/web/pages/api/v0/user/by-id/[id].ts +++ /dev/null @@ -1,19 +0,0 @@ -import { NextApiRequest, NextApiResponse } from 'next' -import { getUser } from 'web/lib/firebase/users' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' -import { LiteUser, ApiError, toLiteUser } from '../../_types' - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - const { id } = req.query - const user = await getUser(id as string) - if (!user) { - res.status(404).json({ error: 'User not found' }) - return - } - res.setHeader('Cache-Control', 'no-cache') - return res.status(200).json(toLiteUser(user)) -} diff --git a/web/pages/api/v0/users.ts b/web/pages/api/v0/users.ts deleted file mode 100644 index 8c62b601..00000000 --- a/web/pages/api/v0/users.ts +++ /dev/null @@ -1,17 +0,0 @@ -// Next.js API route support: https://vercel.com/docs/concepts/functions/serverless-functions -import type { NextApiRequest, NextApiResponse } from 'next' -import { listAllUsers } from 'web/lib/firebase/users' -import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' -import { toLiteUser } from './_types' - -type Data = any[] - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - await applyCorsHeaders(req, res, CORS_UNRESTRICTED) - const users = await listAllUsers() - res.setHeader('Cache-Control', 'max-age=0') - res.status(200).json(users.map(toLiteUser)) -}