Files
supabase/apps/studio/next.config.js
T
Greg RichardsonandCharis 3f1df65bba SQL to REST translator (#25978)
* feat: sql-to-rest poc

* feat: sql-to-supabase-js poc

* chore: upgrade to libpg-query@15

* feat: sql-to-rest docs tool

* docs(sql-to-rest): add introduction

* docs: wording improvements

* fix: theme

* chore: tailwind placeholder

* feat(sql-to-rest): limit, offset, and range

* feat(sql-to-rest): sort by

* fix(sql-to-rest): ui theme

* feat(sql-to-rest): casts

* feat(sql-to-rest): dynamic faqs in ui

* feat(sql-to-rest): improve ui responsiveness

* feat(sql-to-rest): more advanced faqs in ui

* feat(sql-to-rest): http and curl syntax highlighting

* feat(sql-to-rest): baseUrl in http/curl rendering

* docs(sql-to-rest): clarification on curl flags

* feat(sql-to-rest): more faqs

* refactor(sql-to-rest): split faqs into own file

* refactor(sql-to-rest): move formatters to sql-to-rest package

* docs(sql-to-rest): move page to new tools section

* feat(sql-to-rest): joins and resource embeddings

* chore(sql-to-rest): rename 'convert' to 'translate'

* feat(sql-to-rest): add faqs

* feat(sql-to-rest): ui improvements

* feat(sql-to-rest): faq title adjustment

* feat(sql-to-rest): link to client lib docs

* feat(sql-to-rest): assumptions

* feat(sql-to-rest): friendly 'not supported yet' errors

* feat(sql-to-rest): json columns

* feat(sql-to-rest): remove curl -G flag if unused

* feat(sql-to-rest): better error handling

* chore: revert accidental rls ai work

* fix: build errors

* fix(sql-to-rest): theme

* feat(sql-to-rest): change base url

* feat(sql-to-rest): basic aggregate poc

* feat(sql-to-rest): group by

* feat(sql-to-rest): more group by checks

* feat(sql-to-rest): count(*) special case

* fix(sql-to-rest): tests

* feat(sql-to-rest): faq on 'and' operator

* fix(sql-to-rest): error messages

* fix(sql-to-rest): multiple filters on same column

* refactor(sql-to-rest): error hints

* feat(sql-to-rest): match and imatch

* feat(sql-to-rest): in operator

* feat(sql-to-rest): parsing error hints

* feat(sql-to-rest): default language to curl

* feat(sql-to-rest): format on cmd+s

* feat(sql-to-rest): format initial value

* fix(sql-to-rest): turn off tab query group

* feat(sql-to-rest): improve wording in error messages

* feat(sql-to-rest): animated code blocks

* feat(sql-to-rest): more error hints

* fix(sql-to-rest): strip primary relation prefix from columns

* feat(sql-to-rest): json column in order by clause

* feat(sql-to-rest): validate all referenced relations exist in from clause

* refactor(sql-to-rest): split core sql-to-rest lib into separate repo

* feat(sql-to-rest): upgrade to v0.1.1

* feat(sql-to-rest): upgrade to v0.1.2

* feat(sql-to-rest): upgrade to v0.1.4

* chore: upgrade libpg-query

* feat: update 'create a pr' link

* fix: app builds

* fix: prettier

* fix: typecheck

* fix: studio tests

* chore: remove console.log

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* docs(sql-to-rest): remove broken link to client libraries

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
2024-05-22 12:37:01 -06:00

491 lines
15 KiB
JavaScript

const { withSentryConfig } = require('@sentry/nextjs')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
// Required for nextjs standalone build
const path = require('path')
const API_URL = process.env.NEXT_PUBLIC_API_URL
? new URL(process.env.NEXT_PUBLIC_API_URL).origin
: ''
const SUPABASE_URL = process.env.SUPABASE_URL ? new URL(process.env.SUPABASE_URL).origin : ''
const GOTRUE_URL = process.env.NEXT_PUBLIC_GOTRUE_URL
? new URL(process.env.NEXT_PUBLIC_GOTRUE_URL).origin
: ''
const SUPABASE_PROJECTS_URL = 'https://*.supabase.co'
const SUPABASE_PROJECTS_URL_WS = 'wss://*.supabase.co'
// construct the URL for the Websocket Local URLs
let SUPABASE_LOCAL_PROJECTS_URL_WS = ''
if (SUPABASE_URL) {
const url = new URL(SUPABASE_URL)
const wsUrl = `${url.hostname}:${url.port}`
SUPABASE_LOCAL_PROJECTS_URL_WS = `ws://${wsUrl} wss://${wsUrl}`
}
// Needed to test docs search in local dev
const SUPABASE_DOCS_PROJECT_URL = process.env.NEXT_PUBLIC_SUPABASE_URL
? new URL(process.env.NEXT_PUBLIC_SUPABASE_URL).origin
: ''
const SUPABASE_STAGING_PROJECTS_URL = 'https://*.supabase.red'
const SUPABASE_STAGING_PROJECTS_URL_WS = 'wss://*.supabase.red'
const SUPABASE_COM_URL = 'https://supabase.com'
const CLOUDFLARE_CDN_URL = 'https://cdnjs.cloudflare.com'
const HCAPTCHA_SUBDOMAINS_URL = 'https://*.hcaptcha.com'
const HCAPTCHA_ASSET_URL = 'https://newassets.hcaptcha.com'
const HCAPTCHA_JS_URL = 'https://js.hcaptcha.com'
const CONFIGCAT_URL = 'https://cdn-global.configcat.com'
const STRIPE_SUBDOMAINS_URL = 'https://*.stripe.com'
const STRIPE_JS_URL = 'https://js.stripe.com'
const STRIPE_NETWORK_URL = 'https://*.stripe.network'
const CLOUDFLARE_URL = 'https://www.cloudflare.com'
const ONE_ONE_ONE_ONE_URL = 'https://1.1.1.1'
const VERCEL_URL = 'https://vercel.com'
const VERCEL_INSIGHTS_URL = 'https://*.vercel-insights.com'
const GITHUB_API_URL = 'https://api.github.com'
const GITHUB_USER_CONTENT_URL = 'https://raw.githubusercontent.com'
const VERCEL_LIVE_URL = 'https://vercel.live'
// used by vercel live preview
const PUSHER_URL = 'https://*.pusher.com'
const PUSHER_URL_WS = 'wss://*.pusher.com'
const DEFAULT_SRC_URLS = `${API_URL} ${SUPABASE_URL} ${GOTRUE_URL} ${SUPABASE_LOCAL_PROJECTS_URL_WS} ${SUPABASE_PROJECTS_URL} ${SUPABASE_PROJECTS_URL_WS} ${HCAPTCHA_SUBDOMAINS_URL} ${CONFIGCAT_URL} ${STRIPE_SUBDOMAINS_URL} ${STRIPE_NETWORK_URL} ${CLOUDFLARE_URL} ${ONE_ONE_ONE_ONE_URL} ${VERCEL_INSIGHTS_URL} ${GITHUB_API_URL} ${GITHUB_USER_CONTENT_URL}`
const SCRIPT_SRC_URLS = `${CLOUDFLARE_CDN_URL} ${HCAPTCHA_JS_URL} ${STRIPE_JS_URL}`
const FRAME_SRC_URLS = `${HCAPTCHA_ASSET_URL} ${STRIPE_JS_URL}`
const IMG_SRC_URLS = `${SUPABASE_URL} ${SUPABASE_COM_URL} ${SUPABASE_PROJECTS_URL}`
const STYLE_SRC_URLS = `${CLOUDFLARE_CDN_URL}`
const FONT_SRC_URLS = `${CLOUDFLARE_CDN_URL}`
const csp = [
...(process.env.VERCEL_ENV === 'preview' ||
process.env.NEXT_PUBLIC_ENVIRONMENT === 'local' ||
process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
? [
`default-src 'self' ${DEFAULT_SRC_URLS} ${SUPABASE_STAGING_PROJECTS_URL} ${SUPABASE_STAGING_PROJECTS_URL_WS} ${VERCEL_LIVE_URL} ${PUSHER_URL} ${PUSHER_URL_WS} ${SUPABASE_DOCS_PROJECT_URL};`,
`script-src 'self' 'unsafe-eval' 'unsafe-inline' ${SCRIPT_SRC_URLS} ${VERCEL_LIVE_URL};`,
`frame-src 'self' ${FRAME_SRC_URLS} ${VERCEL_LIVE_URL};`,
`img-src 'self' blob: data: ${IMG_SRC_URLS} ${SUPABASE_STAGING_PROJECTS_URL} ${VERCEL_URL};`,
`style-src 'self' 'unsafe-inline' ${STYLE_SRC_URLS} ${VERCEL_LIVE_URL};`,
`font-src 'self' ${FONT_SRC_URLS} ${VERCEL_LIVE_URL};`,
`worker-src 'self' blob: data:;`,
]
: [
`default-src 'self' ${DEFAULT_SRC_URLS};`,
`script-src 'self' 'unsafe-eval' 'unsafe-inline' ${SCRIPT_SRC_URLS};`,
`frame-src 'self' ${FRAME_SRC_URLS};`,
`img-src 'self' blob: data: ${IMG_SRC_URLS};`,
`style-src 'self' 'unsafe-inline' ${STYLE_SRC_URLS};`,
`font-src 'self' ${FONT_SRC_URLS};`,
`worker-src 'self' blob: data:;`,
]),
`object-src 'none';`,
`base-uri 'self';`,
`form-action 'self';`,
`frame-ancestors 'none';`,
`block-all-mixed-content;`,
...(process.env.NEXT_PUBLIC_IS_PLATFORM === 'true' &&
process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod'
? [`upgrade-insecure-requests;`]
: []),
].join(' ')
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
basePath: process.env.NEXT_PUBLIC_BASE_PATH,
output: 'standalone',
experimental: {
// [Kevin] Next polyfills Node modules like Crypto by default, blowing up the bundle size. We use generate-password-browser (safe to use in browser) and the polyfills are not needed for us
// Revisit on Next 14 upgrade (PR #19909)
fallbackNodePolyfills: false,
},
async redirects() {
return [
...(process.env.NEXT_PUBLIC_IS_PLATFORM === 'true'
? [
{
source: '/',
has: [
{
type: 'query',
key: 'next',
value: 'new-project',
},
],
destination: '/new/new-project',
permanent: false,
},
{
source: '/',
destination: '/projects',
permanent: false,
},
{
source: '/register',
destination: '/sign-up',
permanent: false,
},
{
source: '/signup',
destination: '/sign-up',
permanent: false,
},
{
source: '/signin',
destination: '/sign-in',
permanent: false,
},
{
source: '/login',
destination: '/sign-in',
permanent: false,
},
{
source: '/log-in',
destination: '/sign-in',
permanent: false,
},
]
: [
{
source: '/',
destination: '/project/default',
permanent: false,
},
{
source: '/register',
destination: '/project/default',
permanent: false,
},
{
source: '/signup',
destination: '/project/default',
permanent: false,
},
{
source: '/signin',
destination: '/project/default',
permanent: false,
},
{
source: '/login',
destination: '/project/default',
permanent: false,
},
{
source: '/log-in',
destination: '/project/default',
permanent: false,
},
]),
{
source: '/project/:ref/auth',
destination: '/project/:ref/auth/users',
permanent: true,
},
{
source: '/project/:ref/database',
destination: '/project/:ref/database/tables',
permanent: true,
},
{
source: '/project/:ref/database/replication',
destination: '/project/:ref/database/publications',
permanent: true,
},
{
source: '/project/:ref/database/graphiql',
destination: '/project/:ref/api/graphiql',
permanent: true,
},
{
source: '/project/:ref/storage',
destination: '/project/:ref/storage/buckets',
permanent: true,
},
{
source: '/project/:ref/settings',
destination: '/project/:ref/settings/general',
permanent: true,
},
{
source: '/project/:ref/auth/settings',
destination: '/project/:ref/auth/users',
permanent: true,
},
{
source: '/project/:ref/settings/billing/subscription',
has: [
{
type: 'query',
key: 'panel',
value: 'subscriptionPlan',
},
],
destination: '/org/_/billing?panel=subscriptionPlan',
permanent: true,
},
{
source: '/project/:ref/settings/billing/subscription',
has: [
{
type: 'query',
key: 'panel',
value: 'pitr',
},
],
destination: '/project/:ref/settings/addons?panel=pitr',
permanent: true,
},
{
source: '/project/:ref/settings/billing/subscription',
has: [
{
type: 'query',
key: 'panel',
value: 'computeInstance',
},
],
destination: '/project/:ref/settings/addons?panel=computeInstance',
permanent: true,
},
{
source: '/project/:ref/settings/billing/subscription',
has: [
{
type: 'query',
key: 'panel',
value: 'customDomain',
},
],
destination: '/project/:ref/settings/addons?panel=customDomain',
permanent: true,
},
{
source: '/project/:ref/settings/billing/subscription',
destination: '/org/_/billing',
permanent: true,
},
{
source: '/project/:ref/database/api-logs',
destination: '/project/:ref/logs/edge-logs',
permanent: true,
},
{
source: '/project/:ref/database/postgres-logs',
destination: '/project/:ref/logs/postgres-logs',
permanent: true,
},
{
source: '/project/:ref/database/postgrest-logs',
destination: '/project/:ref/logs/postgrest-logs',
permanent: true,
},
{
source: '/project/:ref/database/pgbouncer-logs',
destination: '/project/:ref/logs/pooler-logs',
permanent: true,
},
{
source: '/project/:ref/logs/pgbouncer-logs',
destination: '/project/:ref/logs/pooler-logs',
permanent: true,
},
{
source: '/project/:ref/database/realtime-logs',
destination: '/project/:ref/logs/realtime-logs',
permanent: true,
},
{
source: '/project/:ref/storage/logs',
destination: '/project/:ref/logs/storage-logs',
permanent: true,
},
{
source: '/project/:ref/auth/logs',
destination: '/project/:ref/logs/auth-logs',
permanent: true,
},
{
source: '/project/:ref/logs-explorer',
destination: '/project/:ref/logs/explorer',
permanent: true,
},
{
source: '/project/:ref/sql/templates',
destination: '/project/:ref/sql',
permanent: true,
},
{
source: '/org/:slug/settings',
destination: '/org/:slug/general',
permanent: true,
},
{
source: '/project/:ref/settings/billing/update',
destination: '/org/_/billing',
permanent: true,
},
{
source: '/project/:ref/settings/billing/update/free',
destination: '/org/_/billing',
permanent: true,
},
{
source: '/project/:ref/settings/billing/update/pro',
destination: '/org/_/billing',
permanent: true,
},
{
source: '/project/:ref/settings/billing/update/team',
destination: '/org/_/billing',
permanent: true,
},
{
source: '/project/:ref/settings/billing/update/enterprise',
destination: '/org/_/billing',
permanent: true,
},
{
source: '/project/:ref/sql',
destination: '/project/:ref/sql/new',
permanent: true,
},
{
permanent: true,
source: '/project/:ref/reports/linter',
destination: '/project/:ref/database/linter',
},
{
permanent: true,
source: '/project/:ref/reports/query-performance',
destination: '/project/:ref/database/query-performance',
},
{
permanent: true,
source: '/project/:ref/auth/column-privileges',
destination: '/project/:ref/database/column-privileges',
},
{
permanent: true,
source: '/project/:ref/database/linter',
destination: '/project/:ref/database/security-advisor',
},
...(process.env.NEXT_PUBLIC_BASE_PATH?.length
? [
{
source: '/',
destination: process.env.NEXT_PUBLIC_BASE_PATH,
basePath: false,
permanent: false,
},
]
: []),
]
},
async headers() {
return [
{
source: '/(.*?)',
headers: [
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'X-Content-Type-Options',
value: 'no-sniff',
},
{
key: 'Content-Security-Policy',
value: process.env.NEXT_PUBLIC_IS_PLATFORM === 'true' ? csp : "frame-ancestors 'none';",
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
],
},
{
source: '/img/:slug*',
headers: [{ key: 'cache-control', value: 'max-age=2592000' }],
},
{
source: '/fonts/:slug*',
headers: [{ key: 'cache-control', value: 'max-age=2592000' }],
},
]
},
images: {
// to make Vercel avatars work without issue. Vercel uses SVGs for users who don't have set avatars.
dangerouslyAllowSVG: true,
domains: [
'github.com',
'avatars.githubusercontent.com',
'api-frameworks.vercel.sh',
'vercel.com',
],
},
transpilePackages: [
'ui',
'ui-patterns',
'common',
'shared-data',
'api-types',
'icons',
'libpg-query',
],
webpack(config) {
config.module?.rules
.find((rule) => rule.oneOf)
.oneOf.forEach((rule) => {
if (rule.issuer?.and?.[0]?.toString().includes('_app')) {
const and = rule.issuer.and
rule.issuer.or = [/[\\/]node_modules[\\/]monaco-editor[\\/]/, { and }]
delete rule.issuer.and
}
})
return config
},
onDemandEntries: {
maxInactiveAge: 24 * 60 * 60 * 1000,
pagesBufferLength: 100,
},
}
// module.exports = withBundleAnalyzer(nextConfig)
// Make sure adding Sentry options is the last code to run before exporting, to
// ensure that your source maps include changes from all other Webpack plugins
module.exports =
process.env.NEXT_PUBLIC_IS_PLATFORM === 'true'
? withSentryConfig(
withBundleAnalyzer(nextConfig),
{
silent: true,
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: false,
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/monitoring',
// Hides source maps from generated client bundles
hideSourceMaps: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
}
)
: nextConfig