2023-01-27 03:22:44 -08:00
import type { INodeProperties } from 'n8n-workflow' ;
2021-05-20 14:31:23 -07:00
2022-08-17 08:50:24 -07:00
import { blocks } from './Blocks' ;
2021-05-20 14:31:23 -07:00
2024-03-13 04:57:17 -07:00
//RLC with fixed regex for blockId
const blockIdRLC : INodeProperties = {
displayName : 'Block' ,
name : 'blockId' ,
type : 'resourceLocator' ,
default : { mode : 'url' , value : '' } ,
required : true ,
modes : [
{
displayName : 'Link' ,
name : 'url' ,
type : 'string' ,
placeholder :
'e.g. https://www.notion.so/Block-Test-88888ccc303e4f44847f27d24bd7ad8e?pvs=4#c44444444444bbbbb4d32fdfdd84e' ,
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:\\/\\/www\\.notion\\.so\\/.+\\?pvs=[0-9]+#([a-f0-9]{2,})',
// },
} ,
{
displayName : 'ID' ,
name : 'id' ,
type : 'string' ,
placeholder : 'e.g. ab1545b247fb49fa92d6f4b49f4d8116' ,
validation : [
{
type : 'regex' ,
properties : {
regex : '[a-f0-9]{2,}' ,
errorMessage : 'Not a valid Notion Block ID' ,
} ,
} ,
] ,
} ,
] ,
description :
"The Notion Block to get all children from, when using 'By URL' mode make sure to use the URL of the block itself, you can find it in block parameters in Notion under 'Copy link to block'" ,
} ;
2022-07-04 02:12:08 -07:00
export const blockOperations : INodeProperties [ ] = [
2021-05-20 14:31:23 -07:00
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2021-05-20 14:31:23 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'block' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
options : [
{
2021-12-29 14:23:22 -08:00
name : 'Append After' ,
2021-05-20 14:31:23 -07:00
value : 'append' ,
description : 'Append a block' ,
2022-07-10 13:50:51 -07:00
action : 'Append a block' ,
2021-05-20 14:31:23 -07:00
} ,
{
2022-09-07 07:51:14 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-option-name-wrong-for-get-many
2021-12-29 14:23:22 -08:00
name : 'Get Child Blocks' ,
2021-05-20 14:31:23 -07:00
value : 'getAll' ,
2022-09-13 03:36:36 -07:00
description : 'Get many child blocks' ,
action : 'Get many child blocks' ,
2021-05-20 14:31:23 -07:00
} ,
] ,
default : 'append' ,
} ,
2022-07-04 02:12:08 -07:00
] ;
2021-05-20 14:31:23 -07:00
2022-11-09 02:26:13 -08:00
export const blockFields : INodeProperties [ ] = [
2021-05-20 14:31:23 -07:00
/* -------------------------------------------------------------------------- */
/* block:append */
/* -------------------------------------------------------------------------- */
{
2022-11-11 04:37:52 -08:00
displayName : 'Block' ,
2021-05-20 14:31:23 -07:00
name : 'blockId' ,
2022-11-11 04:37:52 -08:00
type : 'resourceLocator' ,
default : { mode : 'url' , value : '' } ,
2021-05-20 14:31:23 -07:00
required : true ,
2022-11-11 04:37:52 -08:00
modes : [
{
displayName : 'Link' ,
name : 'url' ,
type : 'string' ,
2022-11-22 04:43:28 -08:00
placeholder : 'https://www.notion.so/My-Page-b4eeb113e118403ba450af65ac25f0b9' ,
2022-11-11 04:37:52 -08:00
validation : [
{
type : 'regex' ,
properties : {
regex :
2022-11-22 04:43:28 -08:00
'(?: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}).*' ,
2022-11-11 04:37:52 -08:00
errorMessage : 'Not a valid Notion Block URL' ,
} ,
} ,
] ,
extractValue : {
type : 'regex' ,
2022-11-22 04:43:28 -08:00
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})' ,
2022-11-11 04:37:52 -08:00
} ,
} ,
{
displayName : 'ID' ,
name : 'id' ,
type : 'string' ,
placeholder : 'ab1545b247fb49fa92d6f4b49f4d8116' ,
validation : [
{
type : 'regex' ,
properties : {
2022-11-22 04:43:28 -08:00
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]*' ,
2022-11-11 04:37:52 -08:00
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, "")}}' ,
} ,
] ,
2021-05-20 14:31:23 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'block' ] ,
operation : [ 'append' ] ,
2021-05-20 14:31:23 -07:00
} ,
2024-03-13 04:57:17 -07:00
hide : {
'@version' : [ { _cnd : { gte : 2.2 } } ] ,
} ,
2021-05-20 14:31:23 -07:00
} ,
2022-11-22 04:43:28 -08:00
description : 'The Notion Block to append blocks to' ,
2021-05-20 14:31:23 -07:00
} ,
2024-03-13 04:57:17 -07:00
{
. . . blockIdRLC ,
displayOptions : {
show : {
resource : [ 'block' ] ,
operation : [ 'append' ] ,
'@version' : [ { _cnd : { gte : 2.2 } } ] ,
} ,
} ,
} ,
2021-05-20 14:31:23 -07:00
. . . blocks ( 'block' , 'append' ) ,
/* -------------------------------------------------------------------------- */
/* block:getAll */
/* -------------------------------------------------------------------------- */
{
2022-11-11 04:37:52 -08:00
displayName : 'Block' ,
2021-05-20 14:31:23 -07:00
name : 'blockId' ,
2022-11-11 04:37:52 -08:00
type : 'resourceLocator' ,
default : { mode : 'url' , value : '' } ,
2021-05-20 14:31:23 -07:00
required : true ,
2022-11-11 04:37:52 -08:00
modes : [
{
displayName : 'Link' ,
name : 'url' ,
type : 'string' ,
2022-11-22 04:43:28 -08:00
placeholder : 'https://www.notion.so/My-Page-b4eeb113e118403ba450af65ac25f0b9' ,
2022-11-11 04:37:52 -08:00
validation : [
{
type : 'regex' ,
properties : {
regex :
2022-11-22 04:43:28 -08:00
'(?: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}).*' ,
2022-11-11 04:37:52 -08:00
errorMessage : 'Not a valid Notion Block URL' ,
} ,
} ,
] ,
extractValue : {
type : 'regex' ,
2022-11-22 04:43:28 -08:00
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})' ,
2022-11-11 04:37:52 -08:00
} ,
} ,
{
displayName : 'ID' ,
name : 'id' ,
type : 'string' ,
placeholder : 'ab1545b247fb49fa92d6f4b49f4d8116' ,
validation : [
{
type : 'regex' ,
properties : {
2022-11-22 04:43:28 -08:00
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]*' ,
2022-11-11 04:37:52 -08:00
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, "")}}' ,
} ,
] ,
2021-05-20 14:31:23 -07:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'block' ] ,
operation : [ 'getAll' ] ,
2021-05-20 14:31:23 -07:00
} ,
2024-03-13 04:57:17 -07:00
hide : {
'@version' : [ { _cnd : { gte : 2.2 } } ] ,
} ,
2021-05-20 14:31:23 -07:00
} ,
2022-11-22 04:43:28 -08:00
description : 'The Notion Block to get all children from' ,
2021-05-20 14:31:23 -07:00
} ,
2024-03-13 04:57:17 -07:00
{
. . . blockIdRLC ,
displayOptions : {
show : {
resource : [ 'block' ] ,
operation : [ 'getAll' ] ,
'@version' : [ { _cnd : { gte : 2.2 } } ] ,
} ,
} ,
} ,
2021-05-20 14:31:23 -07:00
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'block' ] ,
operation : [ 'getAll' ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
default : false ,
2022-05-06 14:01:25 -07:00
description : 'Whether to return all results or only up to a given limit' ,
2021-05-20 14:31:23 -07:00
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'block' ] ,
operation : [ 'getAll' ] ,
returnAll : [ false ] ,
2021-05-20 14:31:23 -07:00
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 100 ,
} ,
default : 50 ,
2022-05-06 14:01:25 -07:00
description : 'Max number of results to return' ,
2021-05-20 14:31:23 -07:00
} ,
2023-10-06 04:55:44 -07:00
{
displayName : 'Also Fetch Nested Blocks' ,
name : 'fetchNestedBlocks' ,
type : 'boolean' ,
displayOptions : {
show : {
resource : [ 'block' ] ,
operation : [ 'getAll' ] ,
} ,
} ,
default : false ,
} ,
2023-11-27 05:02:57 -08:00
{
displayName : 'Simplify Output' ,
name : 'simplifyOutput' ,
type : 'boolean' ,
displayOptions : {
show : {
resource : [ 'block' ] ,
operation : [ 'getAll' ] ,
} ,
hide : {
'@version' : [ 1 , 2 ] ,
} ,
} ,
default : true ,
} ,
2022-11-09 02:26:13 -08:00
] ;