EdgeFunctionDetails.utils.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { EdgeFunction } from '@/data/edge-functions/edge-function-query'
  2. export const generateCLICommands = ({
  3. selectedFunction,
  4. functionUrl,
  5. anonKey,
  6. }: {
  7. selectedFunction?: EdgeFunction
  8. functionUrl: string
  9. anonKey: string
  10. }) => {
  11. const managementCommands: any = [
  12. {
  13. command: `briven functions deploy ${selectedFunction?.slug}`,
  14. description: 'This will overwrite the deployed function with your new function',
  15. jsx: () => {
  16. return (
  17. <>
  18. <span className="text-brand">briven</span> functions deploy {selectedFunction?.slug}
  19. </>
  20. )
  21. },
  22. comment: 'Deploy a new version',
  23. },
  24. {
  25. command: `briven functions delete ${selectedFunction?.slug}`,
  26. description: 'This will remove the function and all the logs associated with it',
  27. jsx: () => {
  28. return (
  29. <>
  30. <span className="text-brand">briven</span> functions delete {selectedFunction?.slug}
  31. </>
  32. )
  33. },
  34. comment: 'Delete the function',
  35. },
  36. ]
  37. const secretCommands: any = [
  38. {
  39. command: `briven secrets list`,
  40. description: 'This will list all the secrets for your project',
  41. jsx: () => {
  42. return (
  43. <>
  44. <span className="text-brand">briven</span> secrets list
  45. </>
  46. )
  47. },
  48. comment: 'View all secrets',
  49. },
  50. {
  51. command: `briven secrets set NAME1=VALUE1 NAME2=VALUE2`,
  52. description: 'This will set secrets for your project',
  53. jsx: () => {
  54. return (
  55. <>
  56. <span className="text-brand">briven</span> secrets set NAME1=VALUE1 NAME2=VALUE2
  57. </>
  58. )
  59. },
  60. comment: 'Set secrets for your project',
  61. },
  62. {
  63. command: `briven secrets unset NAME1 NAME2 `,
  64. description: 'This will delete secrets for your project',
  65. jsx: () => {
  66. return (
  67. <>
  68. <span className="text-brand">briven</span> secrets unset NAME1 NAME2
  69. </>
  70. )
  71. },
  72. comment: 'Unset secrets for your project',
  73. },
  74. ]
  75. const invokeCommands: any = [
  76. {
  77. command: `curl -L -X POST '${functionUrl}' -H 'Authorization: Bearer ${
  78. anonKey ?? '[YOUR ANON KEY]'
  79. }' --data '{"name":"Functions"}'`,
  80. description: 'Invokes the hello function',
  81. jsx: () => {
  82. return (
  83. <>
  84. <span className="text-brand">curl</span> -L -X POST '{functionUrl}'{' '}
  85. {selectedFunction?.verify_jwt
  86. ? `-H
  87. 'Authorization: Bearer [YOUR ANON KEY]' `
  88. : ''}
  89. {`--data '{"name":"Functions"}'`}
  90. </>
  91. )
  92. },
  93. comment: 'Invoke your function',
  94. },
  95. ]
  96. return { managementCommands, secretCommands, invokeCommands }
  97. }