Skip to content

feat(functions) update functions template to match new 'server' style#5063

Open
kallebysantos wants to merge 6 commits intosupabase:developfrom
kallebysantos:feat-update-functions-template-server-sdk
Open

feat(functions) update functions template to match new 'server' style#5063
kallebysantos wants to merge 6 commits intosupabase:developfrom
kallebysantos:feat-update-functions-template-server-sdk

Conversation

@kallebysantos
Copy link
Copy Markdown
Member

@kallebysantos kallebysantos commented Apr 10, 2026

What kind of change does this PR introduce?

Feature

What is the new behavior?

Apply withSupabase helper from @supabase/server

Additional context

A new optional flag --auth was introduced for the functions new command, chose between the auth access template:

  • always No credentials required - Open endpoints, wrappers that handle their own auth
  • apikey Valid publishable key or secret key - Use respectively for Client-facing, key-validated endpoints or Server-to-server, internal calls
  • user User JWT required - Authenticated user endpoints

Current default --auth apikey

--
Towards FUNC-563

- Creating different templates for 'functions new' command
- Handling '--auth' flag to specify which template use
@kallebysantos kallebysantos requested a review from a team as a code owner April 10, 2026 19:04
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 10, 2026

Coverage Report for CI Build 24408017002

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.06%) to 63.746%

Details

  • Coverage decreased (-0.06%) from the base build.
  • Patch coverage: 7 uncovered changes across 2 files (19 of 26 lines covered, 73.08%).
  • 111 coverage regressions across 8 files.

Uncovered Changes

File Changed Covered %
cmd/functions.go 6 1 16.67%
internal/functions/new/new.go 20 18 90.0%

Coverage Regressions

111 previously-covered lines in 8 files lost coverage.

File Lines Losing Coverage Coverage
internal/db/declarative/declarative.go 51 43.1%
internal/sso/update/update.go 23 51.81%
internal/sso/create/create.go 13 0.0%
internal/sso/remove/remove.go 8 54.17%
internal/sso/list/list.go 7 55.0%
internal/utils/git.go 5 57.14%
internal/vanity_subdomains/activate/activate.go 2 87.5%
internal/vanity_subdomains/check/check.go 2 87.5%

Coverage Stats

Coverage Status
Relevant Lines: 15375
Covered Lines: 9801
Line Coverage: 63.75%
Coverage Strength: 7.05 hits per line

💛 - Coveralls

@kallebysantos
Copy link
Copy Markdown
Member Author

WIP: Do not merge until @supabase/server be announced

Comment thread cmd/functions.go Outdated
Comment thread internal/functions/new/templates/index_always_access.ts
Copy link
Copy Markdown
Member

@avallete avallete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments. Otherwise LGTM.

--header 'Content-Type: application/json' \
--data '{"name":"Functions"}'

--header 'apiKey: {{ .PublishableKey }}'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue

This wont execute if copy/pasted because of missing backslash

Suggested change
--header 'apiKey: {{ .PublishableKey }}'
--header 'apiKey: {{ .PublishableKey }}' \


// Setup type definitions for built-in Supabase Runtime APIs
import "@supabase/functions-js/edge-runtime.d.ts"
import { withSupabase } from '@supabase/server'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick
For code style consistency with the other templates it should be:

Suggested change
import { withSupabase } from '@supabase/server'
import { withSupabase } from "@supabase/server";

"imports": {
"@supabase/functions-js": "jsr:@supabase/functions-js@^2"
"@supabase/functions-js": "jsr:@supabase/functions-js@^2",
"@supabase/server": "npm:@supabase/server"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

Should this be pinned to a major version like for functions-js ?

Comment thread cmd/functions.go
Comment on lines +104 to +107
authMode := new_.AuthAccessModeApiKey
if len(authAccessMode.Value) > 0 {
authMode = new_.AuthAccessMode(authAccessMode.Value)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick

Instead of manually setting this default could use the Value param in the flag definition like we do here: https://github.com/kallebysantos/supabase-cli/blob/6b96df41dec4f585ec3b0855ebdfc104af005e6e/cmd/gen.go#L64

	authAccessMode = utils.EnumFlag{
		Allowed: []string{
			string(new_.AuthAccessModeAlways),
			string(new_.AuthAccessModeApiKey),
			string(new_.AuthAccessModeUser),
		},
        Value: string(new_.AuthAccessModeApiKey)
	}

That'll also make --help show the real default automatically and let us drop the "(default apikey)" in the flag description: https://github.com/kallebysantos/supabase-cli/blob/6b96df41dec4f585ec3b0855ebdfc104af005e6e/cmd/functions.go#L183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants