Skip to content

Commit

Permalink
fix(Notion Node): Allow UUID v8 in notion id checks (#10938)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored Sep 24, 2024
1 parent 8db8817 commit 46beda0
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 85 deletions.
17 changes: 10 additions & 7 deletions packages/nodes-base/nodes/Notion/NotionTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import moment from 'moment-timezone';
import { notionApiRequest, simplifyObjects } from './shared/GenericFunctions';

import { listSearch } from './shared/methods';
import {
databaseUrlExtractionRegexp,
databaseUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from './shared/constants';

export class NotionTrigger implements INodeType {
description: INodeTypeDescription = {
Expand Down Expand Up @@ -85,16 +91,14 @@ export class NotionTrigger implements INodeType {
{
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}).*',
regex: databaseUrlValidationRegexp,
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})',
regex: databaseUrlExtractionRegexp,
},
},
{
Expand All @@ -106,15 +110,14 @@ export class NotionTrigger implements INodeType {
{
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]*',
regex: idValidationRegexp,
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})',
regex: idExtractionRegexp,
},
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Notion/shared/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import moment from 'moment-timezone';
import { validate as uuidValidate } from 'uuid';
import set from 'lodash/set';
import { filters } from './descriptions/Filters';
import { blockUrlExtractionRegexp } from './constants';

function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
if (uuidValidate(value)) return true;
Expand Down Expand Up @@ -1152,8 +1153,7 @@ export function extractBlockId(this: IExecuteFunctions, nodeVersion: number, ite
const match = (blockIdRLCData.value as string).match(blockRegex);

if (match === null) {
const pageRegex =
/(?: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 pageRegex = new RegExp(blockUrlExtractionRegexp);
const pageMatch = (blockIdRLCData.value as string).match(pageRegex);

if (pageMatch === null) {
Expand Down
15 changes: 15 additions & 0 deletions packages/nodes-base/nodes/Notion/shared/constants.ts
Original file line number Diff line number Diff line change
@@ -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}.*`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { INodeProperties } from 'n8n-workflow';

import { blocks } from './Blocks';
import {
blockUrlExtractionRegexp,
blockUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';

//RLC with fixed regex for blockId
const blockIdRLC: INodeProperties = {
Expand All @@ -20,15 +26,14 @@ const blockIdRLC: INodeProperties = {
{
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}).*',
regex: blockUrlValidationRegexp,
errorMessage: 'Not a valid Notion Block URL',
},
},
],
// extractValue: {
// type: 'regex',
// regex: 'https:\\/\\/www\\.notion\\.so\\/.+\\?pvs=[0-9]+#([a-f0-9]{2,})',
// regex: blockUrlExtractionRegexp,
// },
},
{
Expand Down Expand Up @@ -101,16 +106,14 @@ export const blockFields: INodeProperties[] = [
{
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}).*',
regex: blockUrlValidationRegexp,
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})',
regex: blockUrlExtractionRegexp,
},
},
{
Expand All @@ -122,15 +125,14 @@ export const blockFields: INodeProperties[] = [
{
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]*',
regex: idValidationRegexp,
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})',
regex: idExtractionRegexp,
},
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
},
Expand Down Expand Up @@ -176,16 +178,14 @@ export const blockFields: INodeProperties[] = [
{
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}).*',
regex: blockUrlValidationRegexp,
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})',
regex: blockUrlExtractionRegexp,
},
},
{
Expand All @@ -197,15 +197,14 @@ export const blockFields: INodeProperties[] = [
{
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]*',
regex: idValidationRegexp,
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})',
regex: idExtractionRegexp,
},
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
},
Expand Down
17 changes: 10 additions & 7 deletions packages/nodes-base/nodes/Notion/shared/descriptions/Blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type { IDisplayOptions, INodeProperties } from 'n8n-workflow';
import {
databaseUrlExtractionRegexp,
databaseUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';

const colors = [
{
Expand Down Expand Up @@ -221,16 +227,14 @@ const typeMention: INodeProperties[] = [
{
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}).*',
regex: databaseUrlValidationRegexp,
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})',
regex: databaseUrlExtractionRegexp,
},
},
{
Expand All @@ -242,15 +246,14 @@ const typeMention: INodeProperties[] = [
{
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]*',
regex: idValidationRegexp,
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})',
regex: idExtractionRegexp,
},
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type { INodeProperties } from 'n8n-workflow';
import {
databaseUrlExtractionRegexp,
databaseUrlValidationRegexp,
idExtractionRegexp,
idValidationRegexp,
} from '../constants';

export const databaseOperations: INodeProperties[] = [
{
Expand Down Expand Up @@ -97,17 +103,15 @@ export const databaseFields: INodeProperties[] = [
{
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}).*',
regex: databaseUrlValidationRegexp,
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})',
regex: databaseUrlExtractionRegexp,
},
},
{
Expand All @@ -119,15 +123,14 @@ export const databaseFields: INodeProperties[] = [
{
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]*',
regex: idValidationRegexp,
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})',
regex: idExtractionRegexp,
},
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
},
Expand Down
Loading

0 comments on commit 46beda0

Please sign in to comment.