@@ -41,7 +41,7 @@ Find the complete code on [GitHub](https://github.com/supabase/supabase/tree/mas
|
||||
```ts
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
||||
import { HfInference } from 'https://esm.sh/@huggingface/inference@2.3.2'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { Database } from './types.ts'
|
||||
|
||||
console.log('Hello from `huggingface-image-captioning` function!')
|
||||
|
||||
@@ -166,7 +166,7 @@ from
|
||||
In practice, you will likely be calling this from the [Supabase client](/docs/reference/javascript/introduction) or through a custom backend layer. Here is a quick example of how you might call this from an [Edge Function](/docs/guides/functions) using JavaScript:
|
||||
|
||||
```tsx
|
||||
import { createClient } from 'npm:@supabase/supabase-js'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import OpenAI from 'npm:openai'
|
||||
|
||||
const supabaseUrl = Deno.env.get('SUPABASE_URL')!
|
||||
|
||||
@@ -23,7 +23,7 @@ const model = new Supabase.ai.Session('model-name')
|
||||
To get type hints and checks for the API you can import types from `functions-js` at the top of your file:
|
||||
|
||||
```ts
|
||||
import 'https://esm.sh/@supabase/functions-js/src/edge-runtime.d.ts'
|
||||
import 'jsr:@supabase/functions-js/edge-runtime.d.ts'
|
||||
```
|
||||
|
||||
</Admonition>
|
||||
@@ -100,7 +100,7 @@ Inference via larger models is supported via [Ollama](https://ollama.com/). In t
|
||||
```
|
||||
|
||||
```ts
|
||||
import 'https://esm.sh/@supabase/functions-js/src/edge-runtime.d.ts'
|
||||
import 'jsr:@supabase/functions-js/edge-runtime.d.ts'
|
||||
const session = new Supabase.ai.Session('mistral')
|
||||
|
||||
Deno.serve(async (req: Request) => {
|
||||
|
||||
@@ -12,7 +12,7 @@ Edge Functions work seamlessly with [Supabase Auth](/docs/guides/auth).
|
||||
When a user makes a request to an Edge Function, you can use the Authorization header to set the Auth context in the Supabase client:
|
||||
|
||||
```js mark=9
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
Deno.serve(async (req: Request) => {
|
||||
|
||||
@@ -33,7 +33,7 @@ Importantly, this is done _inside_ the `Deno.serve()` callback argument, so that
|
||||
After initializing a Supabase client with the Auth context, you can use `getUser()` to fetch the user object, and run queries in the context of the user with [Row Level Security (RLS)](/docs/guides/database/postgres/row-level-security) policies enforced.
|
||||
|
||||
```js mark=12:13
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
Deno.serve(async (req: Request) => {
|
||||
|
||||
@@ -61,7 +61,7 @@ Deno.serve(async (req: Request) => {
|
||||
After initializing a Supabase client with the Auth context, all queries will be executed with the context of the user. For database queries, this means [Row Level Security](/docs/guides/database/postgres/row-level-security) will be enforced.
|
||||
|
||||
```js mark=12
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
Deno.serve(async (req: Request) => {
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ You can also use other Postgres clients like [Deno Postgres](https://deno.land/x
|
||||
The `supabase-js` client is a great option for connecting to your Supabase database since it handles authorization with Row Level Security, and it automatically formats your response as JSON.
|
||||
|
||||
```ts index.ts
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
Deno.serve(async (_req) => {
|
||||
try {
|
||||
|
||||
@@ -53,7 +53,7 @@ Push notifications are an important part of any mobile app. They allow you to se
|
||||
1. `supabase secrets set --env-file .env.local`
|
||||
|
||||
```ts supabase/functions/push/index.ts
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.38.4'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
console.log('Hello from Functions!')
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ The following script is a good example to get started with testing your Edge Fun
|
||||
```typescript function-one-test.ts
|
||||
// Import required libraries and modules
|
||||
import { assert, assertEquals } from 'https://deno.land/std@0.192.0/testing/asserts.ts'
|
||||
import { createClient, SupabaseClient } from 'https://esm.sh/@supabase/supabase-js@2.23.0'
|
||||
import { createClient, SupabaseClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
// Set up the configuration for the Supabase client
|
||||
const supabaseUrl = Deno.env.get('SUPABASE_URL') ?? ''
|
||||
|
||||
@@ -73,14 +73,14 @@ custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supab
|
||||
<RefSubLayout.EducationRow>
|
||||
<RefSubLayout.Details>
|
||||
|
||||
You can use supabase-js in the Deno runtime via esm.sh:
|
||||
You can use supabase-js in the Deno runtime via [JSR](https://jsr.io/@supabase/supabase-js):
|
||||
|
||||
</RefSubLayout.Details>
|
||||
|
||||
<RefSubLayout.Examples>
|
||||
|
||||
```ts
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
```
|
||||
|
||||
</RefSubLayout.Examples>
|
||||
|
||||
@@ -203,7 +203,7 @@ Finally, let's create an [Edge Function](https://supabase.com/docs/guides/functi
|
||||
```tsx
|
||||
import { serve } from 'https://deno.land/std@0.170.0/http/server.ts'
|
||||
import 'https://deno.land/x/xhr@0.2.1/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.5.0'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { Configuration, OpenAIApi } from 'https://esm.sh/openai@3.1.0'
|
||||
import { supabaseClient } from './lib/supabase'
|
||||
|
||||
@@ -264,7 +264,7 @@ Here's another Edge Function that expands upon the simple example above:
|
||||
```tsx
|
||||
import { serve } from 'https://deno.land/std@0.170.0/http/server.ts'
|
||||
import 'https://deno.land/x/xhr@0.2.1/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.5.0'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import GPT3Tokenizer from 'https://esm.sh/gpt3-tokenizer@1.1.5'
|
||||
import { Configuration, OpenAIApi } from 'https://esm.sh/openai@3.1.0'
|
||||
import { oneLine, stripIndent } from 'https://esm.sh/common-tags@1.8.2'
|
||||
|
||||
@@ -96,7 +96,7 @@ Let’s step through a small demo where we accept some text, convert it into an
|
||||
```ts
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
||||
import { env, pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.0'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
// Preparation for Deno runtime
|
||||
env.useBrowserCache = false
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import CodeWindow from '~/components/CodeWindow'
|
||||
|
||||
const code = `import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
const code = `import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
Deno.serve(async (req: Request) => {
|
||||
// Create supabase client
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import CodeWindow from '~/components/CodeWindow'
|
||||
|
||||
const code = `import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
const code = `import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
Deno.serve(async (req: Request) => {
|
||||
// Create supabase client
|
||||
|
||||
@@ -56,7 +56,7 @@ serve(async (req: Request) => {
|
||||
description: `Read and write to any of your buckets, while also respecting storage auth policies.`,
|
||||
size: 'large',
|
||||
code: `import { serve } from "https://deno.land/std@0.114.0/http/server.ts";
|
||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@1.33.1";
|
||||
import { createClient } from "jsr:@supabase/supabase-js@2";
|
||||
|
||||
serve(async (req) => {
|
||||
const SUPABASE_URL = Deno.env.get("SUPABASE_URL") ?? "";
|
||||
@@ -78,7 +78,7 @@ serve(async (req) => {
|
||||
description: `Read, Write, Update, Insert anything on the database`,
|
||||
size: 'large',
|
||||
code: `import { serve } from "https://deno.land/std@0.114.0/http/server.ts";
|
||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@1.33.1";
|
||||
import { createClient } from "jsr:@supabase/supabase-js@2";
|
||||
|
||||
serve(async () => {
|
||||
const SUPABASE_URL = Deno.env.get("SUPABASE_URL") ?? "";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'https://esm.sh/react@18.2.0?deno-std=0.140.0'
|
||||
import { ImageResponse } from 'https://deno.land/x/og_edge@0.0.4/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'https://esm.sh/react@18.2.0?deno-std=0.140.0'
|
||||
import { ImageResponse } from 'https://deno.land/x/og_edge@0.0.4/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'https://esm.sh/react@18.2.0?deno-std=0.140.0'
|
||||
import { ImageResponse } from 'https://deno.land/x/og_edge@0.0.4/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'https://esm.sh/react@18.2.0?deno-std=0.140.0'
|
||||
import { ImageResponse } from 'https://deno.land/x/og_edge@0.0.4/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import "https://esm.sh/@supabase/functions-js/src/edge-runtime.d.ts";
|
||||
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
|
||||
|
||||
import { createClient } from "npm:@supabase/supabase-js@2.42.0";
|
||||
import { createClient } from "jsr:@supabase/supabase-js@2";
|
||||
import { Database, Tables } from "../_shared/database.types.ts";
|
||||
|
||||
type EmbeddingsRecord = Tables<"embeddings">;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import "https://esm.sh/@supabase/functions-js/src/edge-runtime.d.ts";
|
||||
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
|
||||
|
||||
import { createClient } from "npm:@supabase/supabase-js@2.42.0";
|
||||
import { createClient } from "jsr:@supabase/supabase-js@2";
|
||||
import { Database } from "../_shared/database.types.ts";
|
||||
|
||||
const supabase = createClient<Database>(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// and write files to Supabase Storage and other fields to a database table.
|
||||
|
||||
import { Application } from 'https://deno.land/x/oak@v11.1.0/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
const MB = 1024 * 1024
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// https://deno.land/manual/getting_started/setup_your_environment
|
||||
// This enables autocomplete, go to definition, etc.
|
||||
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { corsHeaders } from '../_shared/cors.ts'
|
||||
|
||||
console.log(`Function "get-tshirt-competition" up and running!`)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HfInference } from 'https://esm.sh/@huggingface/inference@2.3.2'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { Database } from './types.ts'
|
||||
|
||||
console.log('Hello from `huggingface-image-captioning` function!')
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"std/server": "https://deno.land/std@0.177.0/http/server.ts",
|
||||
"stripe": "https://esm.sh/stripe@11.1.0?target=deno",
|
||||
"sift": "https://deno.land/x/sift@0.6.0/mod.ts",
|
||||
"@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2.7.1",
|
||||
"@supabase/supabase-js": "jsr:@supabase/supabase-js@2",
|
||||
"postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts",
|
||||
"puppeteer": "https://deno.land/x/puppeteer@16.2.0/mod.ts",
|
||||
"React": "https://esm.sh/react@18.2.0?deno-std=0.177.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'https://esm.sh/react@18.2.0?deno-std=0.177.0'
|
||||
import { ImageResponse } from 'https://deno.land/x/og_edge@0.0.4/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { corsHeaders } from '../_shared/cors.ts'
|
||||
|
||||
const STORAGE_URL = 'https://obuldanrptloktxcffvn.supabase.co/storage/v1/object/public/images/lw6'
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// https://deno.land/manual/getting_started/setup_your_environment
|
||||
// This enables autocomplete, go to definition, etc.
|
||||
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// https://deno.land/manual/getting_started/setup_your_environment
|
||||
// This enables autocomplete, go to definition, etc.
|
||||
|
||||
import { createClient, SupabaseClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient, SupabaseClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// https://deno.land/manual/getting_started/setup_your_environment
|
||||
// This enables autocomplete, go to definition, etc.
|
||||
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { corsHeaders } from '../_shared/cors.ts'
|
||||
|
||||
console.log(`Function "select-from-table-with-auth-rls" up and running!`)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
console.log('Hello from the Sentry Functions Challenge!')
|
||||
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.42.5'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import * as Sentry from 'https://deno.land/x/sentry@7.102.0/index.mjs'
|
||||
|
||||
const supabase = createClient(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'https://esm.sh/react@18.2.0?deno-std=0.140.0'
|
||||
import { ImageResponse } from 'https://deno.land/x/og_edge@0.0.4/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.5.0'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { corsHeaders } from '../_shared/cors.ts'
|
||||
import { getTweets } from './getTweet.ts'
|
||||
import Tweet from './Tweet.tsx'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Redis } from 'https://deno.land/x/upstash_redis@v1.19.3/mod.ts'
|
||||
import { Ratelimit } from 'https://cdn.skypack.dev/@upstash/ratelimit@0.4.4'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.7.1'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
console.log(`Function "upstash-redis-counter" up and running!`)
|
||||
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
// 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.
|
||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.38.4";
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
|
||||
console.log("Hello from Functions!");
|
||||
console.log('Hello from Functions!')
|
||||
|
||||
interface Notification {
|
||||
id: string;
|
||||
user_id: string;
|
||||
body: string;
|
||||
id: string
|
||||
user_id: string
|
||||
body: string
|
||||
}
|
||||
|
||||
interface WebhookPayload {
|
||||
type: "INSERT" | "UPDATE" | "DELETE";
|
||||
table: string;
|
||||
record: Notification;
|
||||
schema: "public";
|
||||
old_record: null | Notification;
|
||||
type: 'INSERT' | 'UPDATE' | 'DELETE'
|
||||
table: string
|
||||
record: Notification
|
||||
schema: 'public'
|
||||
old_record: null | Notification
|
||||
}
|
||||
|
||||
const supabase = createClient(
|
||||
Deno.env.get("SUPABASE_URL")!,
|
||||
Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!
|
||||
);
|
||||
Deno.env.get('SUPABASE_URL')!,
|
||||
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
|
||||
)
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
const payload: WebhookPayload = await req.json();
|
||||
const payload: WebhookPayload = await req.json()
|
||||
const { data } = await supabase
|
||||
.from("profiles")
|
||||
.select("expo_push_token")
|
||||
.eq("id", payload.record.user_id)
|
||||
.single();
|
||||
.from('profiles')
|
||||
.select('expo_push_token')
|
||||
.eq('id', payload.record.user_id)
|
||||
.single()
|
||||
|
||||
const res = await fetch("https://exp.host/--/api/v2/push/send", {
|
||||
method: "POST",
|
||||
const res = await fetch('https://exp.host/--/api/v2/push/send', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${Deno.env.get("EXPO_ACCESS_TOKEN")}`,
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${Deno.env.get('EXPO_ACCESS_TOKEN')}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
to: data?.expo_push_token,
|
||||
sound: "default",
|
||||
sound: 'default',
|
||||
body: payload.record.body,
|
||||
}),
|
||||
}).then((res) => res.json());
|
||||
}).then((res) => res.json())
|
||||
|
||||
return new Response(JSON.stringify(res), {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
});
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
})
|
||||
|
||||
// To invoke:
|
||||
// curl -i --location --request POST 'http://localhost:54321/functions/v1/' \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { serve } from 'https://deno.land/std@0.170.0/http/server.ts'
|
||||
import 'https://deno.land/x/xhr@0.2.1/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.5.0'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { codeBlock, oneLine } from 'https://esm.sh/common-tags@1.8.2'
|
||||
import {
|
||||
ChatCompletionRequestMessage,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'https://deno.land/x/xhr@0.2.1/mod.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.8.0'
|
||||
import { createClient } from 'jsr:@supabase/supabase-js@2'
|
||||
import { Configuration, OpenAIApi } from 'https://esm.sh/openai@3.1.0'
|
||||
import { Database } from '../common/database-types.ts'
|
||||
import { ApplicationError, UserError } from '../common/errors.ts'
|
||||
|
||||
Reference in New Issue
Block a user