EdgeFunctionDetails.constants.ts 2.2 KB

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