n8n/packages/nodes-base/nodes/Notion/BlockDescription.ts
Marcus 277b6b73c3
feat(Notion (Beta) Node): Use resource locator component for database and page parameters (#4340)
* use resource locator component for database -> get (Notion V1/V2)

* getDatabases search function for V1/V2 with url

* updated database get list placeholder

* get database RLC by url - regex support optional workspace domain names

* fixed linting error

* listSearch getDatabases support filter query

* support extractValue in getCurrentNodeParameter for RLC

* RLC for database page create/getAll operation

* RLC for database get operation support "By ID" with optional v param.

* use RLC in append blocks operation

* use RLC in NotionTrigger.nodes.ts

* removed unused loadOptions getDatabases

* support database RLC in createPage/createDbPage operation

* page create operation use RLC for parent page param

* page archive operation use RLC for page param

* removed unused imports

* fixed missing extractPageId in NotionV1.node.ts

* database page get operation use RLC for page param

* database page update operation use RLC for page param

* block getAll children operation use RLC for page param

* block append operation use RLC for block param

* support databaseId with optional '-' characters

* support blockId with optional '-' characters

* support pageId with optional '-' characters

* improved RLC descriptions and hints

* NotionTrigger node support databseId with optional '-' characters

* stricter RLC by ID regex rules for uuids

* stricter RLC by URL regex rules for uuids

* stricter RLC by ID regex rules for uuids (support max length)

* RLC regex from URL allow both http and https

* RLC by ID only allow uuid v4 with optional dash

* removed RLC from URL hint "Use Notion's copy link..."

* RLC from URL only allow uuid v4

* DB Status Column: Support Simplify Properties

* Notion Credentials: Support custom Notion-Version header

Use latest Notion-Version 2022-02-22 if not set

* DB Status Column: Support DB Page Create/Update

* DB Status Column: Support DB Page GetMany Filters

* removed unused paginationToken args

* Database Get: RLC by URL improve validation error message
2022-11-11 13:37:52 +01:00

189 lines
4.9 KiB
TypeScript

import { INodeProperties } from 'n8n-workflow';
import { blocks } from './Blocks';
export const blockOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['block'],
},
},
options: [
{
name: 'Append After',
value: 'append',
description: 'Append a block',
action: 'Append a block',
},
{
// eslint-disable-next-line n8n-nodes-base/node-param-option-name-wrong-for-get-many
name: 'Get Child Blocks',
value: 'getAll',
description: 'Get many child blocks',
action: 'Get many child blocks',
},
],
default: 'append',
},
];
export const blockFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* block:append */
/* -------------------------------------------------------------------------- */
{
displayName: 'Block',
name: 'blockId',
type: 'resourceLocator',
default: { mode: 'url', value: '' },
required: true,
modes: [
{
displayName: 'Link',
name: 'url',
type: 'string',
placeholder:
'https://www.notion.so/My-Page-b4eeb113e118403ba450af65ac25f0b9',
validation: [
{
type: 'regex',
properties: {
regex:
'(?:https|http):\/\/www.notion.so\/(?:[a-z0-9\-]{2,}\/)?(?:[a-zA-Z0-9\-]{2,}-)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}).*',
errorMessage: 'Not a valid Notion Block URL',
},
},
],
extractValue: {
type: 'regex',
regex: '(?:https|http):\/\/www.notion.so\/(?:[a-z0-9\-]{2,}\/)?(?:[a-zA-Z0-9\-]{2,}-)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})',
},
},
{
displayName: 'ID',
name: 'id',
type: 'string',
placeholder: 'ab1545b247fb49fa92d6f4b49f4d8116',
validation: [
{
type: 'regex',
properties: {
regex: '^(([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})|([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}))[ \t]*',
errorMessage: 'Not a valid Notion Block ID',
},
},
],
extractValue: {
type: 'regex',
regex: '^([0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12})',
},
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
},
],
displayOptions: {
show: {
resource: ['block'],
operation: ['append'],
},
},
description: "The Notion Block to append blocks to",
},
...blocks('block', 'append'),
/* -------------------------------------------------------------------------- */
/* block:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Block',
name: 'blockId',
type: 'resourceLocator',
default: { mode: 'url', value: '' },
required: true,
modes: [
{
displayName: 'Link',
name: 'url',
type: 'string',
placeholder:
'https://www.notion.so/My-Page-b4eeb113e118403ba450af65ac25f0b9',
validation: [
{
type: 'regex',
properties: {
regex:
'(?:https|http):\/\/www.notion.so\/(?:[a-z0-9\-]{2,}\/)?(?:[a-zA-Z0-9\-]{2,}-)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}).*',
errorMessage: 'Not a valid Notion Block URL',
},
},
],
extractValue: {
type: 'regex',
regex: '(?:https|http):\/\/www.notion.so\/(?:[a-z0-9\-]{2,}\/)?(?:[a-zA-Z0-9\-]{2,}-)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})',
},
},
{
displayName: 'ID',
name: 'id',
type: 'string',
placeholder: 'ab1545b247fb49fa92d6f4b49f4d8116',
validation: [
{
type: 'regex',
properties: {
regex: '^(([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})|([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}))[ \t]*',
errorMessage: 'Not a valid Notion Block ID',
},
},
],
extractValue: {
type: 'regex',
regex: '^([0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12})',
},
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
},
],
displayOptions: {
show: {
resource: ['block'],
operation: ['getAll'],
},
},
description: "The Notion Block to get all children from",
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['block'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['block'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 50,
description: 'Max number of results to return',
},
];