Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Notion (Beta) Node): Use resource locator component for database and page parameters #4340

Merged
merged 42 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b587e57
use resource locator component for database -> get (Notion V1/V2)
maspio Oct 13, 2022
1c6c435
Merge branch 'master' into n8n-4972-notion-node-roll-out-resource-loc…
maspio Oct 14, 2022
1aca7a2
getDatabases search function for V1/V2 with url
maspio Oct 14, 2022
7eed932
updated database get list placeholder
maspio Oct 14, 2022
394f7a3
get database RLC by url - regex support optional workspace domain names
maspio Oct 14, 2022
b10edeb
fixed linting error
maspio Oct 14, 2022
bdcfdd0
listSearch getDatabases support filter query
maspio Oct 14, 2022
43fc9bb
Merge branch 'master' into n8n-4972-notion-node-roll-out-resource-loc…
maspio Oct 14, 2022
dc0ca3a
support extractValue in getCurrentNodeParameter for RLC
maspio Oct 17, 2022
c1491ed
RLC for database page create/getAll operation
maspio Oct 17, 2022
d431130
RLC for database get operation support "By ID" with optional v param.
maspio Oct 17, 2022
b220304
use RLC in append blocks operation
maspio Oct 18, 2022
40834e7
use RLC in NotionTrigger.nodes.ts
maspio Oct 18, 2022
fe6dde9
removed unused loadOptions getDatabases
maspio Oct 18, 2022
1124ca2
support database RLC in createPage/createDbPage operation
maspio Oct 18, 2022
cdb80e8
page create operation use RLC for parent page param
maspio Oct 18, 2022
c8cc23a
page archive operation use RLC for page param
maspio Oct 18, 2022
5b04d0b
removed unused imports
maspio Oct 18, 2022
19f2d21
fixed missing extractPageId in NotionV1.node.ts
maspio Oct 18, 2022
59430a4
database page get operation use RLC for page param
maspio Oct 19, 2022
ccecf8c
database page update operation use RLC for page param
maspio Oct 19, 2022
227897c
block getAll children operation use RLC for page param
maspio Oct 19, 2022
a1598f4
block append operation use RLC for block param
maspio Oct 19, 2022
b92f971
support databaseId with optional '-' characters
maspio Oct 25, 2022
66247d4
support blockId with optional '-' characters
maspio Oct 25, 2022
16a480a
support pageId with optional '-' characters
maspio Oct 25, 2022
b6cb545
improved RLC descriptions and hints
maspio Oct 25, 2022
b21337b
NotionTrigger node support databseId with optional '-' characters
maspio Oct 25, 2022
775d226
stricter RLC by ID regex rules for uuids
maspio Oct 26, 2022
afa9c15
stricter RLC by URL regex rules for uuids
maspio Oct 26, 2022
139913d
stricter RLC by ID regex rules for uuids (support max length)
maspio Oct 26, 2022
bc17dcb
RLC regex from URL allow both http and https
maspio Oct 27, 2022
2e5ce23
RLC by ID only allow uuid v4 with optional dash
maspio Oct 28, 2022
f4c904f
removed RLC from URL hint "Use Notion's copy link..."
maspio Oct 28, 2022
41aef10
RLC from URL only allow uuid v4
maspio Oct 28, 2022
cebc023
DB Status Column: Support Simplify Properties
maspio Nov 8, 2022
5f68342
Notion Credentials: Support custom Notion-Version header
maspio Nov 8, 2022
86dea30
DB Status Column: Support DB Page Create/Update
maspio Nov 8, 2022
302be4d
DB Status Column: Support DB Page GetMany Filters
maspio Nov 8, 2022
9f694cf
removed unused paginationToken args
maspio Nov 9, 2022
70eb24f
Merge branch 'master' into n8n-4972-notion-node-roll-out-resource-loc…
maspio Nov 9, 2022
850eb5c
Database Get: RLC by URL improve validation error message
maspio Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2676,14 +2676,33 @@ export function getLoadOptionsFunctions(
},
getCurrentNodeParameter: (
parameterPath: string,
options?: IGetNodeParameterOptions,
): NodeParameterValueType | object | undefined => {
const nodeParameters = additionalData.currentNodeParameters;

if (parameterPath.charAt(0) === '&') {
parameterPath = `${path.split('.').slice(1, -1).join('.')}.${parameterPath.slice(1)}`;
}

return get(nodeParameters, parameterPath);
let returnData = get(nodeParameters, parameterPath);

// This is outside the try/catch because it throws errors with proper messages
if (options?.extractValue) {
const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType === undefined) {
throw new Error(
`Node type "${node.type}" is not known so can not return parameter value!`,
);
}
returnData = extractValue(
returnData,
parameterPath,
node,
nodeType,
) as NodeParameterValueType;
}

return returnData;
},
getCurrentNodeParameters: (): INodeParameters | undefined => {
return additionalData.currentNodeParameters;
Expand Down
104 changes: 94 additions & 10 deletions packages/nodes-base/nodes/Notion/BlockDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,122 @@ export const blockFields: INodeProperties[] = [
/* block:append */
/* -------------------------------------------------------------------------- */
{
displayName: 'Block ID or Link',
displayName: 'Block',
name: 'blockId',
type: 'string',
default: '',
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 Block URL from Notion's 'copy link' functionality (or just the ID contained within the URL). Pages are also blocks, so you can use a page URL/ID here too.",
description: "The Notion Block to append blocks to",
},
...blocks('block', 'append'),
/* -------------------------------------------------------------------------- */
/* block:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Block ID or Link',
displayName: 'Block',
name: 'blockId',
type: 'string',
default: '',
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 Block URL from Notion's 'copy link' functionality (or just the ID contained within the URL). Pages are also blocks, so you can use a page URL/ID here too.",
description: "The Notion Block to get all children from",
},
{
displayName: 'Return All',
Expand Down
65 changes: 57 additions & 8 deletions packages/nodes-base/nodes/Notion/Blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,69 @@ const typeMention: INodeProperties[] = [
description: 'The ID of the page being mentioned',
},
{
displayName: 'Database Name or ID',
displayName: 'Database',
name: 'database',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getDatabases',
},
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}).*',
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})',
},
},
{
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 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'],
},
},
default: '',
description:
'The ID of the database being mentioned. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description: "The Notion Database being mentioned",
},
{
displayName: 'Range',
Expand Down
63 changes: 58 additions & 5 deletions packages/nodes-base/nodes/Notion/DatabaseDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,73 @@ export const databaseFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* database:get */
/* -------------------------------------------------------------------------- */

{
displayName: 'Database Link or ID',
displayName: 'Database',
name: 'databaseId',
type: 'string',
default: '',
type: 'resourceLocator',
default: { mode: 'list', value: '' },
required: true,
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}).*',
errorMessage: 'Not a valid Notion Database URL. Hint: use the URL of the database itself, not a page containing it.',
},
},
],
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})',
},
},
{
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 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: {
resource: ['database'],
operation: ['get'],
},
},
description:
"The Database URL from Notion's 'copy link' functionality (or just the ID contained within the URL)",
description: "The Notion Database to get",
},
/* -------------------------------------------------------------------------- */
/* database:getAll */
Expand Down
Loading