From 85383836a99a6f14bc6ca494dcd5a9b49d137c08 Mon Sep 17 00:00:00 2001 From: Lorena Balan Date: Wed, 3 Dec 2025 15:21:22 +0100 Subject: [PATCH 1/5] Notion as ConnectorV2 --- .../kbn-connector-specs/src/all_specs.ts | 1 + .../kbn-connector-specs/src/specs/notion.ts | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts diff --git a/src/platform/packages/shared/kbn-connector-specs/src/all_specs.ts b/src/platform/packages/shared/kbn-connector-specs/src/all_specs.ts index fefd2a67514e8..ac6b11cc7d21c 100644 --- a/src/platform/packages/shared/kbn-connector-specs/src/all_specs.ts +++ b/src/platform/packages/shared/kbn-connector-specs/src/all_specs.ts @@ -10,6 +10,7 @@ export * from './specs/abuseipdb'; export * from './specs/alienvault_otx'; export * from './specs/greynoise'; +export * from './specs/notion'; export * from './specs/shodan'; export * from './specs/urlvoid'; export * from './specs/virustotal'; diff --git a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts new file mode 100644 index 0000000000000..89c5c7bbc4671 --- /dev/null +++ b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts @@ -0,0 +1,72 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ +import { z } from '@kbn/zod/v4'; +import type { ConnectorSpec } from '../connector_spec'; + +export const NotionConnector: ConnectorSpec = { + metadata: { + id: '.notion', + displayName: 'Notion', + description: 'Explore content and databases in Notion', + minimumLicense: 'gold', + supportedFeatureIds: ['workflows'], + }, + + // TODO: we also need to send another custom header "Notion-Version": "2025-09-03" + // https://developers.notion.com/docs/authorization#making-api-requests-with-an-internal-integration + authTypes: ['bearer'], + + actions: { + // https://developers.notion.com/reference/post-search + searchPageOrDSByTitle: { + isTool: true, + input: z.object({ + query: z.string(), + queryObjectType: z.enum(['page', 'data_source']), + startCursor: z.string().optional(), + pageSize: z.number().optional(), + }), + handler: async (ctx, input) => { + const typedInput = input as { + query: string; + queryObjectType: 'page' | 'data_source'; + startCursor?: string; + pageSize?: number; + }; + + const response = await ctx.client.post( + 'https://api.notion.com/v1/search', + { + query: typedInput.query, + filter: { + value: typedInput.queryObjectType, + property: 'object', + }, + ...(typedInput.startCursor && { start_cursor: typedInput.startCursor }), + ...(typedInput.pageSize && { page_size: typedInput.pageSize }), + }, + { headers: { 'Notion-Version': '2025-09-03' } } + ); + + return response.data; + }, + }, + // getPage: {}, + // getDataSource: {}, + // queryDataSource: {}, + }, + + test: { + description: 'Fetch metadata about given data source', + handler: async (ctx) => { + ctx.log.debug('Notion test handler'); + return { ok: true }; + }, + }, +}; From 5be8795e861ca384809acb417b94a629e58d6d93 Mon Sep 17 00:00:00 2001 From: Lorena Balan Date: Wed, 3 Dec 2025 18:13:38 +0100 Subject: [PATCH 2/5] Add getPage action --- .../kbn-connector-specs/src/specs/notion.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts index 89c5c7bbc4671..2a6606cca56a4 100644 --- a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts +++ b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts @@ -57,7 +57,21 @@ export const NotionConnector: ConnectorSpec = { return response.data; }, }, - // getPage: {}, + + // https://developers.notion.com/reference/retrieve-a-page + getPage: { + isTool: true, + input: z.object({ pageId: z.string() }), + handler: async (ctx, input) => { + const typedInput = input as { pageId: string }; + const response = await ctx.client.get( + `https://api.notion.com/v1/pages/${typedInput.pageId}`, + {} + // { headers: { 'Notion-Version': '2025-09-03' } } + ); + return response.data; + }, + }, // getDataSource: {}, // queryDataSource: {}, }, From 4bfde8c39819e4fed1ef88d740c35d3a17c31782 Mon Sep 17 00:00:00 2001 From: Lorena Balan Date: Wed, 3 Dec 2025 18:16:10 +0100 Subject: [PATCH 3/5] Add getDataSource action --- .../kbn-connector-specs/src/specs/notion.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts index 2a6606cca56a4..dfb8e7539d09c 100644 --- a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts +++ b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts @@ -72,7 +72,21 @@ export const NotionConnector: ConnectorSpec = { return response.data; }, }, - // getDataSource: {}, + + // https://developers.notion.com/reference/retrieve-a-data-source + getDataSource: { + isTool: true, + input: z.object({ dataSourceId: z.string() }), + handler: async (ctx, input) => { + const typedInput = input as { dataSourceId: string }; + const response = await ctx.client.get( + `https://api.notion.com/v1/data_sources/${typedInput.dataSourceId}`, + {} + // { headers: { 'Notion-Version': '2025-09-03' } } + ); + return response.data; + }, + }, // queryDataSource: {}, }, From 0ab2253ea7a842eb5e2d91ad5a01b19f3151f807 Mon Sep 17 00:00:00 2001 From: Lorena Balan Date: Wed, 3 Dec 2025 18:23:50 +0100 Subject: [PATCH 4/5] Add queryDataSource action --- .../kbn-connector-specs/src/specs/notion.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts index dfb8e7539d09c..9af78d5bd089f 100644 --- a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts +++ b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts @@ -87,7 +87,43 @@ export const NotionConnector: ConnectorSpec = { return response.data; }, }, - // queryDataSource: {}, + + // https://developers.notion.com/reference/query-a-data-source + queryDataSource: { + isTool: true, + input: z.object({ + dataSourceId: z.string(), + filter: z.string().optional(), + startCursor: z.string().optional(), + pageSize: z.number().optional(), + }), + handler: async (ctx, input) => { + const typedInput = input as { + dataSourceId: string; + filter?: string; + startCursor?: string; + pageSize?: number; + }; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let requestData: Record = { + page_size: typedInput.pageSize, + start_cursor: typedInput.startCursor, + }; + if (typedInput.filter) { + requestData = { ...requestData, filter: JSON.parse(typedInput.filter) }; + } + + // TODO: check if there's error handling for free from the framework + // or if we still need to add some of our own + const response = await ctx.client.post( + `https://api.notion.com/v1/data_sources/${typedInput.dataSourceId}/query`, + requestData, + { headers: { 'Notion-Version': '2025-09-03' } } + ); + return response.data; + }, + }, }, test: { From e8ca409b14be21e1e9de1c99288f23832e4c1c6b Mon Sep 17 00:00:00 2001 From: Lorena Balan Date: Wed, 3 Dec 2025 18:44:42 +0100 Subject: [PATCH 5/5] Add test logic --- .../kbn-connector-specs/src/specs/notion.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts index 9af78d5bd089f..56cee75029188 100644 --- a/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts +++ b/src/platform/packages/shared/kbn-connector-specs/src/specs/notion.ts @@ -22,6 +22,8 @@ export const NotionConnector: ConnectorSpec = { // https://developers.notion.com/docs/authorization#making-api-requests-with-an-internal-integration authTypes: ['bearer'], + // TODO: check if we need `schema` attribute / what for + actions: { // https://developers.notion.com/reference/post-search searchPageOrDSByTitle: { @@ -127,10 +129,22 @@ export const NotionConnector: ConnectorSpec = { }, test: { - description: 'Fetch metadata about given data source', + description: 'Verifies Notion connection by fetching metadata about given data source', + // TODO: might need to accept some input here in order to pass to the API endpoint to test + // if listing all users feels a bit too much handler: async (ctx) => { ctx.log.debug('Notion test handler'); - return { ok: true }; + + try { + const response = await ctx.client.get('https://api.notion.com/v1/users'); + const numOfUsers = response.data.results.length; + return { + ok: true, + message: `Successfully connected to Notion API: found ${numOfUsers} users`, + }; + } catch (error) { + return { ok: false, message: error.message }; + } }, }, };