fix(Notion Node): Fix issue preventing some database page urls from working (#10070)

This commit is contained in:
Jon 2024-07-24 11:27:07 +01:00 committed by GitHub
parent ea5382d20f
commit 7848c19f54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 80 additions and 21 deletions

View file

@ -601,7 +601,7 @@ export const databasePageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
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}).*', '(?: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',
}, },
}, },
@ -609,7 +609,7 @@ export const databasePageFields: INodeProperties[] = [
extractValue: { extractValue: {
type: 'regex', type: 'regex',
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})', '(?: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})',
}, },
}, },
{ {
@ -622,14 +622,14 @@ export const databasePageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
regex: 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]*', '^(([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}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12})', regex: '^([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})',
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },
@ -1070,7 +1070,7 @@ export const databasePageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
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}).*', '(?: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',
}, },
}, },
@ -1078,7 +1078,7 @@ export const databasePageFields: INodeProperties[] = [
extractValue: { extractValue: {
type: 'regex', type: 'regex',
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})', '(?: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})',
}, },
}, },
{ {
@ -1091,14 +1091,14 @@ export const databasePageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
regex: 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]*', '^(([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}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12})', regex: '^([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})',
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },
@ -1161,15 +1161,15 @@ export const databasePageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
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}).*', '(?: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 URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
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})', '(?: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})',
}, },
}, },
{ {
@ -1182,14 +1182,14 @@ export const databasePageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
regex: 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]*', '^(([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 ID', errorMessage: 'Not a valid Notion Database 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: '^([0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})',
}, },
url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}', url: '=https://www.notion.so/{{$value.replace(/-/g, "")}}',
}, },

View file

@ -94,15 +94,15 @@ export const pageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
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}).*', '(?: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 Page URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
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})', '(?: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})',
}, },
}, },
{ {
@ -174,15 +174,15 @@ export const pageFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
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}).*', '(?: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 Page URL', errorMessage: 'Not a valid Notion Database Page URL',
}, },
}, },
], ],
extractValue: { extractValue: {
type: 'regex', type: 'regex',
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})', '(?: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})',
}, },
}, },
{ {

View file

@ -1,4 +1,4 @@
import { formatBlocks } from '../shared/GenericFunctions'; import { extractPageId, formatBlocks } from '../shared/GenericFunctions';
describe('Test NotionV2, formatBlocks', () => { describe('Test NotionV2, formatBlocks', () => {
it('should format to_do block', () => { it('should format to_do block', () => {
@ -31,3 +31,62 @@ describe('Test NotionV2, formatBlocks', () => {
]); ]);
}); });
}); });
describe('Test Notion', () => {
const baseUrl = 'https://www.notion.so/fake-instance';
const testIds = [
'4eb10d5001254b7faaa831d72d9445aa', // Taken from Notion
'fffb95d3060b80309027eb9c99605ec3', // Taken from user comment
'a6356387779d4df485449a72a408f0d4', // Random v4 UUID
'f4c1217e48f711ef94540242ac120002', // Random v1 UUID
];
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
const extractIdFromUrl = (url: string): string => {
const match = url.match(extractPattern);
return match ? match[1] : url;
};
test('should return the part after "p="', () => {
for (const testId of testIds) {
const page = `${baseUrl}?p=${testId}`;
const result = extractPageId(extractIdFromUrl(page));
expect(result).toBe(testId);
}
});
test('should return the last part after splitting by "-" when URL contains multiple "-"', () => {
for (const testId of testIds) {
const page = `${baseUrl}/some-page-${testId}`;
const result = extractPageId(extractIdFromUrl(page));
expect(result).toBe(testId);
}
});
test('should return the last part after splitting by "-" when URL contains one "-"', () => {
for (const testId of testIds) {
const page = `${baseUrl}/1-${testId}`;
const result = extractPageId(extractIdFromUrl(page));
expect(result).toBe(testId);
}
});
test('should return just the id when there is an instance name', () => {
for (const testId of testIds) {
const page = `${baseUrl}/${testId}`;
const result = extractPageId(extractIdFromUrl(page));
expect(result).toBe(testId);
}
});
test('should return the id when there is no instance name', () => {
for (const testId of testIds) {
const page = `https://www.notion.so/${testId}`;
const result = extractPageId(extractIdFromUrl(page));
expect(result).toBe(testId);
}
});
});
});