- 
                Notifications
    You must be signed in to change notification settings 
- Fork 304
Optimize config, entrypoint, and Deno configurations #3431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            Soumojit-007
  wants to merge
  4
  commits into
  supabase:develop
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
Soumojit-007:feat/optimize-config
  
      
      
   
  
    
  
  
  
 
  
      
    base: develop
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            4 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3a9ebe8
              
                I've restructured and optimized the config.toml, index.ts, and deno.j…
              
              
                Soumojit-007 213faef
              
                Optimize config, entrypoint, and Deno configurations
              
              
                Soumojit-007 ca611bd
              
                Merge branch 'feat/optimize-config' of https://github.com/Soumojit-00…
              
              
                Soumojit-007 7847d53
              
                Add golangci-lint GitHub Action
              
              
                Soumojit-007 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
              Empty file.
          
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "imports": { | ||
| "std/": "https://deno.land/std@0.220.1/", | ||
| "@supabase/supabase-js": "https://deno.land/x/supabase@1.0.0/mod.ts" | ||
| } | ||
| } | 
            File renamed without changes.
          
    
            File renamed without changes.
          
    
            File renamed without changes.
          
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [functions.check-email-existence] | ||
| enabled = true | ||
| verify_jwt = false # Public endpoint | ||
| import_map = "supabase/functions/check-email-existence/deno.json" | ||
| entrypoint = "supabase/functions/check-email-existence/index.ts" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "imports": { | ||
| "@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2" | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // // Follow this setup guide to integrate the Deno language server with your editor: | ||
| // // https://deno.land/manual/getting_started/setup_your_environment | ||
| // // This enables autocomplete, go to definition, etc. | ||
|  | ||
| // // Setup type definitions for built-in Supabase Runtime APIs | ||
|  | ||
| // import "jsr:@supabase/functions-js/edge-runtime.d.ts" | ||
|  | ||
| // // console.log("Hello from Functions!") | ||
|  | ||
| // // Deno.serve(async (req) => { | ||
| // // const { name } = await req.json() | ||
| // // const data = { | ||
| // // message: `Hello ${name}!`, | ||
| // // } | ||
|  | ||
| // // return new Response( | ||
| // // JSON.stringify(data), | ||
| // // { headers: { "Content-Type": "application/json" } }, | ||
| // // ) | ||
| // // }) | ||
|  | ||
| // /* To invoke locally: | ||
|  | ||
| // 1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start) | ||
| // 2. Make an HTTP request: | ||
|  | ||
| // curl -i --location --request POST '{{ .URL }}' \ | ||
| // --header 'Authorization: Bearer {{ .Token }}' \ | ||
| // --header 'Content-Type: application/json' \ | ||
| // --data '{"name":"Functions"}' | ||
|  | ||
| // */ | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
| import { createClient } from "https://esm.sh/@supabase/supabase-js@2"; | ||
| const supabase = createClient( | ||
| Deno.env.get("SUPABASE_URL")!, | ||
| Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!, | ||
| { auth: { persistSession: false } } | ||
| ); | ||
|  | ||
| // HTTP handler | ||
| Deno.serve(async (req) => { | ||
| // 1. Reject non-POST requests | ||
| if (req.method !== "POST") { | ||
| return new Response(JSON.stringify({ error: "Method Not Allowed" }), { | ||
| status: 405, | ||
| headers: { "Content-Type": "application/json" } | ||
| }); | ||
| } | ||
|  | ||
| try { | ||
| // 2. Parse and validate email | ||
| const { email } = await req.json(); | ||
| if (!email || typeof email !== "string") { | ||
| return new Response( | ||
| JSON.stringify({ error: "Valid email required" }), | ||
| { status: 400, headers: { "Content-Type": "application/json" } } | ||
| ); | ||
| } | ||
|  | ||
| // 3. Check user existence | ||
| const { data, error } = await supabase.auth.admin.getUserByEmail(email); | ||
| if (error) throw error; | ||
|  | ||
| // 4. Return boolean response | ||
| return new Response( | ||
| JSON.stringify({ exists: !!data.user }), | ||
| { headers: { "Content-Type": "application/json" } } | ||
| ); | ||
|  | ||
| } catch (err) { | ||
| // 5. Handle errors gracefully | ||
| console.error(`Error checking email: ${err.message}`); | ||
| return new Response( | ||
| JSON.stringify({ error: "Internal server error" }), | ||
| { status: 500, headers: { "Content-Type": "application/json" } } | ||
| ); | ||
| } | ||
| }); | 
This file was deleted.
      
      Oops, something went wrong.
      
    
  This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,32 +1,52 @@ | ||
| // Follow this setup guide to integrate the Deno language server with your editor: | ||
| // https://deno.land/manual/getting_started/setup_your_environment | ||
| // This enables autocomplete, go to definition, etc. | ||
|  | ||
| // Setup type definitions for built-in Supabase Runtime APIs | ||
| import "jsr:@supabase/functions-js/edge-runtime.d.ts" | ||
| // index.ts | ||
| // import { serve } from "https://deno.land/std@0.177.0/http/server.ts"; | ||
|  | ||
| console.log("Hello from Functions!") | ||
| // serve((_req) => { | ||
| // return new Response("User existence check function is working!", { | ||
| // headers: { "Content-Type": "text/plain" }, | ||
| // }); | ||
| // }); | ||
|  | ||
| Deno.serve(async (req) => { | ||
| const { name } = await req.json() | ||
| const data = { | ||
| message: `Hello ${name}!`, | ||
| } | ||
|  | ||
| return new Response( | ||
| JSON.stringify(data), | ||
| { headers: { "Content-Type": "application/json" } }, | ||
| ) | ||
| }) | ||
|  | ||
| /* To invoke locally: | ||
| // index.ts | ||
| // import { serve } from 'https://deno.land/std/http/server.ts' | ||
|  | ||
| // serve((_req) => { | ||
| // return new Response("Hello from check-user-existence function!"); | ||
| // }) | ||
|  | ||
|  | ||
|  | ||
| 1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start) | ||
| 2. Make an HTTP request: | ||
| // Setup type definitions for built-in Supabase Runtime APIs | ||
| import "jsr:@supabase/functions-js/edge-runtime.d.ts"; | ||
|  | ||
| import { serve } from 'std/server'; | ||
| import { createClient } from '@supabase/supabase-js'; | ||
|  | ||
| const supabaseUrl = Deno.env.get('SUPABASE_URL')!; | ||
| const supabaseServiceKey = Deno.env.get('SERVICE_ROLE_KEY')!; | ||
|  | ||
| curl -i --location --request POST '{{ .URL }}' \ | ||
| --header 'Authorization: Bearer {{ .Token }}' \ | ||
| --header 'Content-Type: application/json' \ | ||
| --data '{"name":"Functions"}' | ||
| const supabaseClient = createClient(supabaseUrl, supabaseServiceKey, { | ||
| auth: { | ||
| persistSession: false, | ||
| }, | ||
| }); | ||
|  | ||
| */ | ||
| serve(async (req: Request) => { | ||
| if (req.method !== 'POST') { | ||
| return new Response('Method Not Allowed', { status: 405 }); | ||
| } | ||
| try { | ||
| const { email }: { email?: string } = await req.json(); | ||
| if (!email) { | ||
| return new Response(JSON.stringify({ error: 'Email is required' }), { status: 400, headers: { 'Content-Type': 'application/json' } }); | ||
| } | ||
| const { data, error } = await supabaseClient.auth.admin.getUserByEmail(email); | ||
| const exists = data !== null; | ||
| return new Response(JSON.stringify({ exists }), { headers: { 'Content-Type': 'application/json' } }); | ||
| } catch (error) { | ||
| return new Response(JSON.stringify({ error: 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json' } }); | ||
| } | ||
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| { | ||
| "imports": { | ||
| "module": "jsr:@supabase/functions-js/edge-runtime.d.ts" | ||
| "std/": "[https://deno.land/std@1.42.0/](https://deno.land/std@1.42.0/)", | ||
| "@supabase/supabase-js": "[https://esm.supabase.com/supabase-js@2](https://esm.supabase.com/supabase-js@2)" | ||
| } | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1 +1,31 @@ | ||
| import "module"; | ||
| // Setup type definitions for built-in Supabase Runtime APIs | ||
| import "jsr:@supabase/functions-js/edge-runtime.d.ts"; | ||
|  | ||
| import { serve } from 'std/server'; | ||
| import { createClient } from '@supabase/supabase-js'; | ||
|  | ||
| const supabaseUrl = Deno.env.get('SUPABASE_URL')!; | ||
| const supabaseServiceKey = Deno.env.get('SERVICE_ROLE_KEY')!; | ||
|  | ||
| const supabaseClient = createClient(supabaseUrl, supabaseServiceKey, { | ||
| auth: { | ||
| persistSession: false, | ||
| }, | ||
| }); | ||
|  | ||
| serve(async (req: Request) => { | ||
| if (req.method !== 'POST') { | ||
| return new Response('Method Not Allowed', { status: 405 }); | ||
| } | ||
| try { | ||
| const { email }: { email?: string } = await req.json(); | ||
| if (!email) { | ||
| return new Response(JSON.stringify({ error: 'Email is required' }), { status: 400, headers: { 'Content-Type': 'application/json' } }); | ||
| } | ||
| const { data, error } = await supabaseClient.auth.admin.getUserByEmail(email); | ||
| const exists = data !== null; | ||
| return new Response(JSON.stringify({ exists }), { headers: { 'Content-Type': 'application/json' } }); | ||
| } catch (error) { | ||
| return new Response(JSON.stringify({ error: 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json' } }); | ||
| } | ||
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "allowJs": true, | ||
| "lib": ["esnext"], | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "moduleResolution": "node" | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "allowJs": true, | ||
| "lib": ["esnext"], | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "moduleResolution": "node" | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, you want to make the default template created by
functions newmore useful? If so, we should introduce a new flag instead of modifying the default behaviour. For eg.