Snippets.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. const snippets = {
  2. endpoint: (endpoint: string) => ({
  3. title: 'API URL',
  4. bash: {
  5. language: 'bash',
  6. code: `${endpoint}`,
  7. },
  8. js: {
  9. language: 'bash',
  10. code: `${endpoint}`,
  11. },
  12. }),
  13. install: () => ({
  14. title: 'Install',
  15. bash: null,
  16. js: {
  17. language: 'bash',
  18. code: `npm install --save @supabase/supabase-js`,
  19. },
  20. }),
  21. init: (endpoint: string) => ({
  22. title: 'Initializing',
  23. bash: {
  24. language: 'bash',
  25. code: `# No client library required for Bash.`,
  26. },
  27. js: {
  28. language: 'js',
  29. code: `
  30. import { createClient } from '@supabase/supabase-js'
  31. const brivenUrl = '${endpoint}'
  32. const brivenKey = process.env.BRIVEN_KEY
  33. const briven = createClient(brivenUrl, brivenKey)`,
  34. },
  35. python: {
  36. language: 'python',
  37. code: `
  38. import os
  39. from briven import create_client, Client
  40. url: str = '${endpoint}'
  41. key: str = os.environ.get("BRIVEN_KEY")
  42. briven: Client = create_client(url, key)
  43. `,
  44. },
  45. dart: {
  46. language: 'dart',
  47. code: `
  48. const brivenUrl = '${endpoint}';
  49. const brivenKey = String.fromEnvironment('BRIVEN_KEY');
  50. Future<void> main() async {
  51. await Briven.initialize(url: brivenUrl, anonKey: brivenKey);
  52. runApp(MyApp());
  53. }`,
  54. },
  55. }),
  56. authKey: (title: string, varName: string, apikey: string) => ({
  57. title: `${title}`,
  58. bash: {
  59. language: 'bash',
  60. code: `${apikey}`,
  61. },
  62. js: {
  63. language: 'js',
  64. code: `const ${varName} = '${apikey}'`,
  65. },
  66. }),
  67. authKeyExample: (
  68. defaultApiKey: string,
  69. endpoint: string,
  70. { keyName, showBearer = true }: { keyName?: string; showBearer?: boolean }
  71. ) => ({
  72. title: 'Example usage',
  73. bash: {
  74. language: 'bash',
  75. code: `
  76. curl '${endpoint}/rest/v1/' \\
  77. -H "apikey: ${defaultApiKey}" ${
  78. showBearer
  79. ? `\\
  80. -H "Authorization: Bearer ${defaultApiKey}"`
  81. : ''
  82. }
  83. `,
  84. },
  85. js: {
  86. language: 'js',
  87. code: `
  88. const BRIVEN_URL = "${endpoint}"
  89. const briven = createClient(BRIVEN_URL, process.env.${keyName || 'BRIVEN_KEY'});
  90. `,
  91. },
  92. }),
  93. rpcSingle: ({
  94. rpcName,
  95. rpcParams,
  96. endpoint,
  97. apiKey,
  98. showBearer = true,
  99. }: {
  100. rpcName: string
  101. rpcParams: any[]
  102. endpoint: string
  103. apiKey: string
  104. showBearer: boolean
  105. }) => {
  106. let rpcList = rpcParams.map((x) => `"${x.name}": "value"`).join(', ')
  107. let noParams = !rpcParams.length
  108. let bashParams = noParams ? '' : `\n-d '{ ${rpcList} }' \\`
  109. let jsParams = noParams
  110. ? ''
  111. : `, {${
  112. rpcParams.length
  113. ? rpcParams
  114. .map((x) => `\n ${x.name}`)
  115. .join(`, `)
  116. .concat('\n ')
  117. : ''
  118. }}`
  119. return {
  120. title: 'Invoke function ',
  121. bash: {
  122. language: 'bash',
  123. code: `
  124. curl -X POST '${endpoint}/rest/v1/rpc/${rpcName}' \\${bashParams}
  125. -H "Content-Type: application/json" \\
  126. -H "apikey: ${apiKey}" ${
  127. showBearer
  128. ? `\\
  129. -H "Authorization: Bearer ${apiKey}"`
  130. : ''
  131. }
  132. `,
  133. },
  134. js: {
  135. language: 'js',
  136. code: `
  137. let { data, error } = await briven
  138. .rpc('${rpcName}'${jsParams})
  139. if (error) console.error(error)
  140. else console.log(data)
  141. `,
  142. },
  143. }
  144. },
  145. subscribeAll: (listenerName: string, resourceId: string) => ({
  146. title: 'Subscribe to all events',
  147. bash: {
  148. language: 'bash',
  149. code: `# Realtime streams are only supported by our client libraries`,
  150. },
  151. js: {
  152. language: 'js',
  153. code: `
  154. const ${listenerName} = briven.channel('custom-all-channel')
  155. .on(
  156. 'postgres_changes',
  157. { event: '*', schema: 'public', table: '${resourceId}' },
  158. (payload) => {
  159. console.log('Change received!', payload)
  160. }
  161. )
  162. .subscribe()`,
  163. },
  164. }),
  165. subscribeInserts: (listenerName: string, resourceId: string) => ({
  166. title: 'Subscribe to inserts',
  167. bash: {
  168. language: 'bash',
  169. code: `# Realtime streams are only supported by our client libraries`,
  170. },
  171. js: {
  172. language: 'js',
  173. code: `
  174. const ${listenerName} = briven.channel('custom-insert-channel')
  175. .on(
  176. 'postgres_changes',
  177. { event: 'INSERT', schema: 'public', table: '${resourceId}' },
  178. (payload) => {
  179. console.log('Change received!', payload)
  180. }
  181. )
  182. .subscribe()`,
  183. },
  184. }),
  185. subscribeUpdates: (listenerName: string, resourceId: string) => ({
  186. title: 'Subscribe to updates',
  187. bash: {
  188. language: 'bash',
  189. code: `# Realtime streams are only supported by our client libraries`,
  190. },
  191. js: {
  192. language: 'js',
  193. code: `
  194. const ${listenerName} = briven.channel('custom-update-channel')
  195. .on(
  196. 'postgres_changes',
  197. { event: 'UPDATE', schema: 'public', table: '${resourceId}' },
  198. (payload) => {
  199. console.log('Change received!', payload)
  200. }
  201. )
  202. .subscribe()`,
  203. },
  204. }),
  205. subscribeDeletes: (listenerName: string, resourceId: string) => ({
  206. title: 'Subscribe to deletes',
  207. bash: {
  208. language: 'bash',
  209. code: `# Realtime streams are only supported by our client libraries`,
  210. },
  211. js: {
  212. language: 'js',
  213. code: `
  214. const ${listenerName} = briven.channel('custom-delete-channel')
  215. .on(
  216. 'postgres_changes',
  217. { event: 'DELETE', schema: 'public', table: '${resourceId}' },
  218. (payload) => {
  219. console.log('Change received!', payload)
  220. }
  221. )
  222. .subscribe()`,
  223. },
  224. }),
  225. subscribeEq: (listenerName: string, resourceId: string, columnName: string, value: string) => ({
  226. title: 'Subscribe to specific rows',
  227. bash: {
  228. language: 'bash',
  229. code: `# Realtime streams are only supported by our client libraries`,
  230. },
  231. js: {
  232. language: 'js',
  233. code: `
  234. const ${listenerName} = briven.channel('custom-filter-channel')
  235. .on(
  236. 'postgres_changes',
  237. { event: '*', schema: 'public', table: '${resourceId}', filter: '${columnName}=eq.${value}' },
  238. (payload) => {
  239. console.log('Change received!', payload)
  240. }
  241. )
  242. .subscribe()`,
  243. },
  244. }),
  245. readAll: (resourceId: string, endpoint: string, apiKey: string) => ({
  246. title: 'Read all rows',
  247. bash: {
  248. language: 'bash',
  249. code: `
  250. curl '${endpoint}/rest/v1/${resourceId}?select=*' \\
  251. -H "apikey: ${apiKey}" \\
  252. -H "Authorization: Bearer ${apiKey}"
  253. `,
  254. },
  255. js: {
  256. language: 'js',
  257. code: `
  258. let { data: ${resourceId}, error } = await briven
  259. .from('${resourceId}')
  260. .select('*')
  261. `,
  262. },
  263. }),
  264. readColumns: ({
  265. title = 'Read specific columns',
  266. resourceId,
  267. endpoint,
  268. apiKey,
  269. columnName = 'some_column,other_column',
  270. }: {
  271. title?: string
  272. resourceId: string
  273. endpoint: string
  274. apiKey: string
  275. columnName?: string
  276. }) => ({
  277. title,
  278. bash: {
  279. language: 'bash',
  280. code: `
  281. curl '${endpoint}/rest/v1/${resourceId}?select=${columnName}' \\
  282. -H "apikey: ${apiKey}" \\
  283. -H "Authorization: Bearer ${apiKey}"
  284. `,
  285. },
  286. js: {
  287. language: 'js',
  288. code: `
  289. let { data: ${resourceId}, error } = await briven
  290. .from('${resourceId}')
  291. .select('${columnName}')
  292. `,
  293. },
  294. }),
  295. readForeignTables: (resourceId: string, endpoint: string, apiKey: string) => ({
  296. title: 'Read referenced tables',
  297. bash: {
  298. language: 'bash',
  299. code: `
  300. curl '${endpoint}/rest/v1/${resourceId}?select=some_column,other_table(foreign_key)' \\
  301. -H "apikey: ${apiKey}" \\
  302. -H "Authorization: Bearer ${apiKey}"
  303. `,
  304. },
  305. js: {
  306. language: 'js',
  307. code: `
  308. let { data: ${resourceId}, error } = await briven
  309. .from('${resourceId}')
  310. .select(\`
  311. some_column,
  312. other_table (
  313. foreign_key
  314. )
  315. \`)
  316. `,
  317. },
  318. }),
  319. readRange: (resourceId: string, endpoint: string, apiKey: string) => ({
  320. title: 'With pagination',
  321. bash: {
  322. language: 'bash',
  323. code: `
  324. curl '${endpoint}/rest/v1/${resourceId}?select=*' \\
  325. -H "apikey: ${apiKey}" \\
  326. -H "Authorization: Bearer ${apiKey}" \\
  327. -H "Range: 0-9"
  328. `,
  329. },
  330. js: {
  331. language: 'js',
  332. code: `
  333. let { data: ${resourceId}, error } = await briven
  334. .from('${resourceId}')
  335. .select('*')
  336. .range(0, 9)
  337. `,
  338. },
  339. }),
  340. readFilters: (resourceId: string, endpoint: string, apiKey: string) => ({
  341. title: 'With filtering',
  342. bash: {
  343. language: 'bash',
  344. code: `
  345. curl --get '${endpoint}/rest/v1/${resourceId}' \\
  346. -H "apikey: ${apiKey}" \\
  347. -H "Authorization: Bearer ${apiKey}" \\
  348. -H "Range: 0-9" \\
  349. -d "select=*" \\
  350. \\
  351. \`# Filters\` \\
  352. -d "column=eq.Equal+to" \\
  353. -d "column=gt.Greater+than" \\
  354. -d "column=lt.Less+than" \\
  355. -d "column=gte.Greater+than+or+equal+to" \\
  356. -d "column=lte.Less+than+or+equal+to" \\
  357. -d "column=like.*CaseSensitive*" \\
  358. -d "column=ilike.*CaseInsensitive*" \\
  359. -d "column=is.null" \\
  360. -d "column=in.(Array,Values)" \\
  361. -d "column=neq.Not+equal+to" \\
  362. \\
  363. \`# Arrays\` \\
  364. -d "array_column=cs.{array,contains}" \\
  365. -d "array_column=cd.{contained,by}" \\
  366. \\
  367. \`# Logical operators\` \\
  368. -d "column=not.like.Negate+filter" \\
  369. -d "or=(some_column.eq.Some+value,other_column.eq.Other+value)"
  370. `,
  371. },
  372. js: {
  373. language: 'js',
  374. code: `
  375. let { data: ${resourceId}, error } = await briven
  376. .from('${resourceId}')
  377. .select("*")
  378. // Filters
  379. .eq('column', 'Equal to')
  380. .gt('column', 'Greater than')
  381. .lt('column', 'Less than')
  382. .gte('column', 'Greater than or equal to')
  383. .lte('column', 'Less than or equal to')
  384. .like('column', '%CaseSensitive%')
  385. .ilike('column', '%CaseInsensitive%')
  386. .is('column', null)
  387. .in('column', ['Array', 'Values'])
  388. .neq('column', 'Not equal to')
  389. // Arrays
  390. .contains('array_column', ['array', 'contains'])
  391. .containedBy('array_column', ['contained', 'by'])
  392. // Logical operators
  393. .not('column', 'like', 'Negate filter')
  394. .or('some_column.eq.Some value, other_column.eq.Other value')
  395. `,
  396. },
  397. }),
  398. insertSingle: (resourceId: string, endpoint: string, apiKey: string) => ({
  399. title: 'Insert a row',
  400. bash: {
  401. language: 'bash',
  402. code: `
  403. curl -X POST '${endpoint}/rest/v1/${resourceId}' \\
  404. -H "apikey: ${apiKey}" \\
  405. -H "Authorization: Bearer ${apiKey}" \\
  406. -H "Content-Type: application/json" \\
  407. -H "Prefer: return=minimal" \\
  408. -d '{ "some_column": "someValue", "other_column": "otherValue" }'
  409. `,
  410. },
  411. js: {
  412. language: 'js',
  413. code: `
  414. const { data, error } = await briven
  415. .from('${resourceId}')
  416. .insert([
  417. { some_column: 'someValue', other_column: 'otherValue' },
  418. ])
  419. .select()
  420. `,
  421. },
  422. }),
  423. insertMany: (resourceId: string, endpoint: string, apiKey: string) => ({
  424. title: 'Insert many rows',
  425. bash: {
  426. language: 'bash',
  427. code: `
  428. curl -X POST '${endpoint}/rest/v1/${resourceId}' \\
  429. -H "apikey: ${apiKey}" \\
  430. -H "Authorization: Bearer ${apiKey}" \\
  431. -H "Content-Type: application/json" \\
  432. -d '[{ "some_column": "someValue" }, { "other_column": "otherValue" }]'
  433. `,
  434. },
  435. js: {
  436. language: 'js',
  437. code: `
  438. const { data, error } = await briven
  439. .from('${resourceId}')
  440. .insert([
  441. { some_column: 'someValue' },
  442. { some_column: 'otherValue' },
  443. ])
  444. .select()
  445. `,
  446. },
  447. }),
  448. upsert: (resourceId: string, endpoint: string, apiKey: string) => ({
  449. title: 'Upsert matching rows',
  450. bash: {
  451. language: 'bash',
  452. code: `
  453. curl -X POST '${endpoint}/rest/v1/${resourceId}' \\
  454. -H "apikey: ${apiKey}" \\
  455. -H "Authorization: Bearer ${apiKey}" \\
  456. -H "Content-Type: application/json" \\
  457. -H "Prefer: resolution=merge-duplicates" \\
  458. -d '{ "some_column": "someValue", "other_column": "otherValue" }'
  459. `,
  460. },
  461. js: {
  462. language: 'js',
  463. code: `
  464. const { data, error } = await briven
  465. .from('${resourceId}')
  466. .upsert({ some_column: 'someValue' })
  467. .select()
  468. `,
  469. },
  470. }),
  471. update: (resourceId: string, endpoint: string, apiKey: string) => ({
  472. title: 'Update matching rows',
  473. bash: {
  474. language: 'bash',
  475. code: `
  476. curl -X PATCH '${endpoint}/rest/v1/${resourceId}?some_column=eq.someValue' \\
  477. -H "apikey: ${apiKey}" \\
  478. -H "Authorization: Bearer ${apiKey}" \\
  479. -H "Content-Type: application/json" \\
  480. -H "Prefer: return=minimal" \\
  481. -d '{ "other_column": "otherValue" }'
  482. `,
  483. },
  484. js: {
  485. language: 'js',
  486. code: `
  487. const { data, error } = await briven
  488. .from('${resourceId}')
  489. .update({ other_column: 'otherValue' })
  490. .eq('some_column', 'someValue')
  491. .select()
  492. `,
  493. },
  494. }),
  495. delete: (resourceId: string, endpoint: string, apiKey: string) => ({
  496. title: 'Delete matching rows',
  497. bash: {
  498. language: 'bash',
  499. code: `
  500. curl -X DELETE '${endpoint}/rest/v1/${resourceId}?some_column=eq.someValue' \\
  501. -H "apikey: ${apiKey}" \\
  502. -H "Authorization: Bearer ${apiKey}"
  503. `,
  504. },
  505. js: {
  506. language: 'js',
  507. code: `
  508. const { error } = await briven
  509. .from('${resourceId}')
  510. .delete()
  511. .eq('some_column', 'someValue')
  512. `,
  513. },
  514. }),
  515. authSignup: (endpoint: string, apiKey: string, randomPassword: string) => ({
  516. title: 'User signup',
  517. bash: {
  518. language: 'bash',
  519. code: `
  520. curl -X POST '${endpoint}/auth/v1/signup' \\
  521. -H "apikey: ${apiKey}" \\
  522. -H "Content-Type: application/json" \\
  523. -d '{
  524. "email": "someone@email.com",
  525. "password": "${randomPassword}"
  526. }'
  527. `,
  528. },
  529. js: {
  530. language: 'js',
  531. code: `
  532. let { data, error } = await briven.auth.signUp({
  533. email: 'someone@email.com',
  534. password: '${randomPassword}'
  535. })
  536. `,
  537. },
  538. }),
  539. authLogin: (endpoint: string, apiKey: string, randomPassword: string) => ({
  540. title: 'User login',
  541. bash: {
  542. language: 'bash',
  543. code: `
  544. curl -X POST '${endpoint}/auth/v1/token?grant_type=password' \\
  545. -H "apikey: ${apiKey}" \\
  546. -H "Content-Type: application/json" \\
  547. -d '{
  548. "email": "someone@email.com",
  549. "password": "${randomPassword}"
  550. }'
  551. `,
  552. },
  553. js: {
  554. language: 'js',
  555. code: `
  556. let { data, error } = await briven.auth.signInWithPassword({
  557. email: 'someone@email.com',
  558. password: '${randomPassword}'
  559. })
  560. `,
  561. },
  562. }),
  563. authMagicLink: (endpoint: string, apiKey: string) => ({
  564. title: 'User login',
  565. bash: {
  566. language: 'bash',
  567. code: `
  568. curl -X POST '${endpoint}/auth/v1/magiclink' \\
  569. -H "apikey: ${apiKey}" \\
  570. -H "Content-Type: application/json" \\
  571. -d '{
  572. "email": "someone@email.com"
  573. }'
  574. `,
  575. },
  576. js: {
  577. language: 'js',
  578. code: `
  579. let { data, error } = await briven.auth.signInWithOtp({
  580. email: 'someone@email.com'
  581. })
  582. `,
  583. },
  584. }),
  585. authPhoneSignUp: (endpoint: string, apiKey: string) => ({
  586. title: 'Phone Signup',
  587. bash: {
  588. language: 'bash',
  589. code: `
  590. curl -X POST '${endpoint}/auth/v1/signup' \\
  591. -H "apikey: ${apiKey}" \\
  592. -H "Content-Type: application/json" \\
  593. -d '{
  594. "phone": "+13334445555",
  595. "password": "some-password"
  596. }'
  597. `,
  598. },
  599. js: {
  600. language: 'js',
  601. code: `
  602. let { data, error } = await briven.auth.signUp({
  603. phone: '+13334445555',
  604. password: 'some-password'
  605. })
  606. `,
  607. },
  608. }),
  609. authMobileOTPLogin: (endpoint: string, apiKey: string) => ({
  610. title: 'Phone Login',
  611. bash: {
  612. language: 'bash',
  613. code: `
  614. curl -X POST '${endpoint}/auth/v1/otp' \\
  615. -H "apikey: ${apiKey}" \\
  616. -H "Content-Type: application/json" \\
  617. -d '{
  618. "phone": "+13334445555"
  619. }'
  620. `,
  621. },
  622. js: {
  623. language: 'js',
  624. code: `
  625. let { data, error } = await briven.auth.signInWithOtp({
  626. phone: '+13334445555'
  627. })
  628. `,
  629. },
  630. }),
  631. authMobileOTPVerify: (endpoint: string, apiKey: string) => ({
  632. title: 'Verify Pin',
  633. bash: {
  634. language: 'bash',
  635. code: `
  636. curl -X POST '${endpoint}/auth/v1/verify' \\
  637. -H "apikey: ${apiKey}" \\
  638. -H "Content-Type: application/json" \\
  639. -d '{
  640. "type": "sms",
  641. "phone": "+13334445555",
  642. "token": "123456"
  643. }'
  644. `,
  645. },
  646. js: {
  647. language: 'js',
  648. code: `
  649. let { data, error } = await briven.auth.verifyOtp({
  650. phone: '+13334445555',
  651. token: '123456',
  652. type: 'sms'
  653. })
  654. `,
  655. },
  656. }),
  657. authInvite: (endpoint: string, apiKey: string) => ({
  658. title: 'Invite User',
  659. bash: {
  660. language: 'bash',
  661. code: `
  662. curl -X POST '${endpoint}/auth/v1/invite' \\
  663. -H "apikey: ${apiKey}" \\
  664. -H "Authorization: Bearer SERVICE_ROLE_KEY" \\
  665. -H "Content-Type: application/json" \\
  666. -d '{
  667. "email": "someone@email.com"
  668. }'
  669. `,
  670. },
  671. js: {
  672. language: 'js',
  673. code: `
  674. let { data, error } = await briven.auth.admin.inviteUserByEmail('someone@email.com')
  675. `,
  676. },
  677. }),
  678. authThirdPartyLogin: (endpoint: string, apiKey: string) => ({
  679. title: 'Third Party Login',
  680. bash: {
  681. language: 'bash',
  682. code: `
  683. curl -X GET '${endpoint}/auth/v1/authorize?provider=github' \\
  684. -H "apikey: ${apiKey}" \\
  685. -H "Authorization: Bearer USER_TOKEN" \\
  686. -H "Content-Type: application/json"
  687. `,
  688. },
  689. js: {
  690. language: 'js',
  691. code: `
  692. let { data, error } = await briven.auth.signInWithOAuth({
  693. provider: 'github'
  694. })
  695. `,
  696. },
  697. }),
  698. authUser: (endpoint: string, apiKey: string) => ({
  699. title: 'Get User',
  700. bash: {
  701. language: 'bash',
  702. code: `
  703. curl -X GET '${endpoint}/auth/v1/user' \\
  704. -H "apikey: ${apiKey}" \\
  705. -H "Authorization: Bearer USER_TOKEN"
  706. `,
  707. },
  708. js: {
  709. language: 'js',
  710. code: `
  711. const { data: { user } } = await briven.auth.getUser()
  712. `,
  713. },
  714. }),
  715. authRecover: (endpoint: string, apiKey: string) => ({
  716. title: 'Password Recovery',
  717. bash: {
  718. language: 'bash',
  719. code: `
  720. curl -X POST '${endpoint}/auth/v1/recover' \\
  721. -H "apikey: ${apiKey}" \\
  722. -H "Content-Type: application/json" \\
  723. -d '{
  724. "email": "someone@email.com"
  725. }'
  726. `,
  727. },
  728. js: {
  729. language: 'js',
  730. code: `
  731. let { data, error } = await briven.auth.resetPasswordForEmail(email)
  732. `,
  733. },
  734. }),
  735. authUpdate: (endpoint: string, apiKey: string) => ({
  736. title: 'Update User',
  737. bash: {
  738. language: 'bash',
  739. code: `
  740. curl -X PUT '${endpoint}/auth/v1/user' \\
  741. -H "apikey: ${apiKey}" \\
  742. -H "Authorization: Bearer USER_TOKEN" \\
  743. -H "Content-Type: application/json" \\
  744. -d '{
  745. "email": "someone@email.com",
  746. "password": "new-password",
  747. "data": {
  748. "key": "value"
  749. }
  750. }'
  751. `,
  752. },
  753. js: {
  754. language: 'js',
  755. code: `
  756. const { data, error } = await briven.auth.updateUser({
  757. email: "new@email.com",
  758. password: "new-password",
  759. data: { hello: 'world' }
  760. })
  761. `,
  762. },
  763. }),
  764. authLogout: (endpoint: string, apiKey: string) => ({
  765. title: 'User logout',
  766. bash: {
  767. language: 'bash',
  768. code: `
  769. curl -X POST '${endpoint}/auth/v1/logout' \\
  770. -H "apikey: ${apiKey}" \\
  771. -H "Content-Type: application/json" \\
  772. -H "Authorization: Bearer USER_TOKEN"
  773. `,
  774. },
  775. js: {
  776. language: 'js',
  777. code: `
  778. let { error } = await briven.auth.signOut()
  779. `,
  780. },
  781. }),
  782. }
  783. export default snippets