Can you believe our book club is celebrating our 10th anniversary?! π
Welcome to our Notion bot that populates our favorite tool with a list of books ranked by average rating and favorite count!
notion-book-club/
ββ node_modules/
ββ src/
β ββ data/
β β ββ ratings.csv
| ββ lib/
| β β ββ notion.ts
β ββ utils/
β β ββ errors.ts
β β ββ index.ts
β β ββ types.ts
β ββ services/
β β ββ database.ts
β β ββ index.ts
β β ββ parser.ts
β ββ index.ts
ββ .gitignore
ββ package.json
ββ README.md
ββ tsconfig.json
- Create a Notion integration to get the NOTION_KEY.
- Share a database with your integration to get the NOTION_DATABASE_ID
- Download the zip file or
git clone
to your favorite working directory yarn
to create a large folder of node_modules- Copy
.env.example
to.env
to store your NOTION_KEY and NOTION_DATABASE_ID - update
ratings.csv
insrc/data
folder if you want to change data yarn start
to update your database!
I wanted to challenge myself by creating a Typescript project from scratch. It took longer to define types but in the end it was helpful to understand exactly the data I was transforming. Below are resources and challenges I ran into:
- Notion Developer Guide : Helpful resource for API reference
- Notion Javascript SDK : Helpful wrappers to call APIs. Loved the examples/ helpers related to Typescript.
- Challenge: Ran into an issue trying to create proper Typescript types for the custom property in the response from
notion.databases.query
- Resolution: Searched the issues tab on notion-sdk's Github project and figured it out
- Challenge: Ran into an issue trying to create proper Typescript types for the custom property in the response from
- dotenv : load env variables
- Challenge: Got stuck because my env variables were not loading in my services functions even though I called
dotenv.config()
in myindex.js
file. - Resolution: Read readme of dotenv Github project to learn that modules are imported first and executed in depth-first traversal of the dependency graph, meaning I had to move my
dotenv
import to the first row!
- Challenge: Got stuck because my env variables were not loading in my services functions even though I called
- fs: Already built into NodeJS. I used
fs.readFileSync
to read the csv file.- Challenge: Never used
fs
directly and wondered what the differences betweenfs.readFileSync
andfs.readFile
were. - Resolution: Found this helpful StackOverFlow answer. Good reminder that
readFileSync
can tie up the single thread loop if it takes a long time!
- Challenge: Never used
- Typescript Docs for creating advanced types
- Challenge: Wanted to have proper error handling. Since error is an unknown type in Typescript, I cannot call any methods directly such as
error.message
- Resolution: Found a Ken Dodds article on how he catches error messages in Typescript. Thankfully, I also discovered that Notion Javascript SDK has helpers such as
isNotionClientError
,ClientErrorCode
,APIErrorCode
to help me with error handling
- Challenge: Wanted to have proper error handling. Since error is an unknown type in Typescript, I cannot call any methods directly such as
I manually tested my functions to ensure that my code is working correctly.
With more time, I would write proper Jest tests, including:
- Unit Tests: Test success and error handling cases for each function within the service. Mocking data from API calls.
- Integration Tests: Testing that the integration between the
parser
service and thedatabase
service are functioning reliably and any future changes will not break existing functionality
Overall, the Notion developer API Reference, Guide, and Javascript SDK README was helpful and clear. The only part I was slightly confused on was whether adding/updating rows in my database table was a page/block/or database. Having more clear examples of each type of component would be helpful.
P.S A small bug I found in the documentation
- In API Reference -> Update a block -> SDK example ->
block_id
is missing from the request
Hi! My name is Alice.
I'm a 4th year computer science student at University of British Columbia (UBC). From eating rotten shark in Iceland to floating in the Dead Sea to trekking on Everest, I love to challenge myself! Curious to see more of what I've done? Visit me at my digital garden. π±