mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(Notion Node): Continue on fail support (#8788)
This commit is contained in:
@@ -7,9 +7,9 @@ import type {
|
|||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import moment from 'moment-timezone';
|
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 {
|
export class NotionTrigger implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
@@ -142,9 +142,7 @@ export class NotionTrigger implements INodeType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
methods = {
|
methods = {
|
||||||
listSearch: {
|
listSearch,
|
||||||
getDatabases,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { camelCase, capitalCase, snakeCase } from 'change-case';
|
|||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
|
|
||||||
import { validate as uuidValidate } from 'uuid';
|
import { validate as uuidValidate } from 'uuid';
|
||||||
import { filters } from './Filters';
|
import { filters } from './descriptions/Filters';
|
||||||
|
|
||||||
function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
|
function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
|
||||||
if (uuidValidate(value)) return true;
|
if (uuidValidate(value)) return true;
|
||||||
@@ -151,7 +151,7 @@ export async function notionApiRequestGetBlockChildrens(
|
|||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBlockTypes() {
|
export function getBlockTypesOptions() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'Paragraph',
|
name: 'Paragraph',
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { INodeProperties } from 'n8n-workflow';
|
import type { INodeProperties } from 'n8n-workflow';
|
||||||
|
|
||||||
import { getConditions, getSearchFilters } from './GenericFunctions';
|
import { getConditions, getSearchFilters } from '../GenericFunctions';
|
||||||
|
|
||||||
import { blocks, text } from './Blocks';
|
import { blocks, text } from './Blocks';
|
||||||
|
|
||||||
1
packages/nodes-base/nodes/Notion/shared/methods/index.ts
Normal file
1
packages/nodes-base/nodes/Notion/shared/methods/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * as listSearch from './listSearch';
|
||||||
@@ -4,7 +4,7 @@ import type {
|
|||||||
INodeListSearchItems,
|
INodeListSearchItems,
|
||||||
INodeListSearchResult,
|
INodeListSearchResult,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { notionApiRequestAllItems } from './GenericFunctions';
|
import { notionApiRequestAllItems } from '../GenericFunctions';
|
||||||
|
|
||||||
export async function getDatabases(
|
export async function getDatabases(
|
||||||
this: ILoadOptionsFunctions,
|
this: ILoadOptionsFunctions,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { formatBlocks } from '../GenericFunctions';
|
import { formatBlocks } from '../shared/GenericFunctions';
|
||||||
|
|
||||||
describe('Test NotionV2, formatBlocks', () => {
|
describe('Test NotionV2, formatBlocks', () => {
|
||||||
it('should format to_do block', () => {
|
it('should format to_do block', () => {
|
||||||
|
|||||||
@@ -10,23 +10,23 @@ import type {
|
|||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import type { SortData } from '../GenericFunctions';
|
import type { SortData } from '../shared/GenericFunctions';
|
||||||
import {
|
import {
|
||||||
extractDatabaseId,
|
extractDatabaseId,
|
||||||
extractDatabaseMentionRLC,
|
extractDatabaseMentionRLC,
|
||||||
extractPageId,
|
extractPageId,
|
||||||
formatBlocks,
|
formatBlocks,
|
||||||
formatTitle,
|
formatTitle,
|
||||||
getBlockTypes,
|
getBlockTypesOptions,
|
||||||
mapFilters,
|
mapFilters,
|
||||||
mapProperties,
|
mapProperties,
|
||||||
mapSorting,
|
mapSorting,
|
||||||
notionApiRequest,
|
notionApiRequest,
|
||||||
notionApiRequestAllItems,
|
notionApiRequestAllItems,
|
||||||
simplifyObjects,
|
simplifyObjects,
|
||||||
} from '../GenericFunctions';
|
} from '../shared/GenericFunctions';
|
||||||
|
|
||||||
import { getDatabases } from '../SearchFunctions';
|
import { listSearch } from '../shared/methods';
|
||||||
import { versionDescription } from './VersionDescription';
|
import { versionDescription } from './VersionDescription';
|
||||||
|
|
||||||
export class NotionV1 implements INodeType {
|
export class NotionV1 implements INodeType {
|
||||||
@@ -40,9 +40,7 @@ export class NotionV1 implements INodeType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
methods = {
|
methods = {
|
||||||
listSearch: {
|
listSearch,
|
||||||
getDatabases,
|
|
||||||
},
|
|
||||||
loadOptions: {
|
loadOptions: {
|
||||||
async getDatabaseProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getDatabaseProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
@@ -104,7 +102,7 @@ export class NotionV1 implements INodeType {
|
|||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
async getBlockTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getBlockTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
return getBlockTypes();
|
return getBlockTypesOptions();
|
||||||
},
|
},
|
||||||
async getPropertySelectValues(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getPropertySelectValues(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const [name, type] = (this.getCurrentNodeParameter('&key') as string).split('|');
|
const [name, type] = (this.getCurrentNodeParameter('&key') as string).split('|');
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||||
import type { INodeTypeDescription } from 'n8n-workflow';
|
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 = {
|
export const versionDescription: INodeTypeDescription = {
|
||||||
displayName: 'Notion',
|
displayName: 'Notion',
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,17 @@
|
|||||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||||
import type { INodeTypeDescription } from 'n8n-workflow';
|
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 = {
|
export const versionDescription: INodeTypeDescription = {
|
||||||
displayName: 'Notion',
|
displayName: 'Notion',
|
||||||
|
|||||||
1
packages/nodes-base/nodes/Notion/v2/methods/index.ts
Normal file
1
packages/nodes-base/nodes/Notion/v2/methods/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * as loadOptions from './loadOptions';
|
||||||
202
packages/nodes-base/nodes/Notion/v2/methods/loadOptions.ts
Normal file
202
packages/nodes-base/nodes/Notion/v2/methods/loadOptions.ts
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user