n8n/packages/nodes-base/nodes/Notion/Blocks.ts

581 lines
11 KiB
TypeScript
Raw Normal View History

import { IDisplayOptions, INodeProperties } from 'n8n-workflow';
const colors = [
{
name: 'Default',
value: 'default',
},
{
name: 'Gray',
value: 'gray',
},
{
name: 'Brown',
value: 'brown',
},
{
name: 'Orange',
value: 'orange',
},
{
name: 'Yellow',
value: 'yellow',
},
{
name: 'Green',
value: 'green',
},
{
name: 'Blue',
value: 'blue',
},
{
name: 'Purple',
value: 'purple',
},
{
name: 'Pink',
value: 'pink',
},
{
name: 'Red',
value: 'red',
},
{
name: 'Gray Background',
value: 'gray_background',
},
{
name: 'Brown Background',
value: 'brown_background',
},
{
name: 'Orange Background',
value: 'orange_background',
},
{
name: 'Yellow Background',
value: 'yellow_background',
},
{
name: 'Green Background',
value: 'green_background',
},
{
name: 'Blue Background',
value: 'blue_background',
},
{
name: 'Purple Background',
value: 'purple_background',
},
{
name: 'Pink Background',
value: 'pink_background',
},
{
name: 'Red Background',
value: 'red_background',
},
];
const annotation: INodeProperties[] = [
{
displayName: 'Annotations',
name: 'annotationUi',
type: 'collection',
placeholder: 'Add Annotation',
default: {},
options: [
{
displayName: 'Bold',
name: 'bold',
type: 'boolean',
default: false,
description: 'Whether the text is bolded',
},
{
displayName: 'Italic',
name: 'italic',
type: 'boolean',
default: false,
description: 'Whether the text is italicized',
},
{
displayName: 'Strikethrough',
name: 'strikethrough',
type: 'boolean',
default: false,
description: 'Whether the text is struck through',
},
{
displayName: 'Underline',
name: 'underline',
type: 'boolean',
default: false,
description: 'Whether the text is underlined',
},
{
displayName: 'Code',
name: 'code',
type: 'boolean',
default: false,
description: 'Whether the text is code style',
},
{
displayName: 'Color',
name: 'color',
type: 'options',
options: colors,
default: '',
description: 'Color of the text',
},
],
description: 'All annotations that apply to this rich text',
},
];
const typeMention: INodeProperties[] = [
{
displayName: 'Type',
name: 'mentionType',
type: 'options',
displayOptions: {
show: {
textType: ['mention'],
},
},
options: [
{
name: 'Database',
value: 'database',
},
{
name: 'Date',
value: 'date',
},
{
name: 'Page',
value: 'page',
},
{
name: 'User',
value: 'user',
},
],
default: '',
description:
'An inline mention of a user, page, database, or date. In the app these are created by typing @ followed by the name of a user, page, database, or a date.',
},
{
refactor: Apply more `eslint-plugin-n8n-nodes-base` autofixable rules (#3432) * :zap: Update `lintfix` script * :shirt: Remove unneeded lint exceptions * :shirt: Run baseline `lintfix` * :shirt: Apply `node-param-description-miscased-url` (#3441) * :shirt: Apply `rule node-param-placeholder-miscased-id` (#3443) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-name-wrong-for-upsert` (#3446) * :shirt: Apply `node-param-min-value-wrong-for-limit` (#3442) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * Apply `node-param-display-name-wrong-for-dynamic-options` (#3454) * :hammer: fix * :zap: Fix `Assigned To` fields Co-authored-by: Michael Kret <michael.k@radency.com> * :shirt: Apply `rule node-param-default-wrong-for-number` (#3453) * :shirt: Apply `node-param-default-wrong-for-string` (#3452) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * Apply `node-param-display-name-miscased` (#3449) * :hammer: fix * :hammer: exceptions * :zap: review fixes * :shirt: Apply `node-param-description-lowercase-first-char` (#3451) * :zap: fix * :zap: review fixes * :zap: fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-wrong-for-dynamic-options` (#3456) * Rule working as intended * Add rule * :fire: Remove repetitions * :shirt: Add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Small fix for `node-param-description-wrong-for-dynamic-options` * :shirt: Apply `node-param-default-wrong-for-fixed-collection` (#3460) * :shirt: Apply `node-param-description-line-break-html-tag` (#3462) * :shirt: Run baseline `lintfix` * :shirt: Apply `node-param-options-type-unsorted-items` (#3459) * :zap: fix * :hammer: exceptions * Add exception for Salesmate and Zoom Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :zap: Restore `lintfix` command Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: brianinoa <54530642+brianinoa@users.noreply.github.com>
2022-06-03 10:23:49 -07:00
displayName: 'User Name or ID',
name: 'user',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
displayOptions: {
show: {
mentionType: ['user'],
},
},
default: '',
description:
'The ID of the user being mentioned. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'Page ID',
name: 'page',
type: 'string',
displayOptions: {
show: {
mentionType: ['page'],
},
},
default: '',
description: 'The ID of the page being mentioned',
},
{
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 04:37:52 -08:00
displayName: 'Database',
name: 'database',
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 04:37:52 -08:00
type: 'resourceLocator',
default: { mode: 'list', value: '' },
modes: [
{
displayName: 'Database',
name: 'list',
type: 'list',
placeholder: 'Select a Database...',
typeOptions: {
searchListMethod: 'getDatabases',
searchable: true,
},
},
{
displayName: 'Link',
name: 'url',
type: 'string',
placeholder:
'https://www.notion.so/0fe2f7de558b471eab07e9d871cdf4a9?v=f2d424ba0c404733a3f500c78c881610',
validation: [
{
type: 'regex',
properties: {
regex:
'(?:https|http)://www.notion.so/(?:[a-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}).*',
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 04:37:52 -08:00
errorMessage: 'Not a valid Notion Database URL',
},
},
],
extractValue: {
type: 'regex',
regex:
'(?:https|http)://www.notion.so/(?:[a-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})',
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 04:37:52 -08:00
},
},
{
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]*',
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 04:37:52 -08:00
errorMessage: 'Not a valid Notion Database 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: {
mentionType: ['database'],
},
},
description: 'The Notion Database being mentioned',
},
{
displayName: 'Range',
name: 'range',
displayOptions: {
show: {
mentionType: ['date'],
},
},
type: 'boolean',
default: false,
refactor: Apply more `eslint-plugin-n8n-nodes-base` rules (#3534) * :zap: Update `lintfix` script * :zap: Run baseline `lintfix` * :fire: Remove unneeded exceptions (#3538) * :fire: Remove exceptions for `node-param-default-wrong-for-simplify` * :fire: Remove exceptions for `node-param-placeholder-miscased-id` * :zap: Update version * :shirt: Apply `node-param-placeholder-missing` (#3542) * :shirt: Apply `filesystem-wrong-cred-filename` (#3543) * :shirt: Apply `node-param-description-missing-from-dynamic-options` (#3545) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-class-description-empty-string` (#3546) * :shirt: Apply `node-class-description-icon-not-svg` (#3548) * :shirt: Apply `filesystem-wrong-node-filename` (#3549) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Expand lintings to credentials (#3550) * :shirt: Apply `node-param-multi-options-type-unsorted-items` (#3552) * :zap: fix * :zap: Minor fixes Co-authored-by: Michael Kret <michael.k@radency.com> * :shirt: Apply `node-param-description-wrong-for-dynamic-multi-options` (#3541) * :zap: Add new lint rule, node-param-description-wrong-for-dynamic-multi-options * :zap: Fix with updated linting rules * :zap: Minor fixes Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-boolean-without-whether` (#3553) * :zap: fix * Update packages/nodes-base/nodes/Clockify/ProjectDescription.ts Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply node-param-display-name-wrong-for-dynamic-multi-options (#3537) * :shirt: Add exceptions * :shirt: Add exception * :pencil2: Alphabetize rules * :zap: Restore `lintfix` command Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: brianinoa <54530642+brianinoa@users.noreply.github.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com>
2022-06-20 07:54:01 -07:00
description: 'Whether or not you want to define a date range',
},
{
displayName: 'Date',
name: 'date',
displayOptions: {
show: {
mentionType: ['date'],
range: [false],
},
},
type: 'dateTime',
default: '',
description: 'An ISO 8601 format date, with optional time',
},
{
displayName: 'Date Start',
name: 'dateStart',
displayOptions: {
show: {
mentionType: ['date'],
range: [true],
},
},
type: 'dateTime',
default: '',
description: 'An ISO 8601 format date, with optional time',
},
{
displayName: 'Date End',
name: 'dateEnd',
displayOptions: {
show: {
range: [true],
mentionType: ['date'],
},
},
type: 'dateTime',
default: '',
description:
'An ISO 8601 formatted date, with optional time. Represents the end of a date range.',
},
];
const typeEquation: INodeProperties[] = [
{
displayName: 'Expression',
name: 'expression',
type: 'string',
displayOptions: {
show: {
textType: ['equation'],
},
},
default: '',
},
];
const typeText: INodeProperties[] = [
{
displayName: 'Text',
name: 'text',
displayOptions: {
show: {
textType: ['text'],
},
},
type: 'string',
default: '',
description:
"Text content. This field contains the actual content of your text and is probably the field you'll use most often.",
},
{
displayName: 'Is Link',
name: 'isLink',
displayOptions: {
show: {
textType: ['text'],
},
},
type: 'boolean',
default: false,
},
{
displayName: 'Text Link',
name: 'textLink',
displayOptions: {
show: {
textType: ['text'],
isLink: [true],
},
},
type: 'string',
default: '',
description: 'The URL that this link points to',
},
];
export const text = (displayOptions: IDisplayOptions): INodeProperties[] =>
[
{
displayName: 'Text',
name: 'text',
placeholder: 'Add Text',
type: 'fixedCollection',
default: {},
typeOptions: {
multipleValues: true,
},
displayOptions,
options: [
{
name: 'text',
displayName: 'Text',
values: [
{
displayName: 'Type',
name: 'textType',
type: 'options',
options: [
{
name: 'Equation',
value: 'equation',
},
{
name: 'Mention',
value: 'mention',
},
{
name: 'Text',
value: 'text',
},
],
default: 'text',
},
...typeText,
...typeMention,
...typeEquation,
...annotation,
],
},
],
description: 'Rich text in the block',
},
] as INodeProperties[];
const todo = (type: string): INodeProperties[] =>
[
{
displayName: 'Checked',
name: 'checked',
type: 'boolean',
default: false,
displayOptions: {
show: {
type: [type],
},
},
description: 'Whether the to_do is checked or not',
},
] as INodeProperties[];
const title = (type: string): INodeProperties[] =>
[
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
displayOptions: {
show: {
type: [type],
},
},
description: 'Plain text of page title',
},
] as INodeProperties[];
const richText = (displayOptions: IDisplayOptions): INodeProperties[] => [
{
displayName: 'Rich Text',
name: 'richText',
type: 'boolean',
displayOptions,
default: false,
},
];
const textContent = (displayOptions: IDisplayOptions): INodeProperties[] => [
{
displayName: 'Text',
name: 'textContent',
type: 'string',
displayOptions,
default: '',
},
];
const block = (blockType: string): INodeProperties[] => {
const data: INodeProperties[] = [];
switch (blockType) {
case 'to_do':
data.push(...todo(blockType));
data.push(
...richText({
show: {
type: [blockType],
},
}),
);
data.push(
...textContent({
show: {
type: [blockType],
richText: [false],
},
}),
);
data.push(
...text({
show: {
type: [blockType],
richText: [true],
},
}),
);
break;
case 'child_page':
data.push(...title(blockType));
break;
default:
data.push(
...richText({
show: {
type: [blockType],
},
}),
);
data.push(
...textContent({
show: {
type: [blockType],
richText: [false],
},
}),
);
data.push(
...text({
show: {
type: [blockType],
richText: [true],
},
}),
);
break;
}
return data;
};
export const blocks = (resource: string, operation: string): INodeProperties[] => [
{
displayName: 'Blocks',
name: 'blockUi',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
displayOptions: {
show: {
resource: [resource],
operation: [operation],
},
},
placeholder: 'Add Block',
options: [
{
name: 'blockValues',
displayName: 'Block',
values: [
{
displayName: 'Type Name or ID',
name: 'type',
type: 'options',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getBlockTypes',
},
default: 'paragraph',
},
...block('paragraph'),
...block('heading_1'),
...block('heading_2'),
...block('heading_3'),
...block('toggle'),
...block('to_do'),
...block('child_page'),
...block('bulleted_list_item'),
...block('numbered_list_item'),
],
},
],
},
];