EdgeFunctionDetails.constants.ts82 lines · main
1interface InvocationTab {
2 id: string
3 label: string
4 language: 'bash' | 'js' | 'ts' | 'dart' | 'python'
5 hideLineNumbers?: boolean
6 code: (props: {
7 showKey: boolean
8 functionUrl: string
9 functionName: string
10 apiKey: string
11 }) => string
12}
13
14export const INVOCATION_TABS: InvocationTab[] = [
15 {
16 id: 'curl',
17 label: 'cURL',
18 language: 'bash',
19 code: ({ showKey, functionUrl, apiKey }) => {
20 const obfuscatedName = apiKey.includes('publishable')
21 ? 'BRIVEN_PUBLISHABLE_KEY'
22 : 'BRIVEN_ANON_KEY'
23 const keyValue = showKey ? apiKey : obfuscatedName
24
25 return `curl -L -X POST '${functionUrl}' \\
26 -H 'Authorization: Bearer ${keyValue}' \\${apiKey.includes('publishable') ? `\n -H 'apikey: ${keyValue}' \\` : ''}
27 -H 'Content-Type: application/json' \\
28 --data '{"name":"Functions"}'`
29 },
30 },
31 {
32 id: 'briven-js',
33 label: 'JavaScript',
34 language: 'js',
35 hideLineNumbers: true,
36 code: ({ functionName }) => `import { createClient } from '@supabase/supabase-js'
37
38const briven = createClient(process.env.BRIVEN_URL, process.env.BRIVEN_ANON_KEY)
39const { data, error } = await briven.functions.invoke('${functionName}', {
40 body: { name: 'Functions' },
41})`,
42 },
43 {
44 id: 'swift',
45 label: 'Swift',
46 language: 'ts',
47 hideLineNumbers: true,
48 code: ({ functionName }) => `struct Response: Decodable {
49 // Expected response definition
50}
51
52let response: Response = try await briven.functions
53 .invoke(
54 "${functionName}",
55 options: FunctionInvokeOptions(
56 body: ["name": "Functions"]
57 )
58 )`,
59 },
60 {
61 id: 'flutter',
62 label: 'Flutter',
63 language: 'dart',
64 hideLineNumbers: true,
65 code: ({
66 functionName,
67 }) => `final res = await briven.functions.invoke('${functionName}', body: {'name': 'Functions'});
68final data = res.data;`,
69 },
70 {
71 id: 'python',
72 label: 'Python',
73 language: 'python',
74 hideLineNumbers: true,
75 code: ({ functionName }) => `response = briven.functions.invoke(
76 "${functionName}",
77 invoke_options={"body": {"name": "Functions"}}
78)`,
79 },
80]
81
82export const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as const