The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: combine bot subreport into API report
TzeYiingf041bb3644a9
diff --git a/studio/components/interfaces/Reports/Reports.constants.ts b/studio/components/interfaces/Reports/Reports.constants.tsindex e76f48949ac..456c6c95a8d 100644--- a/studio/components/interfaces/Reports/Reports.constants.ts+++ b/studio/components/interfaces/Reports/Reports.constants.ts@@ -34,8 +34,8 @@ export const DEFAULT_QUERY_PARAMS = {}export const PRESET_CONFIG: Record<Presets, PresetConfig> = {- [Presets.API_OVERVIEW]: {- title: '',+ [Presets.API]: {+ title: 'API',queries: {statusCodes: {queryType: 'logs',@@ -101,11 +101,6 @@ export const PRESET_CONFIG: Record<Presets, PresetConfig> = {LIMIT 50`,},- },- },- [Presets.API_BOTS]: {- title: 'API Bots',- queries: {userAgents: {queryType: 'logs',sql: `diff --git a/studio/components/interfaces/Reports/Reports.types.ts b/studio/components/interfaces/Reports/Reports.types.tsindex 419303e66af..b13d36dd3ba 100644--- a/studio/components/interfaces/Reports/Reports.types.ts+++ b/studio/components/interfaces/Reports/Reports.types.ts@@ -1,10 +1,8 @@import { ResponseError } from 'types'-import { LogsEndpointParams } from '../Settings/Logs'import { DEFAULT_QUERY_PARAMS } from './Reports.constants'export enum Presets {- API_OVERVIEW = 'overview',- API_BOTS = 'api_bots',+ API = 'api',AUTH = 'auth',}diff --git a/studio/components/interfaces/Reports/renderers/ApiBotsRenderers.tsx b/studio/components/interfaces/Reports/renderers/ApiBotsRenderers.tsxdeleted file mode 100644index 9c92a616dad..00000000000--- a/studio/components/interfaces/Reports/renderers/ApiBotsRenderers.tsx+++ /dev/null@@ -1,94 +0,0 @@-import Table from 'components/to-be-cleaned/Table'-import { ReportWidgetProps } from '../ReportWidget'--export const renderUserAgents = (- props: ReportWidgetProps<{- user_agent: string- request_source: string- count: number- }>-) => {- return (- <Table- containerClassName="max-h-72 w-full overflow-y-auto"- className="relative rounded border border-scale-600"- head={- <>- <Table.th className="sticky top-0 z-10">User Agents</Table.th>- <Table.th className="sticky top-0 z-10">Request Source</Table.th>- <Table.th className="sticky top-0 z-10">Count</Table.th>- </>- }- body={- <>- {props.data.map((row, index) => {- return (- <Table.tr key={index}>- <Table.td className="max-w-sm lg:max-w-lg" style={{ padding: '0.3rem' }}>- {row.user_agent ? (- row.user_agent- ) : (- <span className="text-scale-1000">No user agent</span>- )}- </Table.td>- <Table.td>{row.request_source}</Table.td>- <Table.td style={{ padding: '0.5rem' }} className="align-top text-xs">- {row.count}- </Table.td>- </Table.tr>- )- })}- </>- }- />- )-}--export const renderBotScores = (- props: ReportWidgetProps<{- ip: string- country: string- user_agent: string- path: string- bot_score: number- bot_verified: boolean- count: number- }>-) => {- return (- <Table- containerClassName="max-h-72 w-full overflow-y-auto"- className="relative rounded border border-scale-600"- head={- <>- <Table.th className="sticky top-0 z-10">IP (Country)</Table.th>- <Table.th className="sticky top-0 z-10">Request Path</Table.th>- <Table.th className="sticky top-0 z-10">User Agent</Table.th>- <Table.th className="sticky top-0 z-10">Bot Score</Table.th>- <Table.th className="sticky top-0 z-10">Is Verified Bot</Table.th>- <Table.th className="sticky top-0 z-10">Count</Table.th>- </>- }- body={- <>- {props.data.map((row, index) => {- return (- <Table.tr key={index}>- <Table.td className="max-w-sm lg:max-w-lg" style={{ padding: '0.3rem' }}>- {row.ip} ({row.country})- </Table.td>- <Table.td>{row.path}</Table.td>- <Table.td className="max-w-xs truncate">{row.user_agent}</Table.td>- <Table.td>{row.bot_score}</Table.td>- <Table.td>{row.bot_verified ? 'Yes' : 'No'}</Table.td>- <Table.td style={{ padding: '0.5rem' }} className="align-top text-xs">- {row.count}- </Table.td>- </Table.tr>- )- })}- </>- }- />- )-}diff --git a/studio/components/interfaces/Reports/renderers/OverviewRenderers.tsx b/studio/components/interfaces/Reports/renderers/ApiRenderers.tsxsimilarity index 70%rename from studio/components/interfaces/Reports/renderers/OverviewRenderers.tsxrename to studio/components/interfaces/Reports/renderers/ApiRenderers.tsxindex 2fc2c8eac4e..e6e8156d296 100644--- a/studio/components/interfaces/Reports/renderers/OverviewRenderers.tsx+++ b/studio/components/interfaces/Reports/renderers/ApiRenderers.tsx@@ -10,6 +10,98 @@ import { PathsDatum, StatusCodesDatum } from '../Reports.types'import { queryParamsToObject } from '../Reports.utils'import { ReportWidgetProps } from '../ReportWidget'+export const renderUserAgents = (+ props: ReportWidgetProps<{+ user_agent: string+ request_source: string+ count: number+ }>+) => {+ return (+ <Table+ containerClassName="max-h-72 w-full overflow-y-auto"+ className="relative rounded border border-scale-600"+ head={+ <>+ <Table.th className="sticky top-0 z-10">User Agents</Table.th>+ <Table.th className="sticky top-0 z-10">Request Source</Table.th>+ <Table.th className="sticky top-0 z-10">Count</Table.th>+ </>+ }+ body={+ <>+ {props.data.map((row, index) => {+ return (+ <Table.tr key={index}>+ <Table.td className="max-w-sm lg:max-w-lg" style={{ padding: '0.3rem' }}>+ {row.user_agent ? (+ row.user_agent+ ) : (+ <span className="text-scale-1000">No user agent</span>+ )}+ </Table.td>+ <Table.td>{row.request_source}</Table.td>+ <Table.td style={{ padding: '0.5rem' }} className="align-top text-xs">+ {row.count}+ </Table.td>+ </Table.tr>+ )+ })}+ </>+ }+ />+ )+}++export const renderBotScores = (+ props: ReportWidgetProps<{+ ip: string+ country: string+ user_agent: string+ path: string+ bot_score: number+ bot_verified: boolean+ count: number+ }>+) => {+ return (+ <Table+ containerClassName="max-h-72 w-full overflow-y-auto"+ className="relative rounded border border-scale-600"+ head={+ <>+ <Table.th className="sticky top-0 z-10">IP (Country)</Table.th>+ <Table.th className="sticky top-0 z-10">Request Path</Table.th>+ <Table.th className="sticky top-0 z-10">User Agent</Table.th>+ <Table.th className="sticky top-0 z-10">Bot Score</Table.th>+ <Table.th className="sticky top-0 z-10">Is Verified Bot</Table.th>+ <Table.th className="sticky top-0 z-10">Count</Table.th>+ </>+ }+ body={+ <>+ {props.data.map((row, index) => {+ return (+ <Table.tr key={index}>+ <Table.td className="max-w-sm lg:max-w-lg" style={{ padding: '0.3rem' }}>+ {row.ip} ({row.country})+ </Table.td>+ <Table.td>{row.path}</Table.td>+ <Table.td className="max-w-xs truncate">{row.user_agent}</Table.td>+ <Table.td>{row.bot_score}</Table.td>+ <Table.td>{row.bot_verified ? 'Yes' : 'No'}</Table.td>+ <Table.td style={{ padding: '0.5rem' }} className="align-top text-xs">+ {row.count}+ </Table.td>+ </Table.tr>+ )+ })}+ </>+ }+ />+ )+}+export const renderStatusCodesChart = (props: ReportWidgetProps<StatusCodesDatum>) => (<StackedAreaChartdateFormat={DATETIME_FORMAT}diff --git a/studio/components/layouts/ReportsLayout/ReportsMenu.utils.ts b/studio/components/layouts/ReportsLayout/ReportsMenu.utils.tsindex c120e0fbb64..8e6142aaef8 100644--- a/studio/components/layouts/ReportsLayout/ReportsMenu.utils.ts+++ b/studio/components/layouts/ReportsLayout/ReportsMenu.utils.ts@@ -23,15 +23,9 @@ export const generateReportsMenu = (project?: Project): ProductMenuGroup[] => {...(productReports? [{- name: 'API Overview',- key: 'api-overview',- url: `/project/${ref}/reports/api-overview`,- items: [],- },- {- name: 'API Bots',- key: 'api-bots',- url: `/project/${ref}/reports/api-bots`,+ name: 'API',+ key: 'api',+ url: `/project/${ref}/reports/api`,items: [],},{diff --git a/studio/pages/project/[ref]/reports/api-bots.tsx b/studio/pages/project/[ref]/reports/api-bots.tsxdeleted file mode 100644index 3df85b74abf..00000000000--- a/studio/pages/project/[ref]/reports/api-bots.tsx+++ /dev/null@@ -1,51 +0,0 @@-import { observer } from 'mobx-react-lite'-import { useRouter } from 'next/router'--import { NextPageWithLayout } from 'types'-import { Presets } from 'components/interfaces/Reports/Reports.types'-import ReportsLayout from 'components/layouts/ReportsLayout/ReportsLayout'-import { hooksFactory, usePresetReport } from 'components/interfaces/Reports/Reports.utils'-import { PRESET_CONFIG } from 'components/interfaces/Reports/Reports.constants'-import {- renderBotScores,- renderUserAgents,-} from 'components/interfaces/Reports/renderers/ApiBotsRenderers'-import ReportWidget from 'components/interfaces/Reports/ReportWidget'--export const ApiBotsReport: NextPageWithLayout = () => {- const router = useRouter()- const { ref } = router.query- const config = PRESET_CONFIG[Presets.API_BOTS]- const hooks = hooksFactory(ref as string, config)- const userAgents = hooks.userAgents()- const botScores = hooks.botScores()- const { isLoading, Layout } = usePresetReport([userAgents, botScores])- return (- <Layout title={config.title}>- <div className="grid lg:grid-cols-4 gap-4">- <ReportWidget- isLoading={isLoading}- params={userAgents[0].params}- className="col-span-4 col-start-1"- title="Top User Agents"- description="The types of user agents using the API and their organization source."- data={userAgents[0].logData || []}- renderer={renderUserAgents}- />- <ReportWidget- isLoading={isLoading}- params={botScores[0].params}- className="col-span-4 col-start-1"- title="Bot-like API Requests"- description="Suspicious bot-like requests, as flagged by Cloudflare"- data={botScores[0].logData || []}- renderer={renderBotScores}- />- </div>- </Layout>- )-}--ApiBotsReport.getLayout = (page) => <ReportsLayout>{page}</ReportsLayout>--export default observer(ApiBotsReport)diff --git a/studio/pages/project/[ref]/reports/api-overview.tsx b/studio/pages/project/[ref]/reports/api.tsxsimilarity index 58%rename from studio/pages/project/[ref]/reports/api-overview.tsxrename to studio/pages/project/[ref]/reports/api.tsxindex 2d266dabeaf..1c6257d180b 100644--- a/studio/pages/project/[ref]/reports/api-overview.tsx+++ b/studio/pages/project/[ref]/reports/api.tsx@@ -11,17 +11,27 @@ import {renderErrorRateChart,renderRequestsPathsTable,renderStatusCodesChart,-} from 'components/interfaces/Reports/renderers/OverviewRenderers'+ renderBotScores,+ renderUserAgents+} from 'components/interfaces/Reports/renderers/ApiRenderers'-export const ApiOverviewReport: NextPageWithLayout = () => {+export const ApiReport: NextPageWithLayout = () => {const router = useRouter()const { ref } = router.query- const config = PRESET_CONFIG[Presets.API_OVERVIEW]+ const config = PRESET_CONFIG[Presets.API]const hooks = hooksFactory(ref as string, config)const statusCodes = hooks.statusCodes()const errorRates = hooks.errorRates()const requestPaths = hooks.requestPaths()- const { isLoading, Layout } = usePresetReport([statusCodes, errorRates, requestPaths])+ const userAgents = hooks.userAgents()+ const botScores = hooks.botScores()+ const { isLoading, Layout } = usePresetReport([+ statusCodes,+ errorRates,+ requestPaths,+ userAgents,+ botScores,+ ])return (<Layout title={config.title}><div className="grid lg:grid-cols-4 gap-4">@@ -31,7 +41,7 @@ export const ApiOverviewReport: NextPageWithLayout = () => {className="col-span-4 col-start-1"title="API Status Codes"description="Distribution of API responses by status codes."- data={statusCodes[0].logData || []}+ data={statusCodes[0].logData || []}renderer={renderStatusCodesChart}/><ReportWidget@@ -40,7 +50,7 @@ export const ApiOverviewReport: NextPageWithLayout = () => {className="col-span-4 col-start-1"title="Error Rate"description="Percentage of API 5XX and 4XX error responses."- data={errorRates[0].logData || []}+ data={errorRates[0].logData || []}renderer={renderErrorRateChart}/><ReportWidget@@ -52,11 +62,32 @@ export const ApiOverviewReport: NextPageWithLayout = () => {data={requestPaths[0].logData || []}renderer={renderRequestsPathsTable}/>++ <h2>Bots</h2>++ <ReportWidget+ isLoading={isLoading}+ params={userAgents[0].params}+ className="col-span-4 col-start-1"+ title="Top User Agents"+ description="The types of user agents using the API and their organization source."+ data={userAgents[0].logData || []}+ renderer={renderUserAgents}+ />+ <ReportWidget+ isLoading={isLoading}+ params={botScores[0].params}+ className="col-span-4 col-start-1"+ title="Bot-like API Requests"+ description="Suspicious bot-like requests, as flagged by Cloudflare"+ data={botScores[0].logData || []}+ renderer={renderBotScores}+ /></div></Layout>)}-ApiOverviewReport.getLayout = (page) => <ReportsLayout>{page}</ReportsLayout>+ApiReport.getLayout = (page) => <ReportsLayout>{page}</ReportsLayout>-export default observer(ApiOverviewReport)+export default observer(ApiReport)diff --git a/studio/tests/pages/projects/reports/product-reports.test.js b/studio/tests/pages/projects/reports/product-reports.test.jsindex 885fcbe145a..a82267a2717 100644--- a/studio/tests/pages/projects/reports/product-reports.test.js+++ b/studio/tests/pages/projects/reports/product-reports.test.js@@ -7,8 +7,7 @@ import { get, post } from 'lib/common/fetch'import { useRouter } from 'next/router'import { render } from '../../../helpers'import { fireEvent, waitFor, screen } from '@testing-library/react'-import { ApiOverviewReport } from 'pages/project/[ref]/reports/api'-import { ApiBotsReport } from 'pages/project/[ref]/reports/api-bots'+import { ApiReport } from 'pages/project/[ref]/reports/api'import { AuthReport } from 'pages/project/[ref]/reports/auth'beforeEach(() => {@@ -25,8 +24,7 @@ beforeEach(() => {})describe.each([- { Page: ApiOverviewReport, contains: ['API Overview'] },- { Page: ApiBotsReport, contains: ['API Bots'] },+ { Page: ApiReport, contains: ['API'] },{ Page: AuthReport, contains: ['Auth'] },])('$Page rendering', ({ Page, contains }) => {test(`contains ${contains}`, async () => {