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