fix(Notion Node): Allow UUID v8 in notion id checks (#10938)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-09-24 12:38:11 +02:00
committed by GitHub
parent 8db8817851
commit 46beda05f6
9 changed files with 103 additions and 85 deletions

View File

@@ -11,6 +11,12 @@ import moment from 'moment-timezone';
import { notionApiRequest, simplifyObjects } from './shared/GenericFunctions'; import { notionApiRequest, simplifyObjects } from './shared/GenericFunctions';
import { listSearch } from './shared/methods'; import { listSearch } from './shared/methods';
import {
databaseUrlExtractionRegexp,
databaseUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from './shared/constants';
export class NotionTrigger implements INodeType { export class NotionTrigger implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@@ -85,16 +91,14 @@ export class NotionTrigger implements INodeType {
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databaseUrlValidationRegexp,
'(?: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', errorMessage: 'Not a valid Notion Database URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databaseUrlExtractionRegexp,
'(?: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})',
}, },
}, },
{ {
@@ -106,15 +110,14 @@ export class NotionTrigger implements INodeType {
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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', errorMessage: 'Not a valid Notion Database ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },

View File

@@ -23,6 +23,7 @@ import moment from 'moment-timezone';
import { validate as uuidValidate } from 'uuid'; import { validate as uuidValidate } from 'uuid';
import set from 'lodash/set'; import set from 'lodash/set';
import { filters } from './descriptions/Filters'; import { filters } from './descriptions/Filters';
import { blockUrlExtractionRegexp } from './constants';
function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) { function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
if (uuidValidate(value)) return true; if (uuidValidate(value)) return true;
@@ -1152,8 +1153,7 @@ export function extractBlockId(this: IExecuteFunctions, nodeVersion: number, ite
const match = (blockIdRLCData.value as string).match(blockRegex); const match = (blockIdRLCData.value as string).match(blockRegex);
if (match === null) { if (match === null) {
const pageRegex = const pageRegex = new RegExp(blockUrlExtractionRegexp);
/(?: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})/;
const pageMatch = (blockIdRLCData.value as string).match(pageRegex); const pageMatch = (blockIdRLCData.value as string).match(pageRegex);
if (pageMatch === null) { if (pageMatch === null) {

View File

@@ -0,0 +1,15 @@
const notionIdRegexp = '[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}';
export const idExtractionRegexp = `^(${notionIdRegexp})`;
export const idValidationRegexp = `${idExtractionRegexp}.*`;
const baseUrlRegexp = '(?:https|http)://www\\.notion\\.so/(?:[a-z0-9-]{2,}/)?';
export const databaseUrlExtractionRegexp = `${baseUrlRegexp}(${notionIdRegexp})`;
export const databaseUrlValidationRegexp = `${databaseUrlExtractionRegexp}.*`;
export const databasePageUrlExtractionRegexp = `${baseUrlRegexp}(?:[a-zA-Z0-9-]{1,}-)?(${notionIdRegexp})`;
export const databasePageUrlValidationRegexp = `${databasePageUrlExtractionRegexp}.*`;
export const blockUrlExtractionRegexp = `${baseUrlRegexp}(?:[a-zA-Z0-9-]{2,}-)?(${notionIdRegexp})`;
export const blockUrlValidationRegexp = `${blockUrlExtractionRegexp}.*`;

View File

@@ -1,6 +1,12 @@
import type { INodeProperties } from 'n8n-workflow'; import type { INodeProperties } from 'n8n-workflow';
import { blocks } from './Blocks'; import { blocks } from './Blocks';
import {
blockUrlExtractionRegexp,
blockUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';
//RLC with fixed regex for blockId //RLC with fixed regex for blockId
const blockIdRLC: INodeProperties = { const blockIdRLC: INodeProperties = {
@@ -20,15 +26,14 @@ const blockIdRLC: INodeProperties = {
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: blockUrlValidationRegexp,
'(?: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', errorMessage: 'Not a valid Notion Block URL',
}, },
}, },
], ],
// extractValue: { // extractValue: {
// type: 'regex', // type: 'regex',
// regex: 'https:\\/\\/www\\.notion\\.so\\/.+\\?pvs=[0-9]+#([a-f0-9]{2,})', // regex: blockUrlExtractionRegexp,
// }, // },
}, },
{ {
@@ -101,16 +106,14 @@ export const blockFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: blockUrlValidationRegexp,
'(?: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', errorMessage: 'Not a valid Notion Block URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: blockUrlExtractionRegexp,
'(?: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})',
}, },
}, },
{ {
@@ -122,15 +125,14 @@ export const blockFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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', errorMessage: 'Not a valid Notion Block ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },
@@ -176,16 +178,14 @@ export const blockFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: blockUrlValidationRegexp,
'(?: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', errorMessage: 'Not a valid Notion Block URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: blockUrlExtractionRegexp,
'(?: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})',
}, },
}, },
{ {
@@ -197,15 +197,14 @@ export const blockFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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', errorMessage: 'Not a valid Notion Block ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },

View File

@@ -1,4 +1,10 @@
import type { IDisplayOptions, INodeProperties } from 'n8n-workflow'; import type { IDisplayOptions, INodeProperties } from 'n8n-workflow';
import {
databaseUrlExtractionRegexp,
databaseUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';
const colors = [ const colors = [
{ {
@@ -221,16 +227,14 @@ const typeMention: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databaseUrlValidationRegexp,
'(?: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', errorMessage: 'Not a valid Notion Database URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databaseUrlExtractionRegexp,
'(?: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})',
}, },
}, },
{ {
@@ -242,15 +246,14 @@ const typeMention: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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', errorMessage: 'Not a valid Notion Database ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },

View File

@@ -1,4 +1,10 @@
import type { INodeProperties } from 'n8n-workflow'; import type { INodeProperties } from 'n8n-workflow';
import {
databaseUrlExtractionRegexp,
databaseUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';
export const databaseOperations: INodeProperties[] = [ export const databaseOperations: INodeProperties[] = [
{ {
@@ -97,8 +103,7 @@ export const databaseFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databaseUrlValidationRegexp,
'(?: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: errorMessage:
'Not a valid Notion Database URL. Hint: use the URL of the database itself, not a page containing it.', 'Not a valid Notion Database URL. Hint: use the URL of the database itself, not a page containing it.',
}, },
@@ -106,8 +111,7 @@ export const databaseFields: INodeProperties[] = [
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databaseUrlExtractionRegexp,
'(?: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})',
}, },
}, },
{ {
@@ -119,15 +123,14 @@ export const databaseFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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', errorMessage: 'Not a valid Notion Database ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },

View File

@@ -5,6 +5,14 @@ import { getConditions, getSearchFilters } from '../GenericFunctions';
import { blocks, text } from './Blocks'; import { blocks, text } from './Blocks';
import { filters } from './Filters'; import { filters } from './Filters';
import {
databaseUrlExtractionRegexp,
databaseUrlValidationRegexp,
databasePageUrlExtractionRegexp,
databasePageUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';
export const databasePageOperations: INodeProperties[] = [ export const databasePageOperations: INodeProperties[] = [
{ {
@@ -114,16 +122,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databaseUrlValidationRegexp,
'(?: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', errorMessage: 'Not a valid Notion Database URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databaseUrlExtractionRegexp,
'(?: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})',
}, },
}, },
{ {
@@ -135,15 +141,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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', errorMessage: 'Not a valid Notion Database ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },
@@ -600,16 +605,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databasePageUrlValidationRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12}).*',
errorMessage: 'Not a valid Notion Database Page URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databasePageUrlExtractionRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})',
}, },
}, },
{ {
@@ -621,15 +624,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})|([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}))[ \t]*',
errorMessage: 'Not a valid Notion Database Page ID', errorMessage: 'Not a valid Notion Database Page ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: '^([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },
@@ -1069,16 +1071,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databasePageUrlValidationRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12}).*',
errorMessage: 'Not a valid Notion Database Page URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databasePageUrlExtractionRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})',
}, },
}, },
{ {
@@ -1090,15 +1090,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})|([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}))[ \t]*',
errorMessage: 'Not a valid Notion Database Page ID', errorMessage: 'Not a valid Notion Database Page ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: '^([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },
@@ -1160,16 +1159,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databasePageUrlValidationRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12}).*',
errorMessage: 'Not a valid Notion Database Page URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databasePageUrlExtractionRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})',
}, },
}, },
{ {
@@ -1181,15 +1178,14 @@ export const databasePageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})|([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}))[ \t]*',
errorMessage: 'Not a valid Notion Database Page ID', errorMessage: 'Not a valid Notion Database Page ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: '^([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },

View File

@@ -1,6 +1,12 @@
import type { INodeProperties } from 'n8n-workflow'; import type { INodeProperties } from 'n8n-workflow';
import { blocks } from './Blocks'; import { blocks } from './Blocks';
import {
databasePageUrlExtractionRegexp,
databasePageUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';
export const pageOperations: INodeProperties[] = [ export const pageOperations: INodeProperties[] = [
{ {
@@ -93,16 +99,14 @@ export const pageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databasePageUrlValidationRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([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 Page URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databasePageUrlExtractionRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})',
}, },
}, },
{ {
@@ -114,15 +118,14 @@ export const pageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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 Page ID', errorMessage: 'Not a valid Notion Page ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },
@@ -173,16 +176,14 @@ export const pageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: databasePageUrlValidationRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([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 Page URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
regex: regex: databasePageUrlExtractionRegexp,
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}4[0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12})',
}, },
}, },
{ {
@@ -194,15 +195,14 @@ export const pageFields: INodeProperties[] = [
{ {
type: 'regex', type: 'regex',
properties: { properties: {
regex: regex: idValidationRegexp,
'^(([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 Page ID', errorMessage: 'Not a valid Notion Page ID',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', 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})', regex: idExtractionRegexp,
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },

View File

@@ -1,3 +1,4 @@
import { databasePageUrlExtractionRegexp } from '../shared/constants';
import { extractPageId, formatBlocks } from '../shared/GenericFunctions'; import { extractPageId, formatBlocks } from '../shared/GenericFunctions';
describe('Test NotionV2, formatBlocks', () => { describe('Test NotionV2, formatBlocks', () => {
@@ -41,11 +42,9 @@ describe('Test Notion', () => {
'f4c1217e48f711ef94540242ac120002', // Random v1 UUID 'f4c1217e48f711ef94540242ac120002', // Random v1 UUID
]; ];
describe('extractPageId From URL', () => { describe('extractPageId From URL', () => {
const extractPattern =
'(?:https|http)://www.notion.so/(?:[a-z0-9-]{2,}/)?(?:[a-zA-Z0-9-]{1,}-)?([0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12})';
// RLC does some Regex extraction before extractPageId is called // RLC does some Regex extraction before extractPageId is called
const extractIdFromUrl = (url: string): string => { const extractIdFromUrl = (url: string): string => {
const match = url.match(extractPattern); const match = url.match(databasePageUrlExtractionRegexp);
return match ? match[1] : url; return match ? match[1] : url;
}; };