GithubHelp home page GithubHelp logo

jakeswenson / notion Goto Github PK

View Code? Open in Web Editor NEW
126.0 6.0 59.0 131 KB

Notion Offical API client library for rust

Home Page: https://crates.io/crates/notion

License: MIT License

Rust 99.47% Shell 0.53%
notion-api notion notion-rust rust-library

notion's Introduction

notion

Build Crates.io

Notion API client library for rust.

This project is under active development and this README will be updated as this library gets closer to a reliable state. However, if you're really eager see the example todo cli application provided in examples/todo.

Docs

The generated documentation site is available here: https://docs.rs/notion/

Building

cargo build

Pull Request builds

Testing

We are in the process of moving to wiremock based notion api testing. Existing tests use a private notion org, and expect an environment variable set of NOTION_API_TOKEN.

We understand that right now this is a bit painful, but any help in this migration journey is very welcome!

Contributing

Contributions are always welcome! If you have an idea, it's best to float it by us before working on it to ensure no effort is wasted. If there's already an open issue for it, knock yourself out.

If you have any questions, feel free to use Discussions. Please don't hesitate to ask questions!

notion's People

Contributors

ahmetrehaseker avatar auscyber avatar bspradling avatar flamedmg avatar jakeswenson avatar markacola avatar nxsy avatar spachava753 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

notion's Issues

Querying database requires full user info access

Hello!
I have the following code, in a project where I don't need full user info, just the base (without the email).
If I don't have the e-mail permission granted, the code crashes with the error below, but with the permission granted it successfully queries.

// The query
let results = notion_api
    .query_database(db, DatabaseQuery::default())
    .await?;
// The error without any user info beyond ID
Error: Error parsing json response: missing field `type`

Caused by:
    missing field `type`

// The error with user info without email
Error: Error parsing json response: missing field `email`

Caused by:
    missing field `email`

IMHO, those should either be optional, or on an enum/nested struct, and not require full permissions (otherwise, could it be mentioned in the README?)

API is deprecated

Minimal example:

    let client =
        NotionApi::new("secret_xxx".to_string()).unwrap();
    let databases = client.list_databases().await.unwrap();

Throws

error: ErrorResponse { statu
s: StatusCode(400), code: ValidationError, message: "This API is deprecated." }

JsonParseError when a page contains not empty Files property.

When I query a database whose pages contain not empty Files property, this error occurs.

JsonParseError { source: Error("missing field `url`", line: 0, column: 0) }

Source:

    let works_pages = notion_api
        .query_database(works_database.id.clone(), DatabaseQuery::empty())
        .await.unwrap()
        .results;

Get JsonParseError when querying database

The program keep get JsonParseError as following when database (200+ pages) query's response contains some specific pages, but I can't find out any error in json. Do you have any idea? Thank you!

err = JsonParseError {
    source: Error("missing field `type`", line: 0, column: 0),
}

Rollups are not parsed properly

Hello, usually it try to fix things myself, but this issue i don't have straight way how to fix. Please take a look at json returned by notion:

        "properties": {
    "Is Subscription": {
      "id": "%3E%7Dfd",
      "type": "checkbox",
      "checkbox": false
    },
    "Base Price": {
      "id": "AuNU",
      "type": "number",
      "number": 29.95
    },
    "Product Type Code": {
      "id": "R%7Cm%3F",
      "type": "rollup",
      "rollup": {
        "type": "array",
        "array": [
          {
            "type": "rich_text",
            "rich_text": [
              {
                "type": "text",
                "text": {
                  "content": "personal",
                  "link": null
                },
                "annotations": {
                  "bold": false,
                  "italic": false,
                  "strikethrough": false,
                  "underline": false,
                  "code": false,
                  "color": "default"
                },
                "plain_text": "personal",
                "href": null
              }
            ]
          }
        ],
        "function": "show_original"
      }
    },
......
}

Rollup contains an array, which contains PropertyValue.
There are two issues: RollupValue exists that probably was meant to solve this issue, but it's not used anywhere. If i create property array and make it a Option<Vec>, i will have an issue. Rich text node does not have an ID. Making this field optional is not a good idea imho.

Please suggest how to better solve this issue, and i will be happy to implement and issue PR

RUSTSEC-2020-0159: Potential segfault in `localtime_r` invocations

Potential segfault in localtime_r invocations

Details
Package chrono
Version 0.4.19
URL chronotope/chrono#499
Date 2020-11-10

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

Workarounds

No workarounds are known.

References

See advisory page for additional details.

RUSTSEC-2021-0139: ansi_term is Unmaintained

ansi_term is Unmaintained

Details
Status unmaintained
Package ansi_term
Version 0.12.1
URL ogham/rust-ansi-term#72
Date 2021-08-18

The maintainer has adviced this crate is deprecated and will not
receive any maintenance.

The crate does not seem to have much dependencies and may or may not be ok to use as-is.

Last release seems to have been three years ago.

Possible Alternative(s)

The below list has not been vetted in any way and may or may not contain alternatives;

See advisory page for additional details.

RUSTSEC-2021-0119: Out-of-bounds write in nix::unistd::getgrouplist

Out-of-bounds write in nix::unistd::getgrouplist

Details
Package nix
Version 0.19.1
URL nix-rust/nix#1541
Date 2021-09-27
Patched versions ^0.20.2,^0.21.2,^0.22.2,>=0.23.0
Unaffected versions <0.16.0

On certain platforms, if a user has more than 16 groups, the
nix::unistd::getgrouplist function will call the libc getgrouplist
function with a length parameter greater than the size of the buffer it
provides, resulting in an out-of-bounds write and memory corruption.

The libc getgrouplist function takes an in/out parameter ngroups
specifying the size of the group buffer. When the buffer is too small to
hold all of the reqested user's group memberships, some libc
implementations, including glibc and Solaris libc, will modify ngroups
to indicate the actual number of groups for the user, in addition to
returning an error. The version of nix::unistd::getgrouplist in nix
0.16.0 and up will resize the buffer to twice its size, but will not
read or modify the ngroups variable. Thus, if the user has more than
twice as many groups as the initial buffer size of 8, the next call to
getgrouplist will then write past the end of the buffer.

The issue would require editing /etc/groups to exploit, which is usually
only editable by the root user.

See advisory page for additional details.

How can I search for `Pages` only?

It seems that there is only one implementation of filter_by_databases. Is there any need to add an implementation for filter_by_pages?

BTW, the API list_databases is departed, I got a 400 error when I use it.

Search Assumes Database Response

Description

The search endpoint is the generic way to look for a particular resource within a Notion organization. Currently, the client is returning a Result<ListResponse<Database>, NotionApiClientError>. This makes an assumption that it is a Database when it could be a Page.

Documentation

In the API Reference, there are two results in the payload. The first contains the assumed object: database but the second has object: page.

Current Response

The client gives an Error when the result contains a Page:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("missing field `title`", line: 1, column: 545)'

Expected Behavior

That you can successfully retrieve Database and Page objects via the search endpoint.

Deserialization error with number property

I'm getting an error when using search():

JsonParseError {
    source: Error("missing field `format`", line: 1, column: 1425),
}

My code:

use notion::models::search::NotionSearch;
use notion::NotionApi;
use std::env;

#[tokio::main]
async fn main() {
    let notion_api = NotionApi::new(env::var("NOTION_API_TOKEN").unwrap()).unwrap();
    let query: NotionSearch = {
        NotionSearch::Query(String::from("Movie Collection"))
    };
    let result = notion_api.search(query).await;
    match result {
        Ok(resp) => println!("{:#?}", resp),
        Err(err) => println!("{:#?}", err),
    }
}

Saved JSON from curl:

{
  "object": "list",
  "results": [
    {
      "object": "database",
      "id": "58be2827-5ca0-4cc4-85a8-ff656911df67",
      "created_time": "2021-03-07T19:20:00.000Z",
      "last_edited_time": "2021-07-11T22:04:00.000Z",
      "title": [
        {
          "type": "text",
          "text": { "content": "Movie Collection", "link": null },
          "annotations": {
            "bold": false,
            "italic": false,
            "strikethrough": false,
            "underline": false,
            "code": false,
            "color": "default"
          },
          "plain_text": "Movie Collection",
          "href": null
        }
      ],
      "properties": {
        "Watched": { "id": "<dji", "type": "checkbox", "checkbox": {} },
        "Cover": { "id": "VWBk", "type": "files", "files": {} },
        "Type": {
          "id": "]iu{",
          "type": "select",
          "select": {
            "options": [
              {
                "id": "522ab335-108c-4a92-a2d6-0aeee7b946c8",
                "name": "Blu-Ray",
                "color": "blue"
              },
              {
                "id": "12f11180-47bd-4c36-abb8-c84c35ade60c",
                "name": "Digital",
                "color": "green"
              }
            ]
          }
        },
        "Year": {
          "id": "jwIv",
          "type": "number",
          "number": { "format": "number" }
        },
        "Director": {
          "id": "~psh",
          "type": "select",
          "select": {
            "options": [
              {
                "id": "d1023a7a-52af-4c2f-aabf-cac75b59e9bd",
                "name": "Hirozaku Kore-eda",
                "color": "yellow"
              },
              {
                "id": "45bd4057-eddc-4bf2-be59-a693f4f81f05",
                "name": "Hayao Miyazaki",
                "color": "pink"
              },
              {
                "id": "a1a2896b-26f0-410b-8205-fda67c9edb99",
                "name": "Doug Liman",
                "color": "orange"
              },
              {
                "id": "f9854b2d-b913-454f-b18c-ce312fa1d9e4",
                "name": "Steven Soderbergh",
                "color": "green"
              }
            ]
          }
        },
        "Title": { "id": "title", "type": "title", "title": {} }
      },
      "parent": {
        "type": "page_id",
        "page_id": "2ffcd525-17b1-4606-93ff-e367eade9e66"
      }
    }
  ],
  "next_cursor": null,
  "has_more": false
}

I'm fairly new to Rust, but it seems like there's a mismatch in the property schema versus what's returned. If I delete this line the code runs successfully (albeit without the number's format):

format: NumberFormat,

Or if I add:

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct NumberFmt {
    format: String
}

and change the line to number: NumberFmt that also works, this time with the number's format as a string. I couldn't get it to work with the existing NumberFormat enum.

Mentions to in text cause parsing to fail.

Hello!

As title says, any mention to a page or database will output the following error:
Error parsing json response: missing field 'created_time'

Mentioning users works fine.

Steps to reproduce: create a database, create an item that is (or contains) a mention in title (or any created text field).

Hope it's an easy fix to merge whenever u have some free time :)

RUSTSEC-2020-0071: Potential segfault in the time crate

Potential segfault in the time crate

Details
Package time
Version 0.1.43
URL time-rs/time#293
Date 2020-11-18
Patched versions >=0.2.23
Unaffected versions =0.2.0,=0.2.1,=0.2.2,=0.2.3,=0.2.4,=0.2.5,=0.2.6

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

The affected functions from time 0.2.7 through 0.2.22 are:

  • time::UtcOffset::local_offset_at
  • time::UtcOffset::try_local_offset_at
  • time::UtcOffset::current_local_offset
  • time::UtcOffset::try_current_local_offset
  • time::OffsetDateTime::now_local
  • time::OffsetDateTime::try_now_local

The affected functions in time 0.1 (all versions) are:

  • at
  • at_utc
  • now

Non-Unix targets (including Windows and wasm) are unaffected.

Patches

Pending a proper fix, the internal method that determines the local offset has been modified to always return None on the affected operating systems. This has the effect of returning an Err on the try_* methods and UTC on the non-try_* methods.

Users and library authors with time in their dependency tree should perform cargo update, which will pull in the updated, unaffected code.

Users of time 0.1 do not have a patch and should upgrade to an unaffected version: time 0.2.23 or greater or the 0.3 series.

Workarounds

No workarounds are known.

References

time-rs/time#293

See advisory page for additional details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.