| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- interface InvocationTab {
- id: string
- label: string
- language: 'bash' | 'js' | 'ts' | 'dart' | 'python'
- hideLineNumbers?: boolean
- code: (props: {
- showKey: boolean
- functionUrl: string
- functionName: string
- apiKey: string
- }) => string
- }
- export const INVOCATION_TABS: InvocationTab[] = [
- {
- id: 'curl',
- label: 'cURL',
- language: 'bash',
- code: ({ showKey, functionUrl, apiKey }) => {
- const obfuscatedName = apiKey.includes('publishable')
- ? 'BRIVEN_PUBLISHABLE_KEY'
- : 'BRIVEN_ANON_KEY'
- const keyValue = showKey ? apiKey : obfuscatedName
- return `curl -L -X POST '${functionUrl}' \\
- -H 'Authorization: Bearer ${keyValue}' \\${apiKey.includes('publishable') ? `\n -H 'apikey: ${keyValue}' \\` : ''}
- -H 'Content-Type: application/json' \\
- --data '{"name":"Functions"}'`
- },
- },
- {
- id: 'briven-js',
- label: 'JavaScript',
- language: 'js',
- hideLineNumbers: true,
- code: ({ functionName }) => `import { createClient } from '@supabase/supabase-js'
- const briven = createClient(process.env.BRIVEN_URL, process.env.BRIVEN_ANON_KEY)
- const { data, error } = await briven.functions.invoke('${functionName}', {
- body: { name: 'Functions' },
- })`,
- },
- {
- id: 'swift',
- label: 'Swift',
- language: 'ts',
- hideLineNumbers: true,
- code: ({ functionName }) => `struct Response: Decodable {
- // Expected response definition
- }
- let response: Response = try await briven.functions
- .invoke(
- "${functionName}",
- options: FunctionInvokeOptions(
- body: ["name": "Functions"]
- )
- )`,
- },
- {
- id: 'flutter',
- label: 'Flutter',
- language: 'dart',
- hideLineNumbers: true,
- code: ({
- functionName,
- }) => `final res = await briven.functions.invoke('${functionName}', body: {'name': 'Functions'});
- final data = res.data;`,
- },
- {
- id: 'python',
- label: 'Python',
- language: 'python',
- hideLineNumbers: true,
- code: ({ functionName }) => `response = briven.functions.invoke(
- "${functionName}",
- invoke_options={"body": {"name": "Functions"}}
- )`,
- },
- ]
- export const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as const
|