The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(workers): support private deployments FE-4328 (#49902)
Jordi Enric55706ca61b05
diff --git a/apps/studio/components/interfaces/Workers/workerSnippets.test.ts b/apps/studio/components/interfaces/Workers/workerSnippets.test.tsindex 77f434a1437..bf8c212e7e5 100644--- a/apps/studio/components/interfaces/Workers/workerSnippets.test.ts+++ b/apps/studio/components/interfaces/Workers/workerSnippets.test.ts@@ -1,6 +1,5 @@import { describe, expect, it } from 'vitest'-import { WORKERS_REGION } from './Workers.constants'import { buildWorkerCliCommands, buildWorkerSnippets, EXAMPLE_WORKER } from './workerSnippets'const input = (overrides: Partial<Parameters<typeof buildWorkerSnippets>[0]> = {}) => ({@@ -10,73 +9,19 @@ const input = (overrides: Partial<Parameters<typeof buildWorkerSnippets>[0]> = {})describe('buildWorkerSnippets', () => {- it('points the invoke examples at the worker URL', () => {- const { curl, javascript, python } = buildWorkerSnippets(input({ name: 'embed' }))- const url = 'https://abcdefgh.supabase.co/workers/v1/embed'+ it('passes private exposure to the CLI and config', () => {+ const { cli, configToml } = buildWorkerSnippets(input({ access: 'private' }))- expect(curl).toContain(`'${url}'`)- expect(javascript).toContain(`'${url}'`)- expect(python).toContain(`"${url}"`)- })-- it('leaves a placeholder invoke URL until the project settings resolve', () => {- const { curl } = buildWorkerSnippets(input({ endpoint: undefined }))- expect(curl).toContain('[YOUR WORKER URL]')- })-- it('does not require authorization for the CLI invoke example', () => {- expect(buildWorkerSnippets(input()).curl).not.toContain('Authorization')- })-- it('asks for the anon key to invoke a public worker and the service role key for a private one', () => {- expect(buildWorkerSnippets(input({ access: 'public' })).javascript).toContain('[YOUR ANON KEY]')- expect(buildWorkerSnippets(input({ access: 'private' })).javascript).toContain(- '[YOUR SERVICE ROLE KEY]'- )- })-- it('falls back to a placeholder name when the worker has none', () => {- expect(buildWorkerSnippets(input({ name: ' ' })).cli).toContain('my-worker')- })-- it('trims the name before interpolating it', () => {- expect(buildWorkerSnippets(input({ name: ' embed ' })).cli).toContain('new embed --runtime')- })-- it('defaults the runtime when the API omits it', () => {- expect(buildWorkerSnippets(input({ runtime: undefined })).cli).toContain('--runtime node')- })-- it('writes the worker spec into the config.toml block', () => {- const { configToml } = buildWorkerSnippets(- input({- name: 'embed',- runtime: 'python',- size: '4gb-2vcpu',- access: 'private',- instances: 3,- })- )-- expect(configToml).toContain('[workers.embed]')- expect(configToml).toContain('runtime = "python"')- expect(configToml).toContain('size = "4gb-2vcpu" # 4 GB · 2 vCPU')- expect(configToml).toContain('access = "private"')- expect(configToml).toContain('instances = 3')- expect(configToml).toContain(WORKERS_REGION)+ expect(cli).toContain('--exposure private')+ expect(configToml).toContain('exposure = "private"')})})describe('buildWorkerCliCommands', () => {- it('names the worker in every command', () => {+ it('targets the requested worker in every management command', () => {const commands = buildWorkerCliCommands('embed')- expect(commands).not.toHaveLength(0)- for (const { command } of commands) {- expect(command).toContain('embed')- }- })- it('falls back to a placeholder name when the worker has none', () => {- expect(buildWorkerCliCommands(' ')[0].command).toContain('my-worker')+ expect(commands).toHaveLength(4)+ expect(commands.every(({ command }) => command.includes('embed'))).toBe(true)})})diff --git a/apps/studio/components/interfaces/Workers/workerSnippets.ts b/apps/studio/components/interfaces/Workers/workerSnippets.tsindex 7cc337d332c..aaea57235f5 100644--- a/apps/studio/components/interfaces/Workers/workerSnippets.ts+++ b/apps/studio/components/interfaces/Workers/workerSnippets.ts@@ -41,10 +41,7 @@ export function buildWorkerSnippets(input: WorkerSnippetInput): WorkerSnippets {const cli = [`supabase ${CLI_NAME} new ${name} --runtime ${runtime}`,- // size comes from config.toml — push has no flag for it. Same for access: the CLI- // doesn't have a route to a private worker yet, so this always deploys as public.- `supabase ${CLI_NAME} push ${name} --instances ${input.instances}`,- ...(input.access === 'private' ? [`# note: the CLI can only deploy public workers today`] : []),+ `supabase ${CLI_NAME} push ${name} --instances ${input.instances} --exposure ${input.access}`,].join('\n')const curl = [@@ -57,7 +54,7 @@ export function buildWorkerSnippets(input: WorkerSnippetInput): WorkerSnippets {`[${CLI_NAME}.${name}]`,`runtime = "${runtime}"`,`size = "${input.size}" # ${formatSize(input.size)}`,- `access = "${input.access}"`,+ `exposure = "${input.access}"`,`instances = ${input.instances}`,`# region is locked to ${WORKERS_REGION} at alpha`,].join('\n')@@ -78,10 +75,7 @@ export function buildWorkerSnippets(input: WorkerSnippetInput): WorkerSnippets {configBlock,'```',``,- `3. Run \`supabase ${CLI_NAME} push ${name}\` to deploy it.`,- ...(input.access === 'private'- ? [``, `Note: the CLI can only deploy public workers today.`]- : []),+ `3. Run \`supabase ${CLI_NAME} push ${name} --exposure ${input.access}\` to deploy it.`,].join('\n')const keyPlaceholder = input.access === 'public' ? '[YOUR ANON KEY]' : '[YOUR SERVICE ROLE KEY]'