Files
supabase/apps/www/lib/notion.ts
Tomás PozoandTerry Sutton 3cc4e215d5 New supasquad page (#38441)
* Create initial draft

* Update application url

* Copy changes

* Update quote samples

* Fix typo

* Fix prop value

* Fix hydration errors

* Fix hydration errors, 2

* Fix hydration errors, 3

* Solve icons hydration issue

* Remove console log

* hide quotes

* Nudges

* Add form component and integration to notion (WIP)

* Fix some fields mapping

* Nudges and add form inline

* Some fixes

* Refactor notion lib

* Integrate customerio

* Remove logs

* Apply some minor fixes

* Add country selector and split location fields

* Mark required fields

* Add sentry error capturing

* Add sentry dsn routing to edge config

* Fix with a different sentry client

* Remove custom transport on default sentry

* Fix prettier issues

* Use node client on sentry

* Make monthly commitment text

* Minor improvements

* Use text monthly commitment in notion

* Remove country flag on select item for typing search

* Update apps/www/data/open-source/contributing/supasquad.tsx

* Restore form reset

* Fix missing env vars

---------

Co-authored-by: Terry Sutton <saltcod@gmail.com>
2025-09-05 16:57:28 -02:30

42 lines
1.2 KiB
TypeScript

import 'server-only'
export const getTitlePropertyName = async (dbId: string, apiKey: string): Promise<string> => {
const resp = await fetch(`https://api.notion.com/v1/databases/${dbId}`, {
headers: {
Authorization: `Bearer ${apiKey}`,
'Notion-Version': '2022-06-28',
},
})
if (!resp.ok) throw new Error('Failed to retrieve database metadata')
const db: any = await resp.json()
const entry = Object.entries(db.properties).find(([, v]: any) => v?.type === 'title')
if (!entry) throw new Error('No title property found in notion database')
return entry[0]
}
export const insertPageInDatabase = async (
dbId: string,
apiKey: string,
data: any
): Promise<string> => {
const resp = await fetch(`https://api.notion.com/v1/pages`, {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Notion-Version': '2022-06-28',
'Content-Type': 'application/json',
},
body: JSON.stringify({
parent: { database_id: dbId },
properties: data,
}),
})
if (!resp.ok) {
const respText = await resp.text()
throw new Error('Failed to insert page into notion database: ' + respText)
}
const json = await resp.json()
return json.id
}