2.2.0 • Published 1 month ago

@sota1235/notion-sdk-js-helper v2.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

notion-sdk-js-helper npm version

Helper for makenotion/notion-sdk-js.

Feature

  • Type safe helper to build JSON of blocks.

You can see example codes on this page.

Requirement

Usage

Without this library, when you want to create new page.

import { Client } from '@notionhq/client';

const client = new Client({
  auth: 'YOUR_NOTION_API_TOKEN',
});

await client.pages.create({
  parent: {
    databse_id: 'DATABASE_ID',
  },
  properties: {},
  children: [
    {
      type: 'heading_1',
      heading_1: {
        rich_text: [
          {
            type: 'text',
            text: {
              content: 'Section1',
            },
          },
        ],
      },
    },
    {
      type: 'paragraph',
      paragraph: {
        rich_text: [
          {
            type: 'text',
            text: {
              content: 'I am ',
            },
          },
          {
            type: 'text',
            text: {
              content: 'engineer',
            },
            annotations: {
              bold: true,
            },
          },
        ],
      },
    },
  ],
});

With this library.

import { BlockObjects, RichTextObjects, CustomTypes } from '@sota1235/notion-sdk-js-helper';
import { Client } from '@notionhq/client';

const {
  heading1,
  paragraph,
} = BlockObjects;

const client = new Client({
  auth: 'YOUR_NOTION_API_TOKEN',
});

// Use helper methods when create page
await client.pages.create({
  parent: {
    databse_id: 'DATABASE_ID',
  },
  properties: {},
  children: [
    heading1('Section 1'),
    paragraph([
      RichTextObjects.richText('I am '),
      RichTextObjects.richText('engineer', {
        bold: true,
      }),
    ]),
  ],
});

You can also use this library when fetching data.

// Use custom types as you like when fetching data
const { results } = await client.blocks.children.list({
  block_id: 'PAGE_ID',
});
const heading1Data = results[0].heading_1 as CustomTypes.NotionBlock<'heading_1'>['heading_1'];

Install

npm i -S @sota1235/notion-sdk-js-helper@latest

Licence

This software is released under the MIT License, see LICENSE.txt.

Author

@sota1235

2.2.0

1 month ago

2.1.1

5 months ago

2.1.0

6 months ago

2.0.0

6 months ago

1.0.0

11 months ago

0.1.0

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago