ProjectAPIDocs.constants.ts 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  1. import { DOCS_URL } from '@/lib/constants'
  2. export const API_DOCS_CATEGORIES = {
  3. INTRODUCTION: 'introduction',
  4. USER_MANAGEMENT: 'user-management',
  5. ENTITIES: 'entities',
  6. STORED_PROCEDURES: 'stored-procedures',
  7. STORAGE: 'storage',
  8. EDGE_FUNCTIONS: 'edge-functions',
  9. REALTIME: 'realtime',
  10. }
  11. export const DOCS_MENU = [
  12. { name: 'Connect', key: API_DOCS_CATEGORIES.INTRODUCTION },
  13. { name: 'User Management', key: API_DOCS_CATEGORIES.USER_MANAGEMENT },
  14. { name: 'Tables & Views', key: API_DOCS_CATEGORIES.ENTITIES },
  15. { name: 'Database Functions', key: API_DOCS_CATEGORIES.STORED_PROCEDURES },
  16. { name: 'Storage', key: API_DOCS_CATEGORIES.STORAGE },
  17. { name: 'Edge Functions', key: API_DOCS_CATEGORIES.EDGE_FUNCTIONS },
  18. { name: 'Realtime', key: API_DOCS_CATEGORIES.REALTIME },
  19. ] as const
  20. export const DOCS_CONTENT = {
  21. init: {
  22. key: 'introduction',
  23. category: API_DOCS_CATEGORIES.INTRODUCTION,
  24. title: `Connect to your project`,
  25. description: `Projects have a RESTful endpoint that you can use with your project's API key to query and manage your database. Put these keys in your .env file.`,
  26. js: (_apikey?: string, endpoint?: string) => `
  27. import { createClient } from '@supabase/supabase-js'
  28. const brivenUrl = '${endpoint}'
  29. const brivenKey = process.env.BRIVEN_KEY
  30. const briven = createClient(brivenUrl, brivenKey)`,
  31. bash: () => `# No client library required for Bash.`,
  32. },
  33. clientApiKeys: {
  34. key: 'client-api-keys',
  35. category: API_DOCS_CATEGORIES.INTRODUCTION,
  36. title: `Client API Keys`,
  37. description: `Client keys allow "anonymous access" to your database, until the user has logged in. After logging in, the keys will switch to the user's own login token.
  38. In this documentation, we will refer to the key using the name \`BRIVEN_KEY\`. You can find the \`anon\` key in the [API settings](/project/[ref]/settings/api) page.`,
  39. js: (apikey?: string, endpoint?: string) => `
  40. const BRIVEN_KEY = '${apikey}'
  41. const BRIVEN_URL = '${endpoint}'
  42. const briven = createClient(BRIVEN_URL, process.env.BRIVEN_KEY);`,
  43. bash: (apikey?: string, _endpoint?: string) => `${apikey}`,
  44. },
  45. serviceApiKeys: {
  46. key: 'service-keys',
  47. category: API_DOCS_CATEGORIES.INTRODUCTION,
  48. title: `Service Keys`,
  49. description: `Service keys have *FULL* access to your data, bypassing any security policies. Be VERY careful where you expose these keys. They should only be used on a server and never on a client or browser.
  50. In this documentation, we refer to the key using the name \`SERVICE_KEY\`. You can find the \`service_role\` key above or in the [API settings](/project/[ref]/settings/api) page.`,
  51. js: (apikey?: string, endpoint?: string) => `
  52. const BRIVEN_KEY = '${apikey}'
  53. const BRIVEN_URL = 'https://${endpoint}'
  54. const briven = createClient(BRIVEN_URL, process.env.BRIVEN_KEY);`,
  55. bash: (apikey?: string, _endpoint?: string) => `${apikey}`,
  56. },
  57. // User Management
  58. userManagement: {
  59. key: 'user-management',
  60. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  61. title: `Introduction`,
  62. description: `Briven makes it easy to manage your users.
  63. Briven assigns each user a unique ID. You can reference this ID anywhere in your database. For example, you might create a \`profiles\` table references the user using a \`user_id\` field.
  64. Briven already has built in the routes to sign up, login, and log out for managing users in your apps and websites.`,
  65. js: undefined,
  66. bash: undefined,
  67. },
  68. signUp: {
  69. key: 'sign-up',
  70. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  71. title: `Sign up`,
  72. description: `Allow your users to sign up and create a new account
  73. After they have signed up, all interactions using the Briven client will be performed as "that user".`,
  74. js: (_apikey?: string, _endpoint?: string) => `
  75. const { data, error } = await briven.auth.signUp({
  76. email: 'someone@email.com',
  77. password: 'some-secure-password'
  78. })`,
  79. bash: (apikey?: string, endpoint?: string) => `
  80. curl -X POST '${endpoint}/auth/v1/signup' \\
  81. -H "apikey: ${apikey}" \\
  82. -H "Content-Type: application/json" \\
  83. -d '{
  84. "email": "someone@email.com",
  85. "password": "some-secure-password"
  86. }'`,
  87. },
  88. emailLogin: {
  89. key: 'email-login',
  90. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  91. title: `Log in with Email/Password`,
  92. description: `
  93. If an account is created, users can login to your app.
  94. After they have logged in, all interactions using the Briven JS client will be performed as "that user".`,
  95. js: (_apikey?: string, _endpoint?: string) => `
  96. const { data, error } = await briven.auth.signInWithPassword({
  97. email: 'someone@email.com',
  98. password: 'some-secure-password'
  99. })
  100. `,
  101. bash: (apikey?: string, endpoint?: string) => `
  102. curl -X POST '${endpoint}/auth/v1/token?grant_type=password' \\
  103. -H "apikey: ${apikey}" \\
  104. -H "Content-Type: application/json" \\
  105. -d '{
  106. "email": "someone@email.com",
  107. "password": "some-secure-password"
  108. }'
  109. `,
  110. },
  111. magicLinkLogin: {
  112. key: 'magic-link-login',
  113. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  114. title: `Log in with Magic Link via Email`,
  115. description: `
  116. Send a user a passwordless link which they can use to redeem an access_token.
  117. After they have clicked the link, all interactions using the Briven JS client will be performed as "that user".`,
  118. js: (_apikey?: string, _endpoint?: string) => `
  119. const { data, error } = await briven.auth.signInWithOtp({
  120. email: 'someone@email.com'
  121. })
  122. `,
  123. bash: (apikey?: string, endpoint?: string) => `
  124. curl -X POST '${endpoint}/auth/v1/magiclink' \\
  125. -H "apikey: ${apikey}" \\
  126. -H "Content-Type: application/json" \\
  127. -d '{
  128. "email": "someone@email.com"
  129. }'
  130. `,
  131. },
  132. phoneLogin: {
  133. key: 'phone-log-in',
  134. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  135. title: `Sign up with Phone/Password`,
  136. description: `
  137. A phone number can be used instead of an email as a primary account confirmation mechanism.
  138. The user will receive a mobile OTP via sms with which they can verify that they control the phone number.
  139. You must enter your own twilio credentials on the auth settings page to enable sms confirmations.`,
  140. js: (_apikey?: string, _endpoint?: string) => `
  141. const { data, error } = await briven.auth.signUp({
  142. phone: '+13334445555',
  143. password: 'some-password'
  144. })
  145. `,
  146. bash: (apikey?: string, endpoint?: string) => `
  147. curl -X POST '${endpoint}/auth/v1/signup' \\
  148. -H "apikey: ${apikey}" \\
  149. -H "Content-Type: application/json" \\
  150. -d '{
  151. "phone": "+13334445555",
  152. "password": "some-password"
  153. }'
  154. `,
  155. },
  156. smsLogin: {
  157. key: 'sms-otp-log-in',
  158. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  159. title: `Login via SMS OTP`,
  160. description: `
  161. SMS OTPs work like magic links, except you have to provide an interface for the user to verify the 6 digit number they receive.
  162. You must enter your own twilio credentials on the auth settings page to enable SMS-based Logins.`,
  163. js: (_apikey?: string, _endpoint?: string) => `
  164. const { data, error } = await briven.auth.signInWithOtp({
  165. phone: '+13334445555'
  166. })
  167. `,
  168. bash: (apikey?: string, endpoint?: string) => `
  169. curl -X POST '${endpoint}/auth/v1/otp' \\
  170. -H "apikey: ${apikey}" \\
  171. -H "Content-Type: application/json" \\
  172. -d '{
  173. "phone": "+13334445555"
  174. }'
  175. `,
  176. },
  177. smsVerify: {
  178. key: 'sms-verify',
  179. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  180. title: `Verify an SMS OTP`,
  181. description: `
  182. Once the user has received the OTP, have them enter it in a form and send it for verification
  183. You must enter your own twilio credentials on the auth settings page to enable SMS-based OTP verification.`,
  184. js: (_apikey?: string, _endpoint?: string) => `
  185. const { data, error } = await briven.auth.verifyOtp({
  186. phone: '+13334445555',
  187. token: '123456',
  188. type: 'sms'
  189. })
  190. `,
  191. bash: (apikey?: string, endpoint?: string) => `
  192. curl -X POST '${endpoint}/auth/v1/verify' \\
  193. -H "apikey: ${apikey}" \\
  194. -H "Content-Type: application/json" \\
  195. -d '{
  196. "type": "sms",
  197. "phone": "+13334445555",
  198. "token": "123456"
  199. }'
  200. `,
  201. },
  202. oauthLogin: {
  203. key: 'oauth-login',
  204. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  205. title: `Log in with Third Party OAuth`,
  206. description: `
  207. Users can log in with Third Party OAuth like Google, Facebook, GitHub, and more. You must first enable each of these in the Auth Providers settings [here](https://supabase.com).
  208. View all the available [Third Party OAuth providers](https://supabase.com).
  209. After they have logged in, all interactions using the Briven JS client will be performed as "that user".
  210. Generate your Client ID and secret from: [Google](https://console.developers.google.com/apis/credentials), [Github](https://github.com/settings/applications/new), [Gitlab](https://gitlab.com/oauth/applications), [Facebook](https://developers.facebook.com/apps), and [Bitbucket](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud).`,
  211. js: (_apikey?: string, _endpoint?: string) => `
  212. const { data, error } = await briven.auth.signInWithOAuth({
  213. provider: 'github'
  214. })
  215. `,
  216. bash: (_apikey?: string, _endpoint?: string) => `No available command`,
  217. },
  218. user: {
  219. key: 'get-user',
  220. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  221. title: `Get user`,
  222. description: `Get the JSON object for the logged in user.`,
  223. js: (_apikey?: string, _endpoint?: string) => `
  224. const { data: { user } } = await briven.auth.getUser()
  225. `,
  226. bash: (apikey?: string, endpoint?: string) => `
  227. curl -X GET '${endpoint}/auth/v1/user' \\
  228. -H "apikey: ${apikey}" \\
  229. -H "Authorization: Bearer USER_TOKEN"
  230. `,
  231. },
  232. forgotPassWordEmail: {
  233. key: 'forgot-password-email',
  234. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  235. title: `Forgot password / email`,
  236. description: `Sends the user a log in link via email. Once logged in you should direct the user to a new password form. And use "Update User" below to save the new password.`,
  237. js: (_apikey?: string, _endpoint?: string) => `
  238. const { data, error } = await briven.auth.resetPasswordForEmail(email)
  239. `,
  240. bash: (apikey?: string, endpoint?: string) => `
  241. curl -X POST '${endpoint}/auth/v1/recover' \\
  242. -H "apikey: ${apikey}" \\
  243. -H "Content-Type: application/json" \\
  244. -d '{
  245. "email": "someone@email.com"
  246. }'
  247. `,
  248. },
  249. updateUser: {
  250. key: 'update-user',
  251. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  252. title: `Update User`,
  253. description: `Update the user with a new email or password. Each key (email, password, and data) is optional.`,
  254. js: (_apikey?: string, _endpoint?: string) => `
  255. const { data, error } = await briven.auth.updateUser({
  256. email: "new@email.com",
  257. password: "new-password",
  258. data: { hello: 'world' }
  259. })
  260. `,
  261. bash: (apikey?: string, endpoint?: string) => `
  262. curl -X PUT '${endpoint}/auth/v1/user' \\
  263. -H "apikey: ${apikey}" \\
  264. -H "Authorization: Bearer <USERS-ACCESS-TOKEN>" \\
  265. -H "Content-Type: application/json" \\
  266. -d '{
  267. "email": "someone@email.com",
  268. "password": "new-password",
  269. "data": {
  270. "key": "value"
  271. }
  272. }'
  273. `,
  274. },
  275. logout: {
  276. key: 'log-out',
  277. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  278. title: `Log out`,
  279. description: `After calling log out, all interactions using the Briven JS client will be "anonymous".`,
  280. js: (_apikey?: string, _endpoint?: string) => `
  281. const { error } = await briven.auth.signOut()
  282. `,
  283. bash: (apikey?: string, endpoint?: string) => `
  284. curl -X POST '${endpoint}/auth/v1/logout' \\
  285. -H "apikey: ${apikey}" \\
  286. -H "Content-Type: application/json" \\
  287. -H "Authorization: Bearer USER_TOKEN"
  288. `,
  289. },
  290. emailInvite: {
  291. key: 'email-invite',
  292. category: API_DOCS_CATEGORIES.USER_MANAGEMENT,
  293. title: `Invite user over email`,
  294. description: `
  295. Send a user a passwordless link which they can use to sign up and log in.
  296. After they have clicked the link, all interactions using the Briven JS client will be performed as "that user".
  297. This endpoint requires you use the \`service_role_key\` when initializing the client, and should only be invoked from the server, never from the client.`,
  298. js: (_apikey?: string, _endpoint?: string) => `
  299. const { data, error } = await briven.auth.api.inviteUserByEmail('someone@email.com')
  300. `,
  301. bash: (apikey?: string, endpoint?: string) => `
  302. curl -X POST '${endpoint}/auth/v1/invite' \\
  303. -H "apikey: ${apikey}" \\
  304. -H "Authorization: Bearer ${apikey}" \\
  305. -H "Content-Type: application/json" \\
  306. -d '{
  307. "email": "someone@email.com"
  308. }'
  309. `,
  310. },
  311. // Storage
  312. storage: {
  313. key: 'storage',
  314. category: API_DOCS_CATEGORIES.STORAGE,
  315. title: `Introduction`,
  316. description: `Briven Storage makes it simple to upload and serve files of any size, providing a robust framework for file access controls.
  317. You can use Briven Storage to store images, videos, documents, and any other file type. Serve your assets with a global CDN to reduce latency from over 285 cities globally. Briven Storage includes a built-in image optimizer, so you can resize and compress your media files on the fly.`,
  318. js: undefined,
  319. bash: undefined,
  320. },
  321. // Edge functions
  322. edgeFunctions: {
  323. key: 'edge-function',
  324. category: API_DOCS_CATEGORIES.EDGE_FUNCTIONS,
  325. title: 'Introduction',
  326. description: `
  327. Edge Functions are server-side TypeScript functions, distributed globally at the edge—close to your users. They can be used for listening to webhooks or integrating your Briven project with third-parties like Stripe. Edge Functions are developed using Deno, which offers a few benefits to you as a developer:
  328. `,
  329. js: undefined,
  330. bash: undefined,
  331. },
  332. edgeFunctionsPreReq: {
  333. key: 'edge-function-pre-req',
  334. category: API_DOCS_CATEGORIES.EDGE_FUNCTIONS,
  335. title: 'Pre-requisites',
  336. description: `
  337. Follow the steps to prepare your Briven project on your local machine.
  338. - Install the Briven [CLI](${DOCS_URL}/guides/cli).
  339. - [Login to the CLI](${DOCS_URL}/reference/cli/usage#briven-login) using the command: \`briven login\`..
  340. - [Initialize Briven](${DOCS_URL}/guides/getting-started/local-development#getting-started) inside your project using the command: \`briven init\`..
  341. - [Link to your Remote Project](${DOCS_URL}/reference/cli/usage#briven-link) using the command \`briven link --project-ref [ref]\`..
  342. - Setup your environment: Follow the steps [here](${DOCS_URL}/guides/functions/quickstart#setting-up-your-environment).
  343. `,
  344. js: undefined,
  345. bash: undefined,
  346. },
  347. createEdgeFunction: {
  348. key: 'create-edge-function',
  349. category: API_DOCS_CATEGORIES.EDGE_FUNCTIONS,
  350. title: 'Create an Edge Function',
  351. description: `
  352. Create a Briven Edge Function locally via the Briven CLI.
  353. `,
  354. js: () => `// Create an edge function via the Briven CLI`,
  355. bash: () => `
  356. briven functions new hello-world
  357. `,
  358. },
  359. deployEdgeFunction: {
  360. key: 'deploy-edge-function',
  361. category: API_DOCS_CATEGORIES.EDGE_FUNCTIONS,
  362. title: 'Deploy an Edge Function',
  363. description: `
  364. Deploy a Briven Edge Function to your Briven project via the Briven CLI.
  365. `,
  366. js: () => `// Deploy an edge function via the Briven CLI`,
  367. bash: () => `briven functions deploy hello-world --project-ref [ref]
  368. `,
  369. },
  370. // Entities
  371. entitiesIntroduction: {
  372. key: 'entities-introduction',
  373. category: API_DOCS_CATEGORIES.ENTITIES,
  374. title: 'Introduction',
  375. description: `
  376. All views and tables in the \`public\` schema, and those accessible by the active database role for a request are available for querying via the API.
  377. If you don't want to expose tables in your API, simply add them to a different schema (not the \`public\` schema).
  378. `,
  379. js: undefined,
  380. bash: undefined,
  381. },
  382. generatingTypes: {
  383. key: 'generating-types',
  384. category: API_DOCS_CATEGORIES.ENTITIES,
  385. title: 'Generating Types',
  386. description: `
  387. Briven APIs are generated from your database, which means that we can use database introspection to generate type-safe API definitions.
  388. You can generate types from your database either through the [Briven CLI](${DOCS_URL}/guides/database/api/generating-types), or by downloading the types file via the button on the right and importing it in your application within \`src/index.ts\`.
  389. `,
  390. js: undefined,
  391. bash: undefined,
  392. },
  393. graphql: {
  394. key: 'graphql',
  395. category: API_DOCS_CATEGORIES.ENTITIES,
  396. title: 'GraphQL vs PostgREST',
  397. description: `
  398. If you have a GraphQL background, you might be wondering if you can fetch your data in a single round-trip. The answer is yes! The syntax is very similar. This example shows how you might achieve the same thing with Apollo GraphQL and Briven.
  399. Still want GraphQL?
  400. If you still want to use GraphQL, you can. Briven provides you with a full Postgres database, so as long as your middleware can connect to the database then you can still use the tools you love. You can find the database connection details [in the settings](/project/[ref]/database/settings).
  401. `,
  402. js: (_apikey?: string, _endpoint?: string) => `
  403. // With Apollo GraphQL
  404. const { loading, error, data } = useQuery(gql\`
  405. query GetDogs {
  406. dogs {
  407. id
  408. breed
  409. owner {
  410. id
  411. name
  412. }
  413. }
  414. }
  415. \`)
  416. // With Briven
  417. const { data, error } = await briven
  418. .from('dogs')
  419. .select(\`
  420. id, breed,
  421. owner (id, name)
  422. \`)
  423. `,
  424. bash: (_apikey?: string, _endpoint?: string) => `
  425. // With Apollo GraphQL
  426. const { loading, error, data } = useQuery(gql\`
  427. query GetDogs {
  428. dogs {
  429. id
  430. breed
  431. owner {
  432. id
  433. name
  434. }
  435. }
  436. }
  437. \`)
  438. // With Briven
  439. const { data, error } = await briven
  440. .from('dogs')
  441. .select(\`
  442. id, breed,
  443. owner (id, name)
  444. \`)
  445. `,
  446. },
  447. // Database Functions
  448. storedProceduresIntroduction: {
  449. key: 'stored-procedures-introduction',
  450. category: API_DOCS_CATEGORIES.STORED_PROCEDURES,
  451. title: 'Introduction',
  452. description: `
  453. All of your database functions are available on your API. This means you can build your logic directly into the database (if you're brave enough)!
  454. The API endpoint supports POST (and in some cases GET) to execute the function.
  455. `,
  456. js: undefined,
  457. bash: undefined,
  458. },
  459. // Realtime
  460. realtime: {
  461. key: 'realtime-introduction',
  462. category: API_DOCS_CATEGORIES.REALTIME,
  463. title: 'Introduction',
  464. description: `
  465. Briven provides a globally distributed cluster of Realtime servers that enable the following functionality:
  466. - [Broadcast](${DOCS_URL}/guides/realtime/broadcast): Send ephemeral messages from client to clients with low latency.
  467. - [Presence](${DOCS_URL}/guides/realtime/presence): Track and synchronize shared state between clients.
  468. - [Postgres Changes](${DOCS_URL}/guides/realtime/postgres-changes): Listen to Postgres database changes and send them to authorized clients.
  469. `,
  470. js: undefined,
  471. bash: undefined,
  472. },
  473. subscribeChannel: {
  474. key: 'subscribe-to-channel',
  475. category: API_DOCS_CATEGORIES.REALTIME,
  476. title: 'Subscribe to channel',
  477. description: `
  478. Creates an event handler that listens to changes.
  479. - By default, Broadcast and Presence are enabled for all projects.
  480. - By default, listening to database changes is disabled for new projects due to database performance and security concerns. You can turn it on by managing Realtime's [replication](${DOCS_URL}/guides/api#realtime-api-overview).
  481. - You can receive the "previous" data for updates and deletes by setting the table's \`REPLICA IDENTITY\` to \`FULL\` (e.g., \`ALTER TABLE your_table REPLICA IDENTITY FULL;\`).
  482. - Row level security is not applied to delete statements. When RLS is enabled and replica identity is set to full, only the primary key is sent to clients.
  483. `,
  484. js: () => `
  485. briven
  486. .channel('any')
  487. .on('broadcast', { event: 'cursor-pos' }, payload => {
  488. console.log('Cursor position received!', payload)
  489. })
  490. .subscribe((status) => {
  491. if (status === 'SUBSCRIBED') {
  492. channel.send({
  493. type: 'broadcast',
  494. event: 'cursor-pos',
  495. payload: { x: Math.random(), y: Math.random() },
  496. })
  497. }
  498. })
  499. `,
  500. bash: () => `# Realtime streams are only supported by our client libraries`,
  501. },
  502. unsubscribeChannel: {
  503. key: 'unsubscribe-channel',
  504. category: API_DOCS_CATEGORIES.REALTIME,
  505. title: 'Unsubscribe from a channel',
  506. description: `
  507. Unsubscribes and removes Realtime channel from Realtime client.
  508. Removing a channel is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Briven will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed.
  509. `,
  510. js: () => `briven.removeChannel(myChannel)`,
  511. bash: () => `# Realtime streams are only supported by our client libraries`,
  512. },
  513. unsubscribeChannels: {
  514. key: 'unsubscribe-channels',
  515. category: API_DOCS_CATEGORIES.REALTIME,
  516. title: 'Unsubscribe from all channels',
  517. description: `
  518. Unsubscribes and removes all Realtime channels from Realtime client.
  519. Removing a channel is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Briven will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed.
  520. `,
  521. js: () => `briven.removeChannels()`,
  522. bash: () => `# Realtime streams are only supported by our client libraries`,
  523. },
  524. retrieveAllChannels: {
  525. key: 'unsubscribe-channel',
  526. category: API_DOCS_CATEGORIES.REALTIME,
  527. title: 'Unsubscribe from a channel',
  528. description: `
  529. Returns all Realtime channels.
  530. `,
  531. js: () => `const channels = briven.getChannels()`,
  532. bash: () => `# Realtime streams are only supported by our client libraries`,
  533. },
  534. }
  535. export const DOCS_RESOURCE_CONTENT: {
  536. [key: string]: {
  537. key: string
  538. title: string
  539. category: string
  540. description?: string
  541. docsUrl: string
  542. code: (props: any) => { key: string; title?: string; bash: string; js: string }[]
  543. }
  544. } = {
  545. rpcSingle: {
  546. key: 'invoke-function',
  547. title: 'Invoke function',
  548. category: API_DOCS_CATEGORIES.STORED_PROCEDURES,
  549. description: undefined,
  550. docsUrl: `${DOCS_URL}/reference/javascript/rpc`,
  551. code: ({
  552. rpcName,
  553. rpcParams,
  554. endpoint,
  555. apiKey,
  556. showBearer = true,
  557. }: {
  558. rpcName: string
  559. rpcParams: any[]
  560. endpoint: string
  561. apiKey: string
  562. showBearer: boolean
  563. }) => {
  564. let rpcList = rpcParams.map((x) => `"${x.name}": "value"`).join(', ')
  565. let noParams = !rpcParams.length
  566. let bashParams = noParams ? '' : `\n-d '{ ${rpcList} }' \\`
  567. let jsParams = noParams
  568. ? ''
  569. : `, {${
  570. rpcParams.length
  571. ? rpcParams
  572. .map((x) => `\n ${x.name}`)
  573. .join(`, `)
  574. .concat('\n ')
  575. : ''
  576. }}`
  577. return [
  578. {
  579. key: 'rpc-single',
  580. title: undefined,
  581. bash: `
  582. curl -X POST '${endpoint}/rest/v1/rpc/${rpcName}' \\${bashParams}
  583. -H "Content-Type: application/json" \\
  584. -H "apikey: ${apiKey}" ${
  585. showBearer
  586. ? `\\
  587. -H "Authorization: Bearer ${apiKey}"`
  588. : ''
  589. }
  590. `,
  591. js: `
  592. let { data, error } = await briven
  593. .rpc('${rpcName}'${jsParams})
  594. if (error) console.error(error)
  595. else console.log(data)
  596. `,
  597. },
  598. ]
  599. },
  600. },
  601. readRows: {
  602. key: 'read-rows',
  603. title: `Read rows`,
  604. category: API_DOCS_CATEGORIES.ENTITIES,
  605. docsUrl: `${DOCS_URL}/reference/javascript/select`,
  606. description: `To read rows in this table, use the \`select\` method.`,
  607. code: ({
  608. resourceId,
  609. endpoint,
  610. apikey,
  611. }: {
  612. resourceId: string
  613. endpoint: string
  614. apikey: string
  615. }) => {
  616. return [
  617. {
  618. key: 'read-all-rows',
  619. title: 'Read all rows',
  620. bash: `
  621. curl '${endpoint}/rest/v1/${resourceId}?select=*' \\
  622. -H "apikey: ${apikey}" \\
  623. -H "Authorization: Bearer ${apikey}"
  624. `,
  625. js: `
  626. let { data: ${resourceId}, error } = await briven
  627. .from('${resourceId}')
  628. .select('*')
  629. `,
  630. },
  631. {
  632. key: 'read-specific-columns',
  633. title: 'Read specific columns',
  634. bash: `
  635. curl '${endpoint}/rest/v1/${resourceId}?select=some_column,other_column' \\
  636. -H "apikey: ${apikey}" \\
  637. -H "Authorization: Bearer ${apikey}"
  638. `,
  639. js: `
  640. let { data: ${resourceId}, error } = await briven
  641. .from('${resourceId}')
  642. .select('some_column,other_column')
  643. `,
  644. },
  645. {
  646. key: 'read-foreign-tables',
  647. title: 'Read referenced tables',
  648. bash: `
  649. curl '${endpoint}/rest/v1/${resourceId}?select=some_column,other_table(foreign_key)' \\
  650. -H "apikey: ${apikey}" \\
  651. -H "Authorization: Bearer ${apikey}"
  652. `,
  653. js: `
  654. let { data: ${resourceId}, error } = await briven
  655. .from('${resourceId}')
  656. .select(\`
  657. some_column,
  658. other_table (
  659. foreign_key
  660. )
  661. \`)
  662. `,
  663. },
  664. {
  665. key: 'with-pagination',
  666. title: 'With pagination',
  667. bash: `
  668. curl '${endpoint}/rest/v1/${resourceId}?select=*' \\
  669. -H "apikey: ${apikey}" \\
  670. -H "Authorization: Bearer ${apikey}" \\
  671. -H "Range: 0-9"
  672. `,
  673. js: `
  674. let { data: ${resourceId}, error } = await briven
  675. .from('${resourceId}')
  676. .select('*')
  677. .range(0, 9)
  678. `,
  679. },
  680. ]
  681. },
  682. },
  683. filtering: {
  684. key: 'filter-rows',
  685. category: API_DOCS_CATEGORIES.ENTITIES,
  686. title: 'Filtering',
  687. description: `Briven provides a wide range of filters`,
  688. docsUrl: `${DOCS_URL}/reference/javascript/using-filters`,
  689. code: ({
  690. resourceId,
  691. endpoint,
  692. apikey,
  693. }: {
  694. resourceId: string
  695. endpoint: string
  696. apikey: string
  697. }) => {
  698. return [
  699. {
  700. key: 'with-filtering',
  701. title: 'With filtering',
  702. bash: `
  703. curl --get '${endpoint}/rest/v1/${resourceId}' \\
  704. -H "apikey: ${apikey}" \\
  705. -H "Authorization: Bearer ${apikey}" \\
  706. -H "Range: 0-9" \\
  707. -d "select=*" \\
  708. \\
  709. \`# Filters\` \\
  710. -d "column=eq.Equal+to" \\
  711. -d "column=gt.Greater+than" \\
  712. -d "column=lt.Less+than" \\
  713. -d "column=gte.Greater+than+or+equal+to" \\
  714. -d "column=lte.Less+than+or+equal+to" \\
  715. -d "column=like.*CaseSensitive*" \\
  716. -d "column=ilike.*CaseInsensitive*" \\
  717. -d "column=is.null" \\
  718. -d "column=in.(Array,Values)" \\
  719. -d "column=neq.Not+equal+to" \\
  720. \\
  721. \`# Arrays\` \\
  722. -d "array_column=cs.{array,contains}" \\
  723. -d "array_column=cd.{contained,by}" \\
  724. \\
  725. \`# Logical operators\` \\
  726. -d "column=not.like.Negate+filter" \\
  727. -d "or=(some_column.eq.Some+value,other_column.eq.Other+value)"
  728. `,
  729. js: `
  730. let { data: ${resourceId}, error } = await briven
  731. .from('${resourceId}')
  732. .select("*")
  733. // Filters
  734. .eq('column', 'Equal to')
  735. .gt('column', 'Greater than')
  736. .lt('column', 'Less than')
  737. .gte('column', 'Greater than or equal to')
  738. .lte('column', 'Less than or equal to')
  739. .like('column', '%CaseSensitive%')
  740. .ilike('column', '%CaseInsensitive%')
  741. .is('column', null)
  742. .in('column', ['Array', 'Values'])
  743. .neq('column', 'Not equal to')
  744. // Arrays
  745. .contains('array_column', ['array', 'contains'])
  746. .containedBy('array_column', ['contained', 'by'])
  747. // Logical operators
  748. .not('column', 'like', 'Negate filter')
  749. .or('some_column.eq.Some value, other_column.eq.Other value')
  750. `,
  751. },
  752. ]
  753. },
  754. },
  755. insertRows: {
  756. key: 'insert-rows',
  757. category: API_DOCS_CATEGORIES.ENTITIES,
  758. title: 'Insert rows',
  759. description: `
  760. \`insert\` lets you insert into your tables. You can also insert in bulk and do UPSERT.
  761. \`insert\` will also return the replaced values for UPSERT.
  762. `,
  763. docsUrl: `${DOCS_URL}/reference/javascript/insert`,
  764. code: ({
  765. resourceId,
  766. endpoint,
  767. apikey,
  768. }: {
  769. resourceId: string
  770. endpoint: string
  771. apikey: string
  772. }) => {
  773. return [
  774. {
  775. key: 'insert-a-row',
  776. title: 'Insert a row',
  777. bash: `
  778. curl -X POST '${endpoint}/rest/v1/${resourceId}' \\
  779. -H "apikey: ${apikey}" \\
  780. -H "Authorization: Bearer ${apikey}" \\
  781. -H "Content-Type: application/json" \\
  782. -H "Prefer: return=minimal" \\
  783. -d '{ "some_column": "someValue", "other_column": "otherValue" }'
  784. `,
  785. js: `
  786. const { data, error } = await briven
  787. .from('${resourceId}')
  788. .insert([
  789. { some_column: 'someValue', other_column: 'otherValue' },
  790. ])
  791. .select()
  792. `,
  793. },
  794. {
  795. key: 'insert-many-rows',
  796. title: 'Insert many rows',
  797. bash: `
  798. curl -X POST '${endpoint}/rest/v1/${resourceId}' \\
  799. -H "apikey: ${apikey}" \\
  800. -H "Authorization: Bearer ${apikey}" \\
  801. -H "Content-Type: application/json" \\
  802. -d '[{ "some_column": "someValue" }, { "other_column": "otherValue" }]'
  803. `,
  804. js: `
  805. const { data, error } = await briven
  806. .from('${resourceId}')
  807. .insert([
  808. { some_column: 'someValue' },
  809. { some_column: 'otherValue' },
  810. ])
  811. .select()
  812. `,
  813. },
  814. {
  815. key: 'upsert-matching-rows',
  816. title: 'Upsert matching rows',
  817. bash: `
  818. curl -X POST '${endpoint}/rest/v1/${resourceId}' \\
  819. -H "apikey: ${apikey}" \\
  820. -H "Authorization: Bearer ${apikey}" \\
  821. -H "Content-Type: application/json" \\
  822. -H "Prefer: resolution=merge-duplicates" \\
  823. -d '{ "some_column": "someValue", "other_column": "otherValue" }'
  824. `,
  825. js: `
  826. const { data, error } = await briven
  827. .from('${resourceId}')
  828. .upsert({ some_column: 'someValue' })
  829. .select()
  830. `,
  831. },
  832. ]
  833. },
  834. },
  835. updateRows: {
  836. key: 'update-rows',
  837. category: API_DOCS_CATEGORIES.ENTITIES,
  838. title: 'Update rows',
  839. description: `
  840. \`update\` lets you update rows. \`update\` will match all rows by default. You can update specific rows using horizontal filters, e.g. \`eq\`, \`lt\`, and \`is\`.
  841. \`update\` will also return the replaced values for UPDATE.
  842. `,
  843. docsUrl: `${DOCS_URL}/reference/javascript/update`,
  844. code: ({
  845. resourceId,
  846. endpoint,
  847. apikey,
  848. }: {
  849. resourceId: string
  850. endpoint: string
  851. apikey: string
  852. }) => {
  853. return [
  854. {
  855. key: 'update-matching-rows',
  856. title: 'Update matching rows',
  857. bash: `
  858. curl -X PATCH '${endpoint}/rest/v1/${resourceId}?some_column=eq.someValue' \\
  859. -H "apikey: ${apikey}" \\
  860. -H "Authorization: Bearer ${apikey}" \\
  861. -H "Content-Type: application/json" \\
  862. -H "Prefer: return=minimal" \\
  863. -d '{ "other_column": "otherValue" }'
  864. `,
  865. js: `
  866. const { data, error } = await briven
  867. .from('${resourceId}')
  868. .update({ other_column: 'otherValue' })
  869. .eq('some_column', 'someValue')
  870. .select()
  871. `,
  872. },
  873. ]
  874. },
  875. },
  876. deleteRows: {
  877. key: 'delete-rows',
  878. category: API_DOCS_CATEGORIES.ENTITIES,
  879. title: 'Delete rows',
  880. description: `
  881. \`delete\` lets you delete rows. \`delete\` will match all rows by default, so remember to specify your filters!
  882. `,
  883. docsUrl: `${DOCS_URL}/reference/javascript/delete`,
  884. code: ({
  885. resourceId,
  886. endpoint,
  887. apikey,
  888. }: {
  889. resourceId: string
  890. endpoint: string
  891. apikey: string
  892. }) => {
  893. return [
  894. {
  895. key: 'delete-matching-rows',
  896. title: 'Delete matching rows',
  897. bash: `
  898. curl -X DELETE '${endpoint}/rest/v1/${resourceId}?some_column=eq.someValue' \\
  899. -H "apikey: ${apikey}" \\
  900. -H "Authorization: Bearer ${apikey}"
  901. `,
  902. js: `
  903. const { error } = await briven
  904. .from('${resourceId}')
  905. .delete()
  906. .eq('some_column', 'someValue')
  907. `,
  908. },
  909. ]
  910. },
  911. },
  912. subscribeChanges: {
  913. key: 'subscribe-changes',
  914. category: API_DOCS_CATEGORIES.ENTITIES,
  915. title: 'Subscribe to changes',
  916. description: `
  917. Briven provides realtime functionality and broadcasts database changes to authorized users depending on Row Level Security (RLS) policies.
  918. `,
  919. docsUrl: `${DOCS_URL}/reference/javascript/subscribe`,
  920. code: ({ resourceId }: { resourceId: string }) => {
  921. return [
  922. {
  923. key: 'subscribe-all-events',
  924. title: 'Subscribe to all events',
  925. bash: `# Realtime streams are only supported by our client libraries`,
  926. js: `
  927. const channels = briven.channel('custom-all-channel')
  928. .on(
  929. 'postgres_changes',
  930. { event: '*', schema: 'public', table: '${resourceId}' },
  931. (payload) => {
  932. console.log('Change received!', payload)
  933. }
  934. )
  935. .subscribe()`,
  936. },
  937. {
  938. key: 'subscribe-to-inserts',
  939. title: 'Subscribe to inserts',
  940. bash: `# Realtime streams are only supported by our client libraries`,
  941. js: `
  942. const channels = briven.channel('custom-insert-channel')
  943. .on(
  944. 'postgres_changes',
  945. { event: 'INSERT', schema: 'public', table: '${resourceId}' },
  946. (payload) => {
  947. console.log('Change received!', payload)
  948. }
  949. )
  950. .subscribe()`,
  951. },
  952. {
  953. key: 'subscribe-to-updates',
  954. title: 'Subscribe to updates',
  955. bash: `# Realtime streams are only supported by our client libraries`,
  956. js: `
  957. const channels = briven.channel('custom-update-channel')
  958. .on(
  959. 'postgres_changes',
  960. { event: 'UPDATE', schema: 'public', table: '${resourceId}' },
  961. (payload) => {
  962. console.log('Change received!', payload)
  963. }
  964. )
  965. .subscribe()`,
  966. },
  967. {
  968. key: 'subscribe-to-deletes',
  969. title: 'Subscribe to deletes',
  970. bash: `# Realtime streams are only supported by our client libraries`,
  971. js: `
  972. const channels = briven.channel('custom-delete-channel')
  973. .on(
  974. 'postgres_changes',
  975. { event: 'DELETE', schema: 'public', table: '${resourceId}' },
  976. (payload) => {
  977. console.log('Change received!', payload)
  978. }
  979. )
  980. .subscribe()`,
  981. },
  982. {
  983. key: 'subscribe-to-specific-rows',
  984. title: 'Subscribe to specific rows',
  985. bash: `# Realtime streams are only supported by our client libraries`,
  986. js: `
  987. const channels = briven.channel('custom-filter-channel')
  988. .on(
  989. 'postgres_changes',
  990. { event: '*', schema: 'public', table: '${resourceId}', filter: 'some_column=eq.some_value' },
  991. (payload) => {
  992. console.log('Change received!', payload)
  993. }
  994. )
  995. .subscribe()`,
  996. },
  997. ]
  998. },
  999. },
  1000. uploadFile: {
  1001. key: 'upload-file',
  1002. category: API_DOCS_CATEGORIES.STORAGE,
  1003. title: 'Upload a file',
  1004. docsUrl: `${DOCS_URL}/reference/javascript/storage-from-upload`,
  1005. description: `
  1006. Upload a file to an existing bucket. RLS policy permissions required:
  1007. - \`buckets\` table permissions: none
  1008. - \`objects\` table permissions: only \`insert\` when you are uploading new files and \`select\`, \`insert\`, and \`update\` when you are upserting files.
  1009. `,
  1010. code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
  1011. {
  1012. key: 'storage-upload-file',
  1013. title: undefined,
  1014. bash: `
  1015. curl -X POST '${endpoint}/storage/v1/object/${name}/folder/avatar1.png' \\
  1016. -H 'Content-Type: image/png' \\
  1017. -H "Authorization: Bearer ${apikey}" \\
  1018. --data-binary @/path/to/your/file'
  1019. -H 'Content-Type: multipart/form-data' \\
  1020. -H "Authorization: Bearer ${apikey}" \\
  1021. --data-raw $'your_file_data'
  1022. `,
  1023. js: `
  1024. const avatarFile = event.target.files[0]
  1025. const { data, error } = await briven
  1026. .storage
  1027. .from('${name}')
  1028. .upload('folder/avatar1.png', avatarFile, {
  1029. cacheControl: '3600',
  1030. upsert: false
  1031. })
  1032. `,
  1033. },
  1034. ],
  1035. },
  1036. deleteFiles: {
  1037. key: 'delete-files',
  1038. category: API_DOCS_CATEGORIES.STORAGE,
  1039. title: 'Delete files',
  1040. docsUrl: `${DOCS_URL}/reference/javascript/storage-from-remove`,
  1041. description: `
  1042. Delete files within the bucket. RLS policy permissions required:
  1043. - \`buckets\` table permissions: none
  1044. - \`objects\` table permissions: \`delete\` and \`select\`
  1045. `,
  1046. code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
  1047. {
  1048. key: 'storage-delete-files',
  1049. title: undefined,
  1050. bash: `
  1051. curl -X DELETE '${endpoint}/storage/v1/object/${name}' \\
  1052. -H "Content-Type: application/json" \\
  1053. -H "Authorization: Bearer ${apikey}" \\
  1054. -d '{ "prefixes": ["file_name", "another_file_name"] }'
  1055. `,
  1056. js: `
  1057. const { data, error } = await briven
  1058. .storage
  1059. .from('${name}')
  1060. .remove(['folder/avatar1.png'])
  1061. `,
  1062. },
  1063. ],
  1064. },
  1065. listFiles: {
  1066. key: 'list-files',
  1067. category: API_DOCS_CATEGORIES.STORAGE,
  1068. title: 'List all files',
  1069. docsUrl: `${DOCS_URL}/reference/javascript/storage-from-list`,
  1070. description: `
  1071. List all files within the bucket. RLS policy permissions required:
  1072. - \`buckets\` table permissions: none
  1073. - \`objects\` table permissions: \`select\`
  1074. `,
  1075. code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
  1076. {
  1077. key: 'storage-list-files',
  1078. title: undefined,
  1079. bash: `
  1080. curl -X POST '${endpoint}/storage/v1/object/list/${name}' \\
  1081. -H "Content-Type: application/json" \\
  1082. -H "Authorization: Bearer ${apikey}" \\
  1083. -d '{ "limit": 100, "offset": 0, "prefix": "", "sortBy": { "column": "name", "order": "asc" } }'`,
  1084. js: `
  1085. const { data, error } = await briven
  1086. .storage
  1087. .from('${name}')
  1088. .list('folder', {
  1089. limit: 100,
  1090. offset: 0,
  1091. sortBy: { column: 'name', order: 'asc' },
  1092. })
  1093. `,
  1094. },
  1095. ],
  1096. },
  1097. downloadFile: {
  1098. key: 'download-file',
  1099. category: API_DOCS_CATEGORIES.STORAGE,
  1100. title: 'Download a file',
  1101. docsUrl: `${DOCS_URL}/reference/javascript/storage-from-download`,
  1102. description: `
  1103. Downloads a file from a private bucket. For public buckets, make a request to the URL returned from getPublicUrl instead. RLS policy permissions required:
  1104. - \`buckets\` table permissions: none
  1105. - \`objects\` table permissions: \`select\`
  1106. `,
  1107. code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
  1108. {
  1109. key: 'storage-download-file',
  1110. title: undefined,
  1111. bash: `
  1112. curl -X GET '${endpoint}/storage/v1/object/${name}/folder/avatar1.png' \\
  1113. -H "Content-Type: application/json" \\
  1114. -H "Authorization: Bearer ${apikey}" \\
  1115. --output avatar1.png
  1116. `,
  1117. js: `
  1118. const { data, error } = await briven
  1119. .storage
  1120. .from('${name}')
  1121. .download('folder/avatar1.png')
  1122. `,
  1123. },
  1124. ],
  1125. },
  1126. createSignedURL: {
  1127. key: 'create-signed-url',
  1128. category: API_DOCS_CATEGORIES.STORAGE,
  1129. title: 'Create a signed URL',
  1130. docsUrl: `${DOCS_URL}/reference/javascript/storage-from-createsignedurl`,
  1131. description: `
  1132. Create a signed URL which can be used to share a file for a fixed amount of time. RLS policy permissions required:
  1133. - \`buckets\` table permissions: none
  1134. - \`objects\` table permissions: \`select\`
  1135. `,
  1136. code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
  1137. {
  1138. key: 'storage-create-signed-url',
  1139. title: undefined,
  1140. bash: `
  1141. curl -X POST '${endpoint}/storage/v1/object/sign/${name}/folder/avatar1.png' \\
  1142. -H "Content-Type: application/json" \\
  1143. -H "Authorization: Bearer ${apikey}" \\
  1144. -d '{ "expiresIn": 60 }'
  1145. `,
  1146. js: `
  1147. const { data, error } = await briven
  1148. .storage
  1149. .from('${name}')
  1150. .createSignedUrl('folder/avatar1.png', 60)
  1151. `,
  1152. },
  1153. ],
  1154. },
  1155. retrievePublicURL: {
  1156. key: 'retrieve-public-url',
  1157. category: API_DOCS_CATEGORIES.STORAGE,
  1158. title: 'Retrieve public URL',
  1159. docsUrl: `${DOCS_URL}/reference/javascript/storage-from-getpublicurl`,
  1160. description: `
  1161. A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.
  1162. This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.
  1163. The bucket needs to be set to public, either via \`updateBucket()\` or by going to Storage on supabase.com/dashboard, clicking the overflow menu on a bucket and choosing "Make public"
  1164. RLS policy permissions required:
  1165. - \`buckets\` table permissions: none
  1166. - \`objects\` table permissions: none
  1167. `,
  1168. code: ({
  1169. name,
  1170. apikey: _apikey,
  1171. endpoint,
  1172. }: {
  1173. name: string
  1174. apikey: string
  1175. endpoint: string
  1176. }) => [
  1177. {
  1178. key: 'storage-retrieve-public-url',
  1179. title: undefined,
  1180. bash: `
  1181. # No bash command available.
  1182. # You can construct the public URL by concatenating the bucket URL with the path to the asset
  1183. # e.g ${endpoint}/storage/v1/object/public/${name}/folder/avatar1.png`,
  1184. js: `
  1185. const { data } = briven
  1186. .storage
  1187. .from('${name}')
  1188. .getPublicUrl('folder/avatar1.png')
  1189. `,
  1190. },
  1191. ],
  1192. },
  1193. invokeEdgeFunction: {
  1194. key: 'invoke-edge-function',
  1195. category: API_DOCS_CATEGORIES.EDGE_FUNCTIONS,
  1196. title: 'Invoke an edge function',
  1197. docsUrl: `${DOCS_URL}/reference/javascript/functions-invoke`,
  1198. description: `
  1199. Invokes a Briven Edge Function. Requires an Authorization header, and invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
  1200. When you pass in a body to your function, we automatically attach the \`Content-Type\` header for \`Blob\`, \`ArrayBuffer\`, \`File\`, \`FormData\` and \`String\`. If it doesn't match any of these types we assume the payload is \`json\`, serialize it and attach the \`Content-Type\` header as \`application/json\`. You can override this behavior by passing in a \`Content-Type\` header of your own.
  1201. Responses are automatically parsed as \`json\`, \`blob\` and \`form-data\` depending on the \`Content-Type\` header sent by your function. Responses are parsed as \`text\` by default.
  1202. `,
  1203. code: ({ name, endpoint, apikey }: { name: string; endpoint: string; apikey: string }) => [
  1204. {
  1205. key: 'invoke-edge-function',
  1206. title: undefined,
  1207. bash: `
  1208. curl --request POST '${endpoint}/functions/v1/${name}' \\
  1209. --header 'Authorization: Bearer ${apikey}' \\
  1210. --header 'Content-Type: application/json' \\
  1211. --data '{ "name": "Functions" }'
  1212. `,
  1213. js: `
  1214. const { data, error } = await briven
  1215. .functions
  1216. .invoke('${name}', {
  1217. body: { foo: 'bar' }
  1218. })`,
  1219. },
  1220. ],
  1221. },
  1222. } as const