feat(Notion Node): Continue on fail support (#8788)

This commit is contained in:
Michael Kret 2024-03-05 15:45:36 +02:00 committed by GitHub
parent df064af645
commit 4850f6a9cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 851 additions and 660 deletions

View file

@ -7,9 +7,9 @@ import type {
} from 'n8n-workflow';
import moment from 'moment-timezone';
import { notionApiRequest, simplifyObjects } from './GenericFunctions';
import { notionApiRequest, simplifyObjects } from './shared/GenericFunctions';
import { getDatabases } from './SearchFunctions';
import { listSearch } from './shared/methods';
export class NotionTrigger implements INodeType {
description: INodeTypeDescription = {
@ -142,9 +142,7 @@ export class NotionTrigger implements INodeType {
};
methods = {
listSearch: {
getDatabases,
},
listSearch,
};
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {

View file

@ -20,7 +20,7 @@ import { camelCase, capitalCase, snakeCase } from 'change-case';
import moment from 'moment-timezone';
import { validate as uuidValidate } from 'uuid';
import { filters } from './Filters';
import { filters } from './descriptions/Filters';
function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
if (uuidValidate(value)) return true;
@ -151,7 +151,7 @@ export async function notionApiRequestGetBlockChildrens(
return responseData;
}
export function getBlockTypes() {
export function getBlockTypesOptions() {
return [
{
name: 'Paragraph',

View file

@ -1,6 +1,6 @@
import type { INodeProperties } from 'n8n-workflow';
import { getConditions, getSearchFilters } from './GenericFunctions';
import { getConditions, getSearchFilters } from '../GenericFunctions';
import { blocks, text } from './Blocks';

View file

@ -0,0 +1 @@
export * as listSearch from './listSearch';

View file

@ -4,7 +4,7 @@ import type {
INodeListSearchItems,
INodeListSearchResult,
} from 'n8n-workflow';
import { notionApiRequestAllItems } from './GenericFunctions';
import { notionApiRequestAllItems } from '../GenericFunctions';
export async function getDatabases(
this: ILoadOptionsFunctions,

View file

@ -1,4 +1,4 @@
import { formatBlocks } from '../GenericFunctions';
import { formatBlocks } from '../shared/GenericFunctions';
describe('Test NotionV2, formatBlocks', () => {
it('should format to_do block', () => {

View file

@ -10,23 +10,23 @@ import type {
} from 'n8n-workflow';
import moment from 'moment-timezone';
import type { SortData } from '../GenericFunctions';
import type { SortData } from '../shared/GenericFunctions';
import {
extractDatabaseId,
extractDatabaseMentionRLC,
extractPageId,
formatBlocks,
formatTitle,
getBlockTypes,
getBlockTypesOptions,
mapFilters,
mapProperties,
mapSorting,
notionApiRequest,
notionApiRequestAllItems,
simplifyObjects,
} from '../GenericFunctions';
} from '../shared/GenericFunctions';
import { getDatabases } from '../SearchFunctions';
import { listSearch } from '../shared/methods';
import { versionDescription } from './VersionDescription';
export class NotionV1 implements INodeType {
@ -40,9 +40,7 @@ export class NotionV1 implements INodeType {
}
methods = {
listSearch: {
getDatabases,
},
listSearch,
loadOptions: {
async getDatabaseProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
@ -104,7 +102,7 @@ export class NotionV1 implements INodeType {
return returnData;
},
async getBlockTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
return getBlockTypes();
return getBlockTypesOptions();
},
async getPropertySelectValues(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const [name, type] = (this.getCurrentNodeParameter('&key') as string).split('|');

View file

@ -1,14 +1,17 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import type { INodeTypeDescription } from 'n8n-workflow';
import { databaseFields, databaseOperations } from '../DatabaseDescription';
import { databaseFields, databaseOperations } from '../shared/descriptions/DatabaseDescription';
import { userFields, userOperations } from '../UserDescription';
import { userFields, userOperations } from '../shared/descriptions/UserDescription';
import { pageFields, pageOperations } from '../PageDescription';
import { pageFields, pageOperations } from '../shared/descriptions/PageDescription';
import { blockFields, blockOperations } from '../BlockDescription';
import { blockFields, blockOperations } from '../shared/descriptions/BlockDescription';
import { databasePageFields, databasePageOperations } from '../DatabasePageDescription';
import {
databasePageFields,
databasePageOperations,
} from '../shared/descriptions/DatabasePageDescription';
export const versionDescription: INodeTypeDescription = {
displayName: 'Notion',

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,17 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import type { INodeTypeDescription } from 'n8n-workflow';
import { databaseFields, databaseOperations } from '../DatabaseDescription';
import { databaseFields, databaseOperations } from '../shared/descriptions/DatabaseDescription';
import { userFields, userOperations } from '../UserDescription';
import { userFields, userOperations } from '../shared/descriptions/UserDescription';
import { pageFields, pageOperations } from '../PageDescription';
import { pageFields, pageOperations } from '../shared/descriptions/PageDescription';
import { blockFields, blockOperations } from '../BlockDescription';
import { blockFields, blockOperations } from '../shared/descriptions/BlockDescription';
import { databasePageFields, databasePageOperations } from '../DatabasePageDescription';
import {
databasePageFields,
databasePageOperations,
} from '../shared/descriptions/DatabasePageDescription';
export const versionDescription: INodeTypeDescription = {
displayName: 'Notion',

View file

@ -0,0 +1 @@
export * as loadOptions from './loadOptions';

View file

@ -0,0 +1,202 @@
import type { IDataObject, ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
import moment from 'moment-timezone';
import {
extractPageId,
getBlockTypesOptions,
notionApiRequest,
notionApiRequestAllItems,
} from '../../shared/GenericFunctions';
export async function getDatabaseProperties(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const databaseId = this.getCurrentNodeParameter('databaseId', {
extractValue: true,
}) as string;
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
for (const key of Object.keys(properties as IDataObject)) {
//remove parameters that cannot be set from the API.
if (
![
'created_time',
'last_edited_time',
'created_by',
'last_edited_by',
'formula',
'rollup',
].includes(properties[key].type as string)
) {
returnData.push({
name: `${key}`,
value: `${key}|${properties[key].type}`,
});
}
}
returnData.sort((a, b) => {
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
return -1;
}
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) {
return 1;
}
return 0;
});
return returnData;
}
export async function getFilterProperties(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const databaseId = this.getCurrentNodeParameter('databaseId', {
extractValue: true,
}) as string;
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
for (const key of Object.keys(properties as IDataObject)) {
returnData.push({
name: `${key}`,
value: `${key}|${properties[key].type}`,
});
}
returnData.sort((a, b) => {
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
return -1;
}
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) {
return 1;
}
return 0;
});
return returnData;
}
export async function getBlockTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
return getBlockTypesOptions();
}
export async function getPropertySelectValues(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const [name, type] = (this.getCurrentNodeParameter('&key') as string).split('|');
const databaseId = this.getCurrentNodeParameter('databaseId', {
extractValue: true,
}) as string;
const resource = this.getCurrentNodeParameter('resource') as string;
const operation = this.getCurrentNodeParameter('operation') as string;
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
if (resource === 'databasePage') {
if (['multi_select', 'select', 'status'].includes(type) && operation === 'getAll') {
return properties[name][type].options.map((option: IDataObject) => ({
name: option.name,
value: option.name,
}));
} else if (
['multi_select', 'select', 'status'].includes(type) &&
['create', 'update'].includes(operation)
) {
return properties[name][type].options.map((option: IDataObject) => ({
name: option.name,
value: option.name,
}));
}
}
return properties[name][type].options.map((option: IDataObject) => ({
name: option.name,
value: option.id,
}));
}
export async function getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const users = await notionApiRequestAllItems.call(this, 'results', 'GET', '/users');
for (const user of users) {
if (user.type === 'person') {
returnData.push({
name: user.name,
value: user.id,
});
}
}
return returnData;
}
export async function getDatabaseIdFromPage(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const pageId = extractPageId(
this.getCurrentNodeParameter('pageId', { extractValue: true }) as string,
);
const {
parent: { database_id: databaseId },
} = await notionApiRequest.call(this, 'GET', `/pages/${pageId}`);
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
for (const key of Object.keys(properties as IDataObject)) {
//remove parameters that cannot be set from the API.
if (
![
'created_time',
'last_edited_time',
'created_by',
'last_edited_by',
'formula',
'rollup',
].includes(properties[key].type as string)
) {
returnData.push({
name: `${key}`,
value: `${key}|${properties[key].type}`,
});
}
}
returnData.sort((a, b) => {
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
return -1;
}
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) {
return 1;
}
return 0;
});
return returnData;
}
export async function getDatabaseOptionsFromPage(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const pageId = extractPageId(
this.getCurrentNodeParameter('pageId', { extractValue: true }) as string,
);
const [name, type] = (this.getCurrentNodeParameter('&key') as string).split('|');
const {
parent: { database_id: databaseId },
} = await notionApiRequest.call(this, 'GET', `/pages/${pageId}`);
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
return properties[name][type].options.map((option: IDataObject) => ({
name: option.name,
value: option.name,
}));
}
// Get all the timezones to display them to user so that they can
// select them easily
export async function getTimezones(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
for (const timezone of moment.tz.names()) {
const timezoneName = timezone;
const timezoneId = timezone;
returnData.push({
name: timezoneName,
value: timezoneId,
});
}
returnData.unshift({
name: 'Default',
value: 'default',
description: 'Timezone set in n8n',
});
return returnData;
}