Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(microsoft-onenote): let AI agents manage OneNote notebooks, sections and pages (#16999)

Kishan Parmar57f5a0656619
diff --git a/bun.lock b/bun.lock
index 2ad8c6be9e7..bd523f6aff9 100644
--- a/bun.lock
+++ b/bun.lock
@@ -6011,13 +6011,14 @@
},
"packages/pieces/community/microsoft-onenote": {
"name": "@activepieces/piece-microsoft-onenote",
- "version": "0.4.3",
+ "version": "0.5.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
"@activepieces/pieces-common": "workspace:*",
"@activepieces/pieces-framework": "workspace:*",
"@microsoft/microsoft-graph-client": "3.0.7",
+ "@microsoft/microsoft-graph-types": "2.40.0",
"dayjs": "1.11.9",
},
"devDependencies": {
diff --git a/packages/pieces/community/microsoft-onenote/package.json b/packages/pieces/community/microsoft-onenote/package.json
index 82e3a350e38..fad180db090 100644
--- a/packages/pieces/community/microsoft-onenote/package.json
+++ b/packages/pieces/community/microsoft-onenote/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-microsoft-onenote",
- "version": "0.4.3",
+ "version": "0.5.0",
"type": "commonjs",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
@@ -8,6 +8,7 @@
"@activepieces/pieces-common": "workspace:*",
"@activepieces/pieces-framework": "workspace:*",
"@microsoft/microsoft-graph-client": "3.0.7",
+ "@microsoft/microsoft-graph-types": "2.40.0",
"dayjs": "1.11.9",
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*"
diff --git a/packages/pieces/community/microsoft-onenote/src/index.ts b/packages/pieces/community/microsoft-onenote/src/index.ts
index def6609369a..62154f4b1ce 100644
--- a/packages/pieces/community/microsoft-onenote/src/index.ts
+++ b/packages/pieces/community/microsoft-onenote/src/index.ts
@@ -1,14 +1,15 @@
import { createCustomApiCallAction } from '@activepieces/pieces-common';
-import { createPiece, OAuth2PropertyValue } from '@activepieces/pieces-framework';
+import { createPiece } from '@activepieces/pieces-framework';
import { PieceCategory } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from './lib/common/microsoft-cloud';
-import { appendNote } from './lib/actions/append-note';
-import { createImageNote } from './lib/actions/create-image-note';
-import { createNoteInSection } from './lib/actions/create-note-in-section';
-import { createNotebook } from './lib/actions/create-notebook';
-import { createPage } from './lib/actions/create-page';
-import { createSection } from './lib/actions/create-section';
-import { oneNoteAuth } from './lib/auth';
+import { appendNoteAction } from './lib/actions/append-note';
+import { createImageNoteAction } from './lib/actions/create-image-note';
+import { createNoteInSectionAction } from './lib/actions/create-note-in-section';
+import { createNotebookAction } from './lib/actions/create-notebook';
+import { createPageAction } from './lib/actions/create-page';
+import { createSectionAction } from './lib/actions/create-section';
+import { microsoftOneNoteAiActions } from './lib/actions/ai';
+import { microsoftOneNoteAuth } from './lib/auth';
+import { microsoftOneNoteClient } from './lib/common/client';
import { newNoteInSectionTrigger } from './lib/triggers/new-note-in-section';
export const microsoftOnenote = createPiece({
@@ -16,23 +17,22 @@ export const microsoftOnenote = createPiece({
description:
'Microsoft OneNote is a note-taking app that allows you to create, edit, and share notes with others.',
categories: [PieceCategory.PRODUCTIVITY],
- auth: oneNoteAuth,
- minimumSupportedRelease: '0.36.1',
+ auth: microsoftOneNoteAuth,
+ minimumSupportedRelease: '0.88.2',
logoUrl: 'https://cdn.activepieces.com/pieces/microsoft-onenote.png',
authors: ['fortunamide', 'onyedikachi-david'],
actions: [
- createNotebook,
- createSection,
- createNoteInSection,
- createPage,
- createImageNote,
- appendNote,
+ createNotebookAction,
+ createSectionAction,
+ createNoteInSectionAction,
+ createPageAction,
+ createImageNoteAction,
+ appendNoteAction,
+ ...microsoftOneNoteAiActions,
createCustomApiCallAction({
- auth: oneNoteAuth,
- baseUrl: (auth) => {
- const cloud = (auth as OAuth2PropertyValue).props?.['cloud'] as string | undefined;
- return getGraphBaseUrl(cloud) + '/v1.0/';
- },
+ auth: microsoftOneNoteAuth,
+ baseUrl: (auth) =>
+ auth ? `${microsoftOneNoteClient.baseUrl({ auth })}/v1.0/` : '',
authMapping: async (auth) => ({
Authorization: `Bearer ${auth.access_token}`,
}),
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-notebook.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-notebook.ts
new file mode 100644
index 00000000000..649d30e1a49
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-notebook.ts
@@ -0,0 +1,47 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteOperationOutputSchema } from '../../output-schemas';
+
+import type { OnenoteOperation } from '../../common/types';
+
+export const copyNotebookAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_copy_notebook',
+ outputSchema: microsoftOnenoteOperationOutputSchema,
+ displayName: 'Copy Notebook',
+ description: 'Starts copying a OneNote notebook.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Starts copying a notebook (ID from List Notebooks) to your OneDrive. Returns the copy operation; poll Get Operation with its id until it succeeds to get the new notebook. Work or school accounts only.',
+ idempotent: false,
+ },
+ props: {
+ notebookId: microsoftOneNoteAiProps.notebookId({ required: true }),
+ renameAs: Property.ShortText({
+ displayName: 'New Name',
+ description: 'Name of the copy. Defaults to the original name.',
+ required: false,
+ }),
+ notebookFolder: Property.ShortText({
+ displayName: 'Notebook Folder',
+ description:
+ 'Folder in your OneDrive to put the copy in. Created if missing. Defaults to Notebooks.',
+ required: false,
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenoteOperation = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/notebooks/${encodeURIComponent(propsValue.notebookId)}/copyNotebook`)
+ .post({
+ ...(propsValue.renameAs ? { renameAs: propsValue.renameAs } : {}),
+ ...(propsValue.notebookFolder ? { notebookFolder: propsValue.notebookFolder } : {}),
+ });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-page-to-section.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-page-to-section.ts
new file mode 100644
index 00000000000..b2a9dd998aa
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-page-to-section.ts
@@ -0,0 +1,40 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteOperationOutputSchema } from '../../output-schemas';
+
+import type { OnenoteOperation } from '../../common/types';
+
+export const copyPageToSectionAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_copy_page_to_section',
+ outputSchema: microsoftOnenoteOperationOutputSchema,
+ displayName: 'Copy Page to Section',
+ description: 'Starts copying a OneNote page to a section.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Starts copying a page (ID from List Pages) into a section (ID from List Sections). Returns the copy operation; poll Get Operation with its id until it succeeds to get the new page.',
+ idempotent: false,
+ },
+ props: {
+ pageId: microsoftOneNoteAiProps.pageId({ required: true }),
+ destinationId: microsoftOneNoteAiProps.sectionId({
+ required: true,
+ displayName: 'Destination Section ID',
+ description: 'Section to copy the page into. Use List Sections to find it.',
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenoteOperation = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/pages/${encodeURIComponent(propsValue.pageId)}/copyToSection`)
+ .post({
+ id: propsValue.destinationId,
+ });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-section-to-notebook.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-section-to-notebook.ts
new file mode 100644
index 00000000000..737cbe154fa
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-section-to-notebook.ts
@@ -0,0 +1,46 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteOperationOutputSchema } from '../../output-schemas';
+
+import type { OnenoteOperation } from '../../common/types';
+
+export const copySectionToNotebookAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_copy_section_to_notebook',
+ outputSchema: microsoftOnenoteOperationOutputSchema,
+ displayName: 'Copy Section to Notebook',
+ description: 'Starts copying a OneNote section to a notebook.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Starts copying a section (ID from List Sections) into a notebook (ID from List Notebooks). Returns the copy operation; poll Get Operation with its id until it succeeds to get the new section.',
+ idempotent: false,
+ },
+ props: {
+ sectionId: microsoftOneNoteAiProps.sectionId({ required: true }),
+ destinationId: microsoftOneNoteAiProps.notebookId({
+ required: true,
+ displayName: 'Destination Notebook ID',
+ description: 'Notebook to copy the section into. Use List Notebooks to find it.',
+ }),
+ renameAs: Property.ShortText({
+ displayName: 'New Name',
+ description: 'Name of the copy. Defaults to the original name.',
+ required: false,
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenoteOperation = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/sections/${encodeURIComponent(propsValue.sectionId)}/copyToNotebook`)
+ .post({
+ id: propsValue.destinationId,
+ ...(propsValue.renameAs ? { renameAs: propsValue.renameAs } : {}),
+ });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-section-to-section-group.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-section-to-section-group.ts
new file mode 100644
index 00000000000..59c8b3b0797
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/copy-section-to-section-group.ts
@@ -0,0 +1,46 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteOperationOutputSchema } from '../../output-schemas';
+
+import type { OnenoteOperation } from '../../common/types';
+
+export const copySectionToSectionGroupAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_copy_section_to_section_group',
+ outputSchema: microsoftOnenoteOperationOutputSchema,
+ displayName: 'Copy Section to Section Group',
+ description: 'Starts copying a OneNote section to a section group.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Starts copying a section (ID from List Sections) into a section group (ID from List Section Groups). Returns the copy operation; poll Get Operation with its id until it succeeds to get the new section.',
+ idempotent: false,
+ },
+ props: {
+ sectionId: microsoftOneNoteAiProps.sectionId({ required: true }),
+ destinationId: microsoftOneNoteAiProps.sectionGroupId({
+ required: true,
+ displayName: 'Destination Section Group ID',
+ description: 'Section group to copy the section into. Use List Section Groups to find it.',
+ }),
+ renameAs: Property.ShortText({
+ displayName: 'New Name',
+ description: 'Name of the copy. Defaults to the original name.',
+ required: false,
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenoteOperation = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/sections/${encodeURIComponent(propsValue.sectionId)}/copyToSectionGroup`)
+ .post({
+ id: propsValue.destinationId,
+ ...(propsValue.renameAs ? { renameAs: propsValue.renameAs } : {}),
+ });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-notebook.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-notebook.ts
new file mode 100644
index 00000000000..ee1dc9f5d9a
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-notebook.ts
@@ -0,0 +1,37 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteCreateNotebookOutputSchema } from '../../output-schemas';
+
+import type { Notebook } from '../../common/types';
+
+export const createNotebookAiAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_create_notebook',
+ outputSchema: microsoftOnenoteCreateNotebookOutputSchema,
+ displayName: 'Create Notebook',
+ description: 'Creates a OneNote notebook.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Creates a OneNote notebook and returns it with its ID. Fails if a notebook with the same name exists.',
+ idempotent: false,
+ },
+ props: {
+ displayName: Property.ShortText({
+ displayName: 'Name',
+ description:
+ 'Notebook name, unique among your notebooks, at most 128 characters, without ?*/:<>|\'" characters.',
+ required: true,
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const response: Notebook = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/notebooks`)
+ .post({ displayName: propsValue.displayName });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-page.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-page.ts
new file mode 100644
index 00000000000..79caea79d9c
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-page.ts
@@ -0,0 +1,55 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteCreatePageOutputSchema } from '../../output-schemas';
+
+import type { OnenotePage } from '../../common/types';
+
+export const createPageAiAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_create_page',
+ outputSchema: microsoftOnenoteCreatePageOutputSchema,
+ displayName: 'Create Page',
+ description: 'Creates a OneNote page.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Creates a OneNote page with a title and an HTML body and returns it with its ID. Set Section ID (from List Sections) to choose the section; without it the page goes to the default section of your default notebook. Use Update Page Content to change an existing page.',
+ idempotent: false,
+ },
+ props: {
+ title: Property.ShortText({
+ displayName: 'Title',
+ description: 'Page title.',
+ required: true,
+ }),
+ content: Property.LongText({
+ displayName: 'Content',
+ description:
+ 'Page body as HTML, for example <p>Text</p>, <h1>, <ul><li>, <table>, <img src="https://...">. Only the body: the title and HTML wrapper are added for you.',
+ required: false,
+ }),
+ sectionId: microsoftOneNoteAiProps.sectionId({ required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const parent = propsValue.sectionId
+ ? `/sections/${encodeURIComponent(propsValue.sectionId)}`
+ : '';
+ const html = `<!DOCTYPE html><html><head><title>${escapeHtml({
+ text: propsValue.title,
+ })}</title></head><body>${propsValue.content ?? ''}</body></html>`;
+ const response: OnenotePage = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote${parent}/pages`)
+ .header('Content-Type', 'application/xhtml+xml')
+ .post(html);
+ return response;
+ },
+});
+
+function escapeHtml({ text }: { text: string }): string {
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+}
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-section-group.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-section-group.ts
new file mode 100644
index 00000000000..6d88cb932de
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-section-group.ts
@@ -0,0 +1,52 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteCreateSectionGroupOutputSchema } from '../../output-schemas';
+
+import type { SectionGroup } from '../../common/types';
+
+export const createSectionGroupAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_create_section_group',
+ outputSchema: microsoftOnenoteCreateSectionGroupOutputSchema,
+ displayName: 'Create Section Group',
+ description: 'Creates a OneNote section group.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Creates a section group in a notebook (Notebook ID from List Notebooks) or nested in another section group (Parent Section Group ID from List Section Groups) and returns it with its ID. Set exactly one of the two.',
+ idempotent: false,
+ },
+ props: {
+ displayName: Property.ShortText({
+ displayName: 'Name',
+ description:
+ "Section group name, unique in its parent, at most 50 characters, without ?*/:<>|&#'%~ characters.",
+ required: true,
+ }),
+ notebookId: microsoftOneNoteAiProps.notebookId({ required: false }),
+ parentSectionGroupId: microsoftOneNoteAiProps.sectionGroupId({
+ required: false,
+ displayName: 'Parent Section Group ID',
+ description:
+ 'Creates the new group inside this section group. Use List Section Groups to find it.',
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const { notebookId, parentSectionGroupId } = propsValue;
+ if (Boolean(notebookId) === Boolean(parentSectionGroupId)) {
+ throw new Error('Set exactly one of Notebook ID or Parent Section Group ID.');
+ }
+ const parent = notebookId
+ ? `/notebooks/${encodeURIComponent(notebookId)}`
+ : `/sectionGroups/${encodeURIComponent(parentSectionGroupId ?? '')}`;
+ const response: SectionGroup = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote${parent}/sectionGroups`)
+ .post({ displayName: propsValue.displayName });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-section.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-section.ts
new file mode 100644
index 00000000000..4fefab1e69c
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/create-section.ts
@@ -0,0 +1,47 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteCreateSectionOutputSchema } from '../../output-schemas';
+
+import type { OnenoteSection } from '../../common/types';
+
+export const createSectionAiAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_create_section',
+ outputSchema: microsoftOnenoteCreateSectionOutputSchema,
+ displayName: 'Create Section',
+ description: 'Creates a OneNote section.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Creates a section in a notebook (Notebook ID from List Notebooks) or in a section group (Section Group ID from List Section Groups) and returns it with its ID. Set exactly one of the two. Fails if the parent already has a section with that name.',
+ idempotent: false,
+ },
+ props: {
+ displayName: Property.ShortText({
+ displayName: 'Name',
+ description:
+ "Section name, unique in its parent, at most 50 characters, without ?*/:<>|&#'%~ characters.",
+ required: true,
+ }),
+ notebookId: microsoftOneNoteAiProps.notebookId({ required: false }),
+ sectionGroupId: microsoftOneNoteAiProps.sectionGroupId({ required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const { notebookId, sectionGroupId } = propsValue;
+ if (Boolean(notebookId) === Boolean(sectionGroupId)) {
+ throw new Error('Set exactly one of Notebook ID or Section Group ID.');
+ }
+ const parent = notebookId
+ ? `/notebooks/${encodeURIComponent(notebookId)}`
+ : `/sectionGroups/${encodeURIComponent(sectionGroupId ?? '')}`;
+ const response: OnenoteSection = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote${parent}/sections`)
+ .post({ displayName: propsValue.displayName });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/delete-page.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/delete-page.ts
new file mode 100644
index 00000000000..a50db2d504f
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/delete-page.ts
@@ -0,0 +1,31 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteDeletePageOutputSchema } from '../../output-schemas';
+
+export const deletePageAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_delete_page',
+ outputSchema: microsoftOnenoteDeletePageOutputSchema,
+ displayName: 'Delete Page',
+ description: 'Deletes a OneNote page.',
+ audience: 'ai',
+ classification: 'DESTRUCTIVE',
+ aiMetadata: {
+ description:
+ "Permanently deletes a OneNote page (ID from List Pages). It goes to the notebook's recycle bin in the OneNote apps but can't be restored through this connection. A second call for the same page fails with not found.",
+ idempotent: false,
+ },
+ props: {
+ pageId: microsoftOneNoteAiProps.pageId({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/pages/${encodeURIComponent(propsValue.pageId)}`)
+ .delete();
+ return { pageId: propsValue.pageId, deleted: true };
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-notebook-from-web-url.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-notebook-from-web-url.ts
new file mode 100644
index 00000000000..98054213ccf
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-notebook-from-web-url.ts
@@ -0,0 +1,36 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteGetNotebookFromWebUrlOutputSchema } from '../../output-schemas';
+
+import type { CopyNotebookModel } from '../../common/types';
+
+export const getNotebookFromWebUrlAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_notebook_from_web_url',
+ outputSchema: microsoftOnenoteGetNotebookFromWebUrlOutputSchema,
+ displayName: 'Get Notebook from Web URL',
+ description: 'Gets a OneNote notebook from its web URL.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Resolves a OneNote notebook web URL (the oneNoteWebUrl a link or Get Recent Notebooks gives) to the notebook with its ID, so other actions can use it. Work or school accounts only.',
+ idempotent: true,
+ },
+ props: {
+ webUrl: Property.ShortText({
+ displayName: 'Web URL',
+ description: 'The notebook web URL, for example its OneNote for the web link.',
+ required: true,
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const response: CopyNotebookModel = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/notebooks/getNotebookFromWebUrl`)
+ .post({ webUrl: propsValue.webUrl });
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-notebook.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-notebook.ts
new file mode 100644
index 00000000000..1b14d4ad36a
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-notebook.ts
@@ -0,0 +1,33 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteGetNotebookOutputSchema } from '../../output-schemas';
+
+import type { Notebook } from '../../common/types';
+
+export const getNotebookAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_notebook',
+ outputSchema: microsoftOnenoteGetNotebookOutputSchema,
+ displayName: 'Get Notebook',
+ description: 'Gets a OneNote notebook by ID.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Gets one OneNote notebook (ID from List Notebooks) with its name, owner, sharing state and links.',
+ idempotent: true,
+ },
+ props: {
+ notebookId: microsoftOneNoteAiProps.notebookId({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response: Notebook = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/notebooks/${encodeURIComponent(propsValue.notebookId)}`)
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-operation.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-operation.ts
new file mode 100644
index 00000000000..a13b5ea7978
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-operation.ts
@@ -0,0 +1,37 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteOperationOutputSchema } from '../../output-schemas';
+
+import type { OnenoteOperation } from '../../common/types';
+
+export const getOperationAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_operation',
+ outputSchema: microsoftOnenoteOperationOutputSchema,
+ displayName: 'Get Operation',
+ description: 'Gets the status of a OneNote copy operation.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Reads the status of a copy started by Copy Notebook, Copy Section to Notebook, Copy Section to Section Group or Copy Page to Section, once. Status is NotStarted, Running, Completed or Failed; when Completed, resourceLocation points to the new item.',
+ idempotent: true,
+ },
+ props: {
+ operationId: microsoftOneNoteAiProps.pageId({
+ required: true,
+ displayName: 'Operation ID',
+ description: 'The operation ID a copy action returned.',
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenoteOperation = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/operations/${encodeURIComponent(propsValue.operationId)}`)
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page-content.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page-content.ts
new file mode 100644
index 00000000000..05c16506481
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page-content.ts
@@ -0,0 +1,52 @@
+import { ResponseType } from '@microsoft/microsoft-graph-client';
+
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOneNoteUtils } from '../../common/utils';
+import { microsoftOnenoteGetPageContentOutputSchema } from '../../output-schemas';
+
+export const getPageContentAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_page_content',
+ outputSchema: microsoftOnenoteGetPageContentOutputSchema,
+ displayName: 'Get Page Content',
+ description: 'Gets the HTML content of a OneNote page.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ "Gets a OneNote page's body as HTML (page ID from List Pages). Set Include Element IDs to true to get the data-id and id attributes Update Page Content needs as targets. Images and files appear as resource URLs; use Get Resource Content to download one.",
+ idempotent: true,
+ },
+ props: {
+ pageId: microsoftOneNoteAiProps.pageId({ required: true }),
+ includeIds: Property.StaticDropdown({
+ displayName: 'Include Element IDs',
+ description: 'Whether to add the element IDs that Update Page Content can target.',
+ required: false,
+ options: {
+ disabled: false,
+ options: [
+ { label: 'Yes', value: 'true' },
+ { label: 'No', value: 'false' },
+ ],
+ },
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const includeIds = microsoftOneNoteUtils.booleanChoice({
+ value: propsValue.includeIds,
+ propName: 'Include Element IDs',
+ });
+ const content: string = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/pages/${encodeURIComponent(propsValue.pageId)}/content`)
+ .query(includeIds ? { includeIDs: 'true' } : {})
+ .responseType(ResponseType.TEXT)
+ .get();
+ return { pageId: propsValue.pageId, content };
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page-preview.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page-preview.ts
new file mode 100644
index 00000000000..0aa8b8f0003
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page-preview.ts
@@ -0,0 +1,33 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteGetPagePreviewOutputSchema } from '../../output-schemas';
+
+import type { OnenotePagePreview } from '../../common/types';
+
+export const getPagePreviewAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_page_preview',
+ outputSchema: microsoftOnenoteGetPagePreviewOutputSchema,
+ displayName: 'Get Page Preview',
+ description: 'Gets a short text preview of a OneNote page.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Gets a short plain-text preview (up to about 300 characters) and preview image link of a OneNote page (ID from List Pages). Cheaper than Get Page Content when you only need to tell pages apart.',
+ idempotent: true,
+ },
+ props: {
+ pageId: microsoftOneNoteAiProps.pageId({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenotePagePreview = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/pages/${encodeURIComponent(propsValue.pageId)}/preview()`)
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page.ts
new file mode 100644
index 00000000000..b375660251d
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-page.ts
@@ -0,0 +1,34 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteGetPageOutputSchema } from '../../output-schemas';
+
+import type { OnenotePage } from '../../common/types';
+
+export const getPageAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_page',
+ outputSchema: microsoftOnenoteGetPageOutputSchema,
+ displayName: 'Get Page',
+ description: 'Gets a OneNote page by ID.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ "Gets one OneNote page's metadata (ID from List Pages): title, dates, links, parent notebook and parent section. Use Get Page Content for its HTML body or Get Page Preview for a short text preview.",
+ idempotent: true,
+ },
+ props: {
+ pageId: microsoftOneNoteAiProps.pageId({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenotePage = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/pages/${encodeURIComponent(propsValue.pageId)}`)
+ .expand(['parentNotebook', 'parentSection'])
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-recent-notebooks.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-recent-notebooks.ts
new file mode 100644
index 00000000000..a1f0afe5301
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-recent-notebooks.ts
@@ -0,0 +1,53 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOneNoteUtils } from '../../common/utils';
+import { microsoftOnenoteGetRecentNotebooksOutputSchema } from '../../output-schemas';
+
+import type { MicrosoftOneNoteList, RecentNotebook } from '../../common/types';
+
+export const getRecentNotebooksAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_recent_notebooks',
+ outputSchema: microsoftOnenoteGetRecentNotebooksOutputSchema,
+ displayName: 'Get Recent Notebooks',
+ description: 'Lists the OneNote notebooks you opened recently.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ "Lists the notebooks you opened recently, including ones other people shared with you, with their names, last access time and web links. Use Get Notebook from Web URL to get a listed notebook's ID.",
+ idempotent: true,
+ },
+ props: {
+ includePersonalNotebooks: Property.StaticDropdown({
+ displayName: 'Include Personal Notebooks',
+ description: 'Whether to include notebooks from your personal Microsoft account.',
+ required: true,
+ defaultValue: 'true',
+ options: {
+ disabled: false,
+ options: [
+ { label: 'Yes', value: 'true' },
+ { label: 'No', value: 'false' },
+ ],
+ },
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const includePersonal = microsoftOneNoteUtils.booleanChoice({
+ value: propsValue.includePersonalNotebooks,
+ propName: 'Include Personal Notebooks',
+ });
+ const response: MicrosoftOneNoteList<RecentNotebook> = await microsoftOneNoteClient
+ .create({ auth })
+ .api(
+ `/me/onenote/notebooks/getRecentNotebooks(includePersonalNotebooks=${String(
+ includePersonal ?? true,
+ )})`,
+ )
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-resource-content.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-resource-content.ts
new file mode 100644
index 00000000000..5bf34808ccd
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-resource-content.ts
@@ -0,0 +1,45 @@
+import { ResponseType } from '@microsoft/microsoft-graph-client';
+
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteGetResourceContentOutputSchema } from '../../output-schemas';
+
+export const getResourceContentAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_resource_content',
+ outputSchema: microsoftOnenoteGetResourceContentOutputSchema,
+ displayName: 'Get Resource Content',
+ description: 'Downloads an image or file from a OneNote page.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ "Downloads an image or attached file from a OneNote page and returns it as a file. The resource ID is the part after /resources/ in a src or data attribute of Get Page Content's HTML.",
+ idempotent: true,
+ },
+ props: {
+ resourceId: Property.ShortText({
+ displayName: 'Resource ID',
+ description:
+ 'The ID after /resources/ in an image src or file data URL from Get Page Content.',
+ required: true,
+ }),
+ fileName: Property.ShortText({
+ displayName: 'File Name',
+ description: 'Name for the downloaded file, with its extension. Defaults to the resource ID.',
+ required: false,
+ }),
+ },
+ async run({ auth, propsValue, files }) {
+ const data: ArrayBuffer = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/resources/${encodeURIComponent(propsValue.resourceId)}/content`)
+ .responseType(ResponseType.ARRAYBUFFER)
+ .get();
+ const fileName = propsValue.fileName || propsValue.resourceId;
+ const file = await files.write({ fileName, data: Buffer.from(data) });
+ return { resourceId: propsValue.resourceId, fileName, size: data.byteLength, file };
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-section-group.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-section-group.ts
new file mode 100644
index 00000000000..519196ed11c
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-section-group.ts
@@ -0,0 +1,34 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteGetSectionGroupOutputSchema } from '../../output-schemas';
+
+import type { SectionGroup } from '../../common/types';
+
+export const getSectionGroupAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_section_group',
+ outputSchema: microsoftOnenoteGetSectionGroupOutputSchema,
+ displayName: 'Get Section Group',
+ description: 'Gets a OneNote section group by ID.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Gets one OneNote section group (ID from List Section Groups) with its name, parent notebook and parent section group.',
+ idempotent: true,
+ },
+ props: {
+ sectionGroupId: microsoftOneNoteAiProps.sectionGroupId({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response: SectionGroup = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/sectionGroups/${encodeURIComponent(propsValue.sectionGroupId)}`)
+ .expand(['parentNotebook', 'parentSectionGroup'])
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-section.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-section.ts
new file mode 100644
index 00000000000..bc1ed26ecd3
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/get-section.ts
@@ -0,0 +1,34 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteGetSectionOutputSchema } from '../../output-schemas';
+
+import type { OnenoteSection } from '../../common/types';
+
+export const getSectionAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_get_section',
+ outputSchema: microsoftOnenoteGetSectionOutputSchema,
+ displayName: 'Get Section',
+ description: 'Gets a OneNote section by ID.',
+ audience: 'ai',
+ classification: 'READ',
+ aiMetadata: {
+ description:
+ 'Gets one OneNote section (ID from List Sections) with its name, links, parent notebook and parent section group.',
+ idempotent: true,
+ },
+ props: {
+ sectionId: microsoftOneNoteAiProps.sectionId({ required: true }),
+ },
+ async run({ auth, propsValue }) {
+ const response: OnenoteSection = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/sections/${encodeURIComponent(propsValue.sectionId)}`)
+ .expand(['parentNotebook', 'parentSectionGroup'])
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/index.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/index.ts
new file mode 100644
index 00000000000..0f18c3f9f3f
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/index.ts
@@ -0,0 +1,51 @@
+import { copyNotebookAction } from './copy-notebook';
+import { copyPageToSectionAction } from './copy-page-to-section';
+import { copySectionToNotebookAction } from './copy-section-to-notebook';
+import { copySectionToSectionGroupAction } from './copy-section-to-section-group';
+import { createNotebookAiAction } from './create-notebook';
+import { createPageAiAction } from './create-page';
+import { createSectionAiAction } from './create-section';
+import { createSectionGroupAction } from './create-section-group';
+import { deletePageAction } from './delete-page';
+import { getNotebookAction } from './get-notebook';
+import { getNotebookFromWebUrlAction } from './get-notebook-from-web-url';
+import { getOperationAction } from './get-operation';
+import { getPageAction } from './get-page';
+import { getPageContentAction } from './get-page-content';
+import { getPagePreviewAction } from './get-page-preview';
+import { getRecentNotebooksAction } from './get-recent-notebooks';
+import { getResourceContentAction } from './get-resource-content';
+import { getSectionAction } from './get-section';
+import { getSectionGroupAction } from './get-section-group';
+import { listNotebooksAction } from './list-notebooks';
+import { listPagesAction } from './list-pages';
+import { listSectionGroupsAction } from './list-section-groups';
+import { listSectionsAction } from './list-sections';
+import { updatePageContentAction } from './update-page-content';
+
+export const microsoftOneNoteAiActions = [
+ listNotebooksAction,
+ getNotebookAction,
+ createNotebookAiAction,
+ copyNotebookAction,
+ getNotebookFromWebUrlAction,
+ getRecentNotebooksAction,
+ listSectionGroupsAction,
+ getSectionGroupAction,
+ createSectionGroupAction,
+ listSectionsAction,
+ getSectionAction,
+ createSectionAiAction,
+ copySectionToNotebookAction,
+ copySectionToSectionGroupAction,
+ listPagesAction,
+ getPageAction,
+ getPageContentAction,
+ getPagePreviewAction,
+ createPageAiAction,
+ updatePageContentAction,
+ deletePageAction,
+ copyPageToSectionAction,
+ getResourceContentAction,
+ getOperationAction,
+];
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-notebooks.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-notebooks.ts
new file mode 100644
index 00000000000..64aa5ede83b
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-notebooks.ts
@@ -0,0 +1,38 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOneNoteUtils } from '../../common/utils';
+import { microsoftOnenoteListNotebooksOutputSchema } from '../../output-schemas';
+
+import type { MicrosoftOneNoteList, Notebook } from '../../common/types';
+
+export const listNotebooksAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_list_notebooks',
+ outputSchema: microsoftOnenoteListNotebooksOutputSchema,
+ displayName: 'List Notebooks',
+ description: 'Lists OneNote notebooks.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ 'Lists your own OneNote notebooks with their IDs, names and links, one page at a time. Use Get Recent Notebooks for notebooks you opened recently, including shared ones.',
+ idempotent: true,
+ },
+ props: {
+ limit: microsoftOneNoteAiProps.limit({ required: false }),
+ skip: microsoftOneNoteAiProps.skip({ required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const top = microsoftOneNoteUtils.pageSize({ limit: propsValue.limit });
+ const skip = microsoftOneNoteUtils.offset({ skip: propsValue.skip });
+ const request = microsoftOneNoteClient.create({ auth }).api(`/me/onenote/notebooks`).top(top);
+ const response: MicrosoftOneNoteList<Notebook> = await (skip === undefined
+ ? request
+ : request.skip(skip)
+ ).get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-pages.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-pages.ts
new file mode 100644
index 00000000000..4233785a256
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-pages.ts
@@ -0,0 +1,79 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOneNoteUtils } from '../../common/utils';
+import { microsoftOnenoteListPagesOutputSchema } from '../../output-schemas';
+
+import type { MicrosoftOneNoteList, OnenotePage } from '../../common/types';
+
+const ORDER_BY_OPTIONS = [
+ 'lastModifiedDateTime desc',
+ 'lastModifiedDateTime asc',
+ 'createdDateTime desc',
+ 'createdDateTime asc',
+ 'title asc',
+ 'title desc',
+];
+
+export const listPagesAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_list_pages',
+ outputSchema: microsoftOnenoteListPagesOutputSchema,
+ displayName: 'List Pages',
+ description: 'Lists OneNote pages.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ "Lists OneNote pages with their IDs, titles, dates and links, one page of results at a time (at most 100). Set Section ID (from List Sections) for one section's pages, otherwise lists pages across all sections. Title Contains filters by title, case-insensitively. Use Get Page Content for a page's body.",
+ idempotent: true,
+ },
+ props: {
+ sectionId: microsoftOneNoteAiProps.sectionId({ required: false }),
+ titleContains: Property.ShortText({
+ displayName: 'Title Contains',
+ description: 'Only pages whose title contains this text, ignoring case.',
+ required: false,
+ }),
+ orderBy: Property.StaticDropdown({
+ displayName: 'Order By',
+ description: 'Sort order. Defaults to last modified, newest first.',
+ required: false,
+ options: {
+ disabled: false,
+ options: ORDER_BY_OPTIONS.map((value) => ({ label: value, value })),
+ },
+ }),
+ limit: microsoftOneNoteAiProps.limit({ required: false }),
+ skip: microsoftOneNoteAiProps.skip({ required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const { sectionId, titleContains, orderBy } = propsValue;
+ if (orderBy && !ORDER_BY_OPTIONS.includes(orderBy)) {
+ throw new Error(`Order By must be one of: ${ORDER_BY_OPTIONS.join(', ')}.`);
+ }
+ const parent = sectionId ? `/sections/${encodeURIComponent(sectionId)}` : '';
+ const top = microsoftOneNoteUtils.pageSize({ limit: propsValue.limit });
+ const skip = microsoftOneNoteUtils.offset({ skip: propsValue.skip });
+ const query: Record<string, string> = {
+ $top: String(top),
+ ...(skip !== undefined ? { $skip: String(skip) } : {}),
+ ...(titleContains
+ ? {
+ $filter: `contains(tolower(title),'${titleContains
+ .toLowerCase()
+ .replace(/'/g, "''")}')`,
+ }
+ : {}),
+ ...(orderBy ? { $orderby: orderBy } : {}),
+ };
+ const response: MicrosoftOneNoteList<OnenotePage> = await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote${parent}/pages`)
+ .query(query)
+ .get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-section-groups.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-section-groups.ts
new file mode 100644
index 00000000000..f6f4b7b8808
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-section-groups.ts
@@ -0,0 +1,57 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOneNoteUtils } from '../../common/utils';
+import { microsoftOnenoteListSectionGroupsOutputSchema } from '../../output-schemas';
+
+import type { MicrosoftOneNoteList, SectionGroup } from '../../common/types';
+
+export const listSectionGroupsAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_list_section_groups',
+ outputSchema: microsoftOnenoteListSectionGroupsOutputSchema,
+ displayName: 'List Section Groups',
+ description: 'Lists OneNote section groups.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ "Lists OneNote section groups with their IDs, names and parents, one page at a time. Set Notebook ID (from List Notebooks) for one notebook's top-level groups, or Parent Section Group ID for the groups nested in a group; leave both empty for every section group. Set at most one of them.",
+ idempotent: true,
+ },
+ props: {
+ notebookId: microsoftOneNoteAiProps.notebookId({ required: false }),
+ parentSectionGroupId: microsoftOneNoteAiProps.sectionGroupId({
+ required: false,
+ displayName: 'Parent Section Group ID',
+ description:
+ 'Lists the section groups nested in this section group. Use List Section Groups to find it.',
+ }),
+ limit: microsoftOneNoteAiProps.limit({ required: false }),
+ skip: microsoftOneNoteAiProps.skip({ required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const { notebookId, parentSectionGroupId } = propsValue;
+ if (notebookId && parentSectionGroupId) {
+ throw new Error('Set at most one of Notebook ID or Parent Section Group ID.');
+ }
+ const parent = notebookId
+ ? `/notebooks/${encodeURIComponent(notebookId)}`
+ : parentSectionGroupId
+ ? `/sectionGroups/${encodeURIComponent(parentSectionGroupId)}`
+ : '';
+ const top = microsoftOneNoteUtils.pageSize({ limit: propsValue.limit });
+ const skip = microsoftOneNoteUtils.offset({ skip: propsValue.skip });
+ const request = microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote${parent}/sectionGroups`)
+ .top(top);
+ const response: MicrosoftOneNoteList<SectionGroup> = await (skip === undefined
+ ? request
+ : request.skip(skip)
+ ).get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-sections.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-sections.ts
new file mode 100644
index 00000000000..854308e92ea
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/list-sections.ts
@@ -0,0 +1,52 @@
+import { createAction } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOneNoteUtils } from '../../common/utils';
+import { microsoftOnenoteListSectionsOutputSchema } from '../../output-schemas';
+
+import type { MicrosoftOneNoteList, OnenoteSection } from '../../common/types';
+
+export const listSectionsAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_list_sections',
+ outputSchema: microsoftOnenoteListSectionsOutputSchema,
+ displayName: 'List Sections',
+ description: 'Lists OneNote sections.',
+ audience: 'ai',
+ classification: 'SEARCH',
+ aiMetadata: {
+ description:
+ "Lists OneNote sections with their IDs, names and links, one page at a time. Set Notebook ID (from List Notebooks) for one notebook's top-level sections, or Section Group ID (from List Section Groups) for one group's; leave both empty for every section. Set at most one of them.",
+ idempotent: true,
+ },
+ props: {
+ notebookId: microsoftOneNoteAiProps.notebookId({ required: false }),
+ sectionGroupId: microsoftOneNoteAiProps.sectionGroupId({ required: false }),
+ limit: microsoftOneNoteAiProps.limit({ required: false }),
+ skip: microsoftOneNoteAiProps.skip({ required: false }),
+ },
+ async run({ auth, propsValue }) {
+ const { notebookId, sectionGroupId } = propsValue;
+ if (notebookId && sectionGroupId) {
+ throw new Error('Set at most one of Notebook ID or Section Group ID.');
+ }
+ const parent = notebookId
+ ? `/notebooks/${encodeURIComponent(notebookId)}`
+ : sectionGroupId
+ ? `/sectionGroups/${encodeURIComponent(sectionGroupId)}`
+ : '';
+ const top = microsoftOneNoteUtils.pageSize({ limit: propsValue.limit });
+ const skip = microsoftOneNoteUtils.offset({ skip: propsValue.skip });
+ const request = microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote${parent}/sections`)
+ .top(top);
+ const response: MicrosoftOneNoteList<OnenoteSection> = await (skip === undefined
+ ? request
+ : request.skip(skip)
+ ).get();
+ return response;
+ },
+});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/update-page-content.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/update-page-content.ts
new file mode 100644
index 00000000000..3acf09b8269
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/ai/update-page-content.ts
@@ -0,0 +1,115 @@
+import { createAction, Property } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../../auth';
+import { microsoftOneNoteAiProps } from '../../common/ai-props';
+import { microsoftOneNoteClient } from '../../common/client';
+import { microsoftOnenoteUpdatePageContentOutputSchema } from '../../output-schemas';
+
+const ACTIONS = ['append', 'prepend', 'insert', 'replace'];
+
+const POSITIONS = ['after', 'before'];
+
+export const updatePageContentAction = createAction({
+ auth: microsoftOneNoteAuth,
+ name: 'microsoft_onenote_update_page_content',
+ outputSchema: microsoftOnenoteUpdatePageContentOutputSchema,
+ displayName: 'Update Page Content',
+ description: 'Changes the content of a OneNote page.',
+ audience: 'ai',
+ classification: 'WRITE',
+ aiMetadata: {
+ description:
+ 'Applies one or more changes to a OneNote page (ID from List Pages): append, prepend, insert or replace HTML at a target. Target "body" or "title", or an element ID from Get Page Content with Include Element IDs set to true. Not idempotent: repeating an append adds the content again.',
+ idempotent: false,
+ },
+ props: {
+ pageId: microsoftOneNoteAiProps.pageId({ required: true }),
+ changes: Property.Array({
+ displayName: 'Changes',
+ description: 'The changes to apply, in order.',
+ required: true,
+ properties: {
+ target: Property.ShortText({
+ displayName: 'Target',
+ description: '"body", "title", or an element data-id or id (#id) from Get Page Content.',
+ required: true,
+ }),
+ action: Property.StaticDropdown({
+ displayName: 'Action',
+ description:
+ 'append, prepend, insert or replace. "title" accepts only replace; "body" accepts append and prepend.',
+ required: true,
+ options: {
+ disabled: false,
+ options: ACTIONS.map((value) => ({ label: value, value })),
+ },
+ }),
+ position: Property.StaticDropdown({
+ displayName: 'Position',
+ description: 'For append and insert: after (default) or before the target.',
+ required: false,
+ options: {
+ disabled: false,
+ options: POSITIONS.map((value) => ({ label: value, value })),
+ },
+ }),
+ content: Property.LongText({
+ displayName: 'Content',
+ description: 'HTML to add, or the new text for a title replace.',
+ required: true,
+ }),
+ },
+ }),
+ },
+ async run({ auth, propsValue }) {
+ const changes = (propsValue.changes ?? []).map((change, index) => toCommand({ change, index }));
+ if (changes.length === 0) {
+ throw new Error('Changes must contain at least one change.');
+ }
+ await microsoftOneNoteClient
+ .create({ auth })
+ .api(`/me/onenote/pages/${encodeURIComponent(propsValue.pageId)}/content`)
+ .patch(changes);
+ return { pageId: propsValue.pageId, appliedChanges: changes.length };
+ },
+});
+
+function toCommand({ change, index }: { change: unknown; index: number }): PatchCommand {
+ if (typeof change !== 'object' || change === null) {
+ throw new Error(`Change ${index + 1} must be an object with target, action and content.`);
+ }
+ const target = 'target' in change ? change.target : undefined;
+ const action = 'action' in change ? change.action : undefined;
+ const position = 'position' in change ? change.position : undefined;
+ const content = 'content' in change ? change.content : undefined;
+ if (typeof target !== 'string' || target === '') {
+ throw new Error(`Change ${index + 1} needs a target.`);
+ }
+ if (typeof action !== 'string' || !ACTIONS.includes(action)) {
+ throw new Error(`Change ${index + 1} action must be one of: ${ACTIONS.join(', ')}.`);
+ }
+ if (
+ position !== undefined &&
+ position !== null &&
+ position !== '' &&
+ (typeof position !== 'string' || !POSITIONS.includes(position))
+ ) {
+ throw new Error(`Change ${index + 1} position must be one of: ${POSITIONS.join(', ')}.`);
+ }
+ if (typeof content !== 'string') {
+ throw new Error(`Change ${index + 1} needs content.`);
+ }
+ return {
+ target,
+ action,
+ content,
+ ...(typeof position === 'string' && position !== '' ? { position } : {}),
+ };
+}
+
+type PatchCommand = {
+ target: string;
+ action: string;
+ position?: string;
+ content: string;
+};
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/append-note.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/append-note.ts
index fe13e75d9cb..92b230032fd 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/actions/append-note.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/append-note.ts
@@ -1,82 +1,30 @@
-import { Property, createAction, OAuth2PropertyValue } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from '../common/microsoft-cloud';
-import { getNotebooksDropdown, getSectionsByNotebookDropdown, getPagesBySectionDropdown } from '../common';
-import { oneNoteAuth } from '../auth';
-import { Client } from '@microsoft/microsoft-graph-client';
+import { Property, createAction } from '@activepieces/pieces-framework';
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from '../common/client';
+import { microsoftOneNoteProps } from '../common/props';
+import { appendNoteOutputSchema } from '../output-schemas';
-export const appendNote = createAction({
- auth: oneNoteAuth,
+export const appendNoteAction = createAction({
+ auth: microsoftOneNoteAuth,
name: 'append_note',
+ outputSchema: appendNoteOutputSchema,
classification: 'WRITE',
displayName: 'Append Note',
description: 'Append content to the end of an existing note.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Appends content to the body of an existing OneNote page (note), identified by notebook, section, and page. Use to add to a note rather than replace it; the content type can be a paragraph, list item, heading, or raw HTML. Not idempotent: each call appends again, so repeating duplicates the content.', idempotent: false },
props: {
- notebook_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Notebook',
- description: 'The notebook containing the page to append to.',
+ notebook_id: microsoftOneNoteProps.notebookId({
required: true,
- refreshers: [],
- options: async ({ auth }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- return await getNotebooksDropdown(auth as OAuth2PropertyValue);
- },
+ description: 'The notebook containing the page to append to.',
}),
- section_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Section',
- description: 'The section containing the page to append to.',
+ section_id: microsoftOneNoteProps.sectionId({
required: true,
- refreshers: ['notebook_id'],
- options: async ({ auth, notebook_id }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- if (!notebook_id) {
- return {
- disabled: true,
- placeholder: 'Select a notebook first',
- options: [],
- };
- }
- return await getSectionsByNotebookDropdown(auth as OAuth2PropertyValue, notebook_id as string);
- },
+ description: 'The section containing the page to append to.',
}),
- page_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Page',
- description: 'The page to append content to.',
+ page_id: microsoftOneNoteProps.pageId({
required: true,
- refreshers: ['section_id'],
- options: async ({ auth, section_id }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- if (!section_id) {
- return {
- disabled: true,
- placeholder: 'Select a section first',
- options: [],
- };
- }
- return await getPagesBySectionDropdown(auth as OAuth2PropertyValue, section_id as string);
- },
+ description: 'The page to append content to.',
}),
content_type: Property.StaticDropdown({
displayName: 'Content Type',
@@ -118,17 +66,10 @@ export const appendNote = createAction({
const { auth, propsValue } = context;
const { page_id, content_type, content, heading_level } = propsValue;
- const authValue = auth as OAuth2PropertyValue;
- const cloud = authValue.props?.['cloud'] as string | undefined;
- const client = Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(authValue.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
+ const client = microsoftOneNoteClient.create({ auth });
let htmlContent: string;
-
+
switch (content_type) {
case 'paragraph':
htmlContent = `<p>${content}</p>`;
@@ -168,8 +109,8 @@ export const appendNote = createAction({
contentType: content_type,
appendedContent: htmlContent,
};
- } catch (error: any) {
- throw new Error(`Failed to append content: ${error.message || 'Unknown error'}`);
+ } catch (error) {
+ throw new Error(`Failed to append content: ${(error instanceof Error && error.message) || 'Unknown error'}`);
}
},
});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-image-note.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-image-note.ts
index f35d14b67a0..5afb1b56249 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-image-note.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-image-note.ts
@@ -1,58 +1,27 @@
-import { Property, createAction, OAuth2PropertyValue } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from '../common/microsoft-cloud';
-import { getNotebooksDropdown, getSectionsByNotebookDropdown } from '../common';
-import { oneNoteAuth } from '../auth';
-import { Client } from '@microsoft/microsoft-graph-client';
+import { Property, createAction } from '@activepieces/pieces-framework';
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from '../common/client';
+import { microsoftOneNoteProps } from '../common/props';
+import type { OnenotePage } from '../common/types';
+import { createImageNoteOutputSchema } from '../output-schemas';
-export const createImageNote = createAction({
- auth: oneNoteAuth,
+export const createImageNoteAction = createAction({
+ auth: microsoftOneNoteAuth,
name: 'create_image_note',
+ outputSchema: createImageNoteOutputSchema,
classification: 'WRITE',
displayName: 'Create Image Note',
description: 'Create a note containing an embedded image via a public image URL.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Creates a new OneNote page in a section with an embedded image referenced by a publicly accessible image URL, plus an optional title and description. Choose this over Create Page when the note is primarily an image; the image URL must be reachable by Microsoft Graph. Not idempotent: each call creates a new page.', idempotent: false },
props: {
- notebook_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Notebook',
- description: 'The notebook to create the image note in.',
+ notebook_id: microsoftOneNoteProps.notebookId({
required: true,
- refreshers: [],
- options: async ({ auth }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- return await getNotebooksDropdown(auth as OAuth2PropertyValue);
- },
+ description: 'The notebook to create the image note in.',
}),
- section_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Section',
- description: 'The section to create the image note in.',
+ section_id: microsoftOneNoteProps.sectionId({
required: true,
- refreshers: ['notebook_id'],
- options: async ({ auth, notebook_id }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- if (!notebook_id) {
- return {
- disabled: true,
- placeholder: 'Select a notebook first',
- options: [],
- };
- }
- return await getSectionsByNotebookDropdown(auth as OAuth2PropertyValue, notebook_id as string);
- },
+ description: 'The section to create the image note in.',
}),
title: Property.ShortText({
displayName: 'Page Title',
@@ -86,16 +55,9 @@ export const createImageNote = createAction({
const { auth, propsValue } = context;
const { section_id, title, image_url, image_width, image_alt_text, description } = propsValue;
- const authValue = auth as OAuth2PropertyValue;
- const cloud = authValue.props?.['cloud'] as string | undefined;
- const client = Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(authValue.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
+ const client = microsoftOneNoteClient.create({ auth });
- const imageTag = image_width
+ const imageTag = image_width
? `<img src="${image_url}" alt="${image_alt_text || 'Embedded image'}" width="${image_width}" />`
: `<img src="${image_url}" alt="${image_alt_text || 'Embedded image'}" />`;
@@ -112,7 +74,7 @@ export const createImageNote = createAction({
</html>`;
try {
- const response = await client
+ const response: OnenotePage = await client
.api(`/me/onenote/sections/${section_id}/pages`)
.header('Content-Type', 'application/xhtml+xml')
.post(htmlContent);
@@ -130,8 +92,8 @@ export const createImageNote = createAction({
links: response.links,
self: response.self,
};
- } catch (error: any) {
- throw new Error(`Failed to create image note: ${error.message || 'Unknown error'}`);
+ } catch (error) {
+ throw new Error(`Failed to create image note: ${(error instanceof Error && error.message) || 'Unknown error'}`);
}
},
});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-note-in-section.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-note-in-section.ts
index 1aaedd0f7a2..1181b3357dd 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-note-in-section.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-note-in-section.ts
@@ -1,58 +1,27 @@
-import { Property, createAction, OAuth2PropertyValue } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from '../common/microsoft-cloud';
-import { getNotebooksDropdown, getSectionsByNotebookDropdown } from '../common';
-import { oneNoteAuth } from '../auth';
-import { Client } from '@microsoft/microsoft-graph-client';
+import { Property, createAction } from '@activepieces/pieces-framework';
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from '../common/client';
+import { microsoftOneNoteProps } from '../common/props';
+import type { OnenotePage } from '../common/types';
+import { createNoteInSectionOutputSchema } from '../output-schemas';
-export const createNoteInSection = createAction({
- auth: oneNoteAuth,
+export const createNoteInSectionAction = createAction({
+ auth: microsoftOneNoteAuth,
name: 'create_note_in_section',
+ outputSchema: createNoteInSectionOutputSchema,
classification: 'WRITE',
displayName: 'Create Note in Section',
description: 'Create a new note in a specific section with title and content.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Creates a new OneNote page (note) in a chosen notebook section with a title and optional HTML body content. Use when adding a fresh note; content accepts basic HTML tags. Not idempotent: each call creates a new page even with identical input.', idempotent: false },
props: {
- notebook_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Notebook',
- description: 'The notebook to create the note in.',
+ notebook_id: microsoftOneNoteProps.notebookId({
required: true,
- refreshers: [],
- options: async ({ auth }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- return await getNotebooksDropdown(auth as OAuth2PropertyValue);
- },
+ description: 'The notebook to create the note in.',
}),
- section_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Section',
- description: 'The section to create the note in.',
+ section_id: microsoftOneNoteProps.sectionId({
required: true,
- refreshers: ['notebook_id'],
- options: async ({ auth, notebook_id }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- if (!notebook_id) {
- return {
- disabled: true,
- placeholder: 'Select a notebook first',
- options: [],
- };
- }
- return await getSectionsByNotebookDropdown(auth as OAuth2PropertyValue, notebook_id as string);
- },
+ description: 'The section to create the note in.',
}),
title: Property.ShortText({
displayName: 'Note Title',
@@ -70,15 +39,7 @@ export const createNoteInSection = createAction({
const { auth, propsValue } = context;
const { section_id, title, content } = propsValue;
- const authValue = auth as OAuth2PropertyValue;
- const cloud = authValue.props?.['cloud'] as string | undefined;
- const client = Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(authValue.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
-
+ const client = microsoftOneNoteClient.create({ auth });
const htmlContent = `<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
@@ -92,7 +53,7 @@ export const createNoteInSection = createAction({
</html>`;
try {
- const response = await client
+ const response: OnenotePage = await client
.api(`/me/onenote/sections/${section_id}/pages`)
.header('Content-Type', 'application/xhtml+xml')
.post(htmlContent);
@@ -109,8 +70,8 @@ export const createNoteInSection = createAction({
links: response.links,
self: response.self,
};
- } catch (error: any) {
- throw new Error(`Failed to create note: ${error.message || 'Unknown error'}`);
+ } catch (error) {
+ throw new Error(`Failed to create note: ${(error instanceof Error && error.message) || 'Unknown error'}`);
}
},
});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-notebook.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-notebook.ts
index 774aa50a617..11917d854ac 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-notebook.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-notebook.ts
@@ -1,15 +1,17 @@
-import { Property, createAction, OAuth2PropertyValue } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from '../common/microsoft-cloud';
-import { oneNoteAuth } from '../auth';
-import { Client } from '@microsoft/microsoft-graph-client';
+import { Property, createAction } from '@activepieces/pieces-framework';
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from '../common/client';
+import type { Notebook } from '../common/types';
+import { createNotebookOutputSchema } from '../output-schemas';
-export const createNotebook = createAction({
- auth: oneNoteAuth,
+export const createNotebookAction = createAction({
+ auth: microsoftOneNoteAuth,
name: 'create_notebook',
+ outputSchema: createNotebookOutputSchema,
classification: 'WRITE',
displayName: 'Create Notebook',
description: 'Creates a notebook.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Creates a new OneNote notebook for the authenticated user, given a display name. Use as the top-level container before adding sections and pages; the name must be unique, under 128 characters, and avoid characters such as ?*/:<>|\'"%~. Not idempotent: each call attempts to create another notebook.', idempotent: false },
props: {
displayName: Property.ShortText({
@@ -22,21 +24,14 @@ export const createNotebook = createAction({
const { auth, propsValue } = context;
const { displayName } = propsValue;
- const authValue = auth as OAuth2PropertyValue;
- const cloud = authValue.props?.['cloud'] as string | undefined;
- const client = Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(authValue.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
+ const client = microsoftOneNoteClient.create({ auth });
const notebookBody = {
displayName,
};
try {
- const response = await client.api('/me/onenote/notebooks').post(notebookBody);
+ const response: Notebook = await client.api('/me/onenote/notebooks').post(notebookBody);
return {
id: response.id,
@@ -53,8 +48,8 @@ export const createNotebook = createAction({
links: response.links,
self: response.self,
};
- } catch (error: any) {
- throw new Error(`Failed to create notebook: ${error.message || 'Unknown error'}`);
+ } catch (error) {
+ throw new Error(`Failed to create notebook: ${(error instanceof Error && error.message) || 'Unknown error'}`);
}
},
});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-page.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-page.ts
index e2f20868b34..62a5542f324 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-page.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-page.ts
@@ -1,58 +1,27 @@
-import { Property, createAction, OAuth2PropertyValue } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from '../common/microsoft-cloud';
-import { getNotebooksDropdown, getSectionsByNotebookDropdown } from '../common';
-import { oneNoteAuth } from '../auth';
-import { Client } from '@microsoft/microsoft-graph-client';
+import { Property, createAction } from '@activepieces/pieces-framework';
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from '../common/client';
+import { microsoftOneNoteProps } from '../common/props';
+import type { OnenotePage } from '../common/types';
+import { createNoteInSectionOutputSchema } from '../output-schemas';
-export const createPage = createAction({
- auth: oneNoteAuth,
+export const createPageAction = createAction({
+ auth: microsoftOneNoteAuth,
name: 'create_page',
+ outputSchema: createNoteInSectionOutputSchema,
classification: 'WRITE',
displayName: 'Create Page',
description: 'Creates a page in section.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Creates a new OneNote page in a chosen notebook section with a title and optional HTML body content. Functionally similar to Create Note in Section; pick either to add a text page. Content accepts basic HTML tags. Not idempotent: each call creates a new page.', idempotent: false },
props: {
- notebook_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Notebook',
- description: 'The notebook to create the page in.',
+ notebook_id: microsoftOneNoteProps.notebookId({
required: true,
- refreshers: [],
- options: async ({ auth }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- return await getNotebooksDropdown(auth as OAuth2PropertyValue);
- },
+ description: 'The notebook to create the page in.',
}),
- section_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Section',
- description: 'The section to create the page in.',
+ section_id: microsoftOneNoteProps.sectionId({
required: true,
- refreshers: ['notebook_id'],
- options: async ({ auth, notebook_id }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- if (!notebook_id) {
- return {
- disabled: true,
- placeholder: 'Select a notebook first',
- options: [],
- };
- }
- return await getSectionsByNotebookDropdown(auth as OAuth2PropertyValue, notebook_id as string);
- },
+ description: 'The section to create the page in.',
}),
title: Property.ShortText({
displayName: 'Page Title',
@@ -70,14 +39,7 @@ export const createPage = createAction({
const { auth, propsValue } = context;
const { section_id, title, content } = propsValue;
- const authValue = auth as OAuth2PropertyValue;
- const cloud = authValue.props?.['cloud'] as string | undefined;
- const client = Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(authValue.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
+ const client = microsoftOneNoteClient.create({ auth });
const htmlContent = `<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
@@ -91,7 +53,7 @@ export const createPage = createAction({
</html>`;
try {
- const response = await client
+ const response: OnenotePage = await client
.api(`/me/onenote/sections/${section_id}/pages`)
.header('Content-Type', 'application/xhtml+xml')
.post(htmlContent);
@@ -108,8 +70,8 @@ export const createPage = createAction({
links: response.links,
self: response.self,
};
- } catch (error: any) {
- throw new Error(`Failed to create page: ${error.message || 'Unknown error'}`);
+ } catch (error) {
+ throw new Error(`Failed to create page: ${(error instanceof Error && error.message) || 'Unknown error'}`);
}
},
});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-section.ts b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-section.ts
index f1607de0ccb..95bee7202d6 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/actions/create-section.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/actions/create-section.ts
@@ -1,34 +1,23 @@
-import { Property, createAction, OAuth2PropertyValue } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from '../common/microsoft-cloud';
-import { getNotebooksDropdown } from '../common';
-import { oneNoteAuth } from '../auth';
-import { Client } from '@microsoft/microsoft-graph-client';
+import { Property, createAction } from '@activepieces/pieces-framework';
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from '../common/client';
+import { microsoftOneNoteProps } from '../common/props';
+import type { OnenoteSection } from '../common/types';
+import { createSectionOutputSchema } from '../output-schemas';
-export const createSection = createAction({
- auth: oneNoteAuth,
+export const createSectionAction = createAction({
+ auth: microsoftOneNoteAuth,
name: 'create_section',
+ outputSchema: createSectionOutputSchema,
classification: 'WRITE',
displayName: 'Create Section',
description: 'Creates a new section in notebook.',
- audience: 'both',
+ audience: 'human',
aiMetadata: { description: 'Creates a new section inside a chosen OneNote notebook, given a display name. Use to organize a notebook before adding pages; the name must be unique within the notebook, under 50 characters, and avoid characters such as ?*/:<>|&#\'%~. Not idempotent: each call attempts to create another section.', idempotent: false },
props: {
- notebook_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Notebook',
- description: 'The notebook to create the section in.',
+ notebook_id: microsoftOneNoteProps.notebookId({
required: true,
- refreshers: [],
- options: async ({ auth }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- return await getNotebooksDropdown(auth as OAuth2PropertyValue);
- },
+ description: 'The notebook to create the section in.',
}),
displayName: Property.ShortText({
displayName: 'Section Name',
@@ -40,21 +29,14 @@ export const createSection = createAction({
const { auth, propsValue } = context;
const { notebook_id, displayName } = propsValue;
- const authValue = auth as OAuth2PropertyValue;
- const cloud = authValue.props?.['cloud'] as string | undefined;
- const client = Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(authValue.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
+ const client = microsoftOneNoteClient.create({ auth });
const sectionBody = {
displayName,
};
try {
- const response = await client.api(`/me/onenote/notebooks/${notebook_id}/sections`).post(sectionBody);
+ const response: OnenoteSection = await client.api(`/me/onenote/notebooks/${notebook_id}/sections`).post(sectionBody);
return {
id: response.id,
@@ -68,8 +50,8 @@ export const createSection = createAction({
links: response.links,
self: response.self,
};
- } catch (error: any) {
- throw new Error(`Failed to create section: ${error.message || 'Unknown error'}`);
+ } catch (error) {
+ throw new Error(`Failed to create section: ${(error instanceof Error && error.message) || 'Unknown error'}`);
}
},
});
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/auth.ts b/packages/pieces/community/microsoft-onenote/src/lib/auth.ts
index 2a80e02927b..eef10065e8e 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/auth.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/auth.ts
@@ -1,5 +1,4 @@
-import { PieceAuth } from '@activepieces/pieces-framework';
-import { microsoftCloudProperty } from './common/microsoft-cloud';
+import { PieceAuth, Property } from '@activepieces/pieces-framework';
const authDesc = `
If you’d like to use your own custom Azure app instead of the default app, follow the [Azure app creation guide](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app#register-an-application),
@@ -8,7 +7,21 @@ If you’d like to use your own custom Azure app instead of the default app, fol
- Notes.ReadWrite
- offline_access`;
-export const oneNoteAuth = PieceAuth.OAuth2({
+const microsoftCloudProperty = Property.StaticDropdown({
+ displayName: 'Cloud Environment',
+ description: 'Select your Microsoft cloud environment.',
+ required: true,
+ defaultValue: 'login.microsoftonline.com',
+ options: {
+ disabled: false,
+ options: [
+ { label: 'Commercial (Global)', value: 'login.microsoftonline.com' },
+ { label: 'US Government (GCC High)', value: 'login.microsoftonline.us' },
+ ],
+ },
+});
+
+export const microsoftOneNoteAuth = PieceAuth.OAuth2({
description: authDesc,
props: {
cloud: microsoftCloudProperty,
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/common/ai-props.ts b/packages/pieces/community/microsoft-onenote/src/lib/common/ai-props.ts
new file mode 100644
index 00000000000..1478cb347a7
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/common/ai-props.ts
@@ -0,0 +1,60 @@
+import { Property } from '@activepieces/pieces-framework';
+
+import type { PropParams } from './props';
+
+function notebookId<R extends boolean>({
+ required,
+ displayName = 'Notebook ID',
+ description = 'OneNote notebook ID. Use List Notebooks or Get Recent Notebooks to find it.',
+}: PropParams<R>) {
+ return Property.ShortText({ displayName, description, required });
+}
+
+function sectionGroupId<R extends boolean>({
+ required,
+ displayName = 'Section Group ID',
+ description = 'OneNote section group ID. Use List Section Groups to find it.',
+}: PropParams<R>) {
+ return Property.ShortText({ displayName, description, required });
+}
+
+function sectionId<R extends boolean>({
+ required,
+ displayName = 'Section ID',
+ description = 'OneNote section ID. Use List Sections to find it.',
+}: PropParams<R>) {
+ return Property.ShortText({ displayName, description, required });
+}
+
+function pageId<R extends boolean>({
+ required,
+ displayName = 'Page ID',
+ description = 'OneNote page ID. Use List Pages to find it.',
+}: PropParams<R>) {
+ return Property.ShortText({ displayName, description, required });
+}
+
+function limit<R extends boolean>({
+ required,
+ displayName = 'Limit',
+ description = 'Maximum number of items to return, from 1 to 100. Defaults to 20.',
+}: PropParams<R>) {
+ return Property.Number({ displayName, description, required, defaultValue: 20 });
+}
+
+function skip<R extends boolean>({
+ required,
+ displayName = 'Skip',
+ description = 'Number of items to skip, for the next page. Send the same filters with Skip set to the previous Skip plus Limit.',
+}: PropParams<R>) {
+ return Property.Number({ displayName, description, required });
+}
+
+export const microsoftOneNoteAiProps = {
+ notebookId,
+ sectionGroupId,
+ sectionId,
+ pageId,
+ limit,
+ skip,
+};
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/common/client.ts b/packages/pieces/community/microsoft-onenote/src/lib/common/client.ts
new file mode 100644
index 00000000000..e831bc340f2
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/common/client.ts
@@ -0,0 +1,26 @@
+import { Client } from '@microsoft/microsoft-graph-client';
+
+import type { MicrosoftOneNoteAuthValue } from './types';
+
+function baseUrl({ auth }: { auth: MicrosoftOneNoteAuthValue }): string {
+ const host = auth.props?.cloud ?? COMMERCIAL_LOGIN_HOST;
+ return GRAPH_BASE_URLS[host] ?? GRAPH_BASE_URLS[COMMERCIAL_LOGIN_HOST];
+}
+
+function create({ auth }: { auth: MicrosoftOneNoteAuthValue }): Client {
+ return Client.initWithMiddleware({
+ authProvider: {
+ getAccessToken: () => Promise.resolve(auth.access_token),
+ },
+ baseUrl: baseUrl({ auth }),
+ });
+}
+
+export const microsoftOneNoteClient = { baseUrl, create };
+
+const COMMERCIAL_LOGIN_HOST = 'login.microsoftonline.com';
+
+const GRAPH_BASE_URLS: Record<string, string> = {
+ [COMMERCIAL_LOGIN_HOST]: 'https://graph.microsoft.com',
+ 'login.microsoftonline.us': 'https://graph.microsoft.us',
+};
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/common/index.ts b/packages/pieces/community/microsoft-onenote/src/lib/common/index.ts
deleted file mode 100644
index 7d62deeaa54..00000000000
--- a/packages/pieces/community/microsoft-onenote/src/lib/common/index.ts
+++ /dev/null
@@ -1,128 +0,0 @@
-import { OAuth2PropertyValue } from '@activepieces/pieces-framework';
-import { getGraphBaseUrl } from './microsoft-cloud';
-import { Client } from '@microsoft/microsoft-graph-client';
-
-function createClient(auth: OAuth2PropertyValue): ReturnType<typeof Client.initWithMiddleware> {
- const cloud = auth.props?.['cloud'] as string | undefined;
- return Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(auth.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
-}
-
-export async function getNotebooksDropdown(auth: OAuth2PropertyValue) {
- const client = createClient(auth);
-
- try {
- const response = await client.api('/me/onenote/notebooks').get();
-
- return {
- disabled: false,
- options: response.value.map((notebook: any) => ({
- label: notebook.displayName,
- value: notebook.id,
- })),
- };
- } catch (error) {
- console.error('Error fetching notebooks:', error);
- return {
- disabled: true,
- placeholder: 'Failed to load notebooks',
- options: [],
- };
- }
-}
-
-export async function getSectionsDropdown(auth: OAuth2PropertyValue) {
- const client = createClient(auth);
-
- try {
- const response = await client.api('/me/onenote/sections').get();
-
- return {
- disabled: false,
- options: response.value.map((section: any) => ({
- label: section.displayName,
- value: section.id,
- })),
- };
- } catch (error) {
- console.error('Error fetching sections:', error);
- return {
- disabled: true,
- placeholder: 'Failed to load sections',
- options: [],
- };
- }
-}
-
-export async function getPagesDropdown(auth: OAuth2PropertyValue) {
- const client = createClient(auth);
-
- try {
- const response = await client.api('/me/onenote/pages').get();
-
- return {
- disabled: false,
- options: response.value.map((page: any) => ({
- label: page.title,
- value: page.id,
- })),
- };
- } catch (error) {
- console.error('Error fetching pages:', error);
- return {
- disabled: true,
- placeholder: 'Failed to load pages',
- options: [],
- };
- }
-}
-
-export async function getSectionsByNotebookDropdown(auth: OAuth2PropertyValue, notebookId: string) {
- const client = createClient(auth);
-
- try {
- const response = await client.api(`/me/onenote/notebooks/${notebookId}/sections`).get();
-
- return {
- disabled: false,
- options: response.value.map((section: any) => ({
- label: section.displayName,
- value: section.id,
- })),
- };
- } catch (error) {
- console.error('Error fetching sections for notebook:', error);
- return {
- disabled: true,
- placeholder: 'Failed to load sections',
- options: [],
- };
- }
-}
-
-export async function getPagesBySectionDropdown(auth: OAuth2PropertyValue, sectionId: string) {
- const client = createClient(auth);
-
- try {
- const response = await client.api(`/me/onenote/sections/${sectionId}/pages`).get();
-
- return {
- disabled: false,
- options: response.value.map((page: any) => ({
- label: page.title,
- value: page.id,
- })),
- };
- } catch (error) {
- console.error('Error fetching pages for section:', error);
- return {
- disabled: true,
- placeholder: 'Failed to load pages',
- options: [],
- };
- }
-}
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/common/microsoft-cloud.ts b/packages/pieces/community/microsoft-onenote/src/lib/common/microsoft-cloud.ts
deleted file mode 100644
index 065a7056060..00000000000
--- a/packages/pieces/community/microsoft-onenote/src/lib/common/microsoft-cloud.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';
-
-const COMMERCIAL_LOGIN_HOST = 'login.microsoftonline.com';
-const GOV_LOGIN_HOST = 'login.microsoftonline.us';
-
-const GRAPH_BASE_URLS: Record<string, string> = {
- [COMMERCIAL_LOGIN_HOST]: 'https://graph.microsoft.com',
- [GOV_LOGIN_HOST]: 'https://graph.microsoft.us',
-};
-
-export const microsoftCloudProperty = Property.StaticDropdown({
- displayName: 'Cloud Environment',
- description: 'Select your Microsoft cloud environment.',
- required: true,
- defaultValue: COMMERCIAL_LOGIN_HOST,
- options: {
- disabled: false,
- options: [
- { label: 'Commercial (Global)', value: COMMERCIAL_LOGIN_HOST },
- { label: 'US Government (GCC High)', value: GOV_LOGIN_HOST },
- ],
- },
-});
-
-function resolveCloudHost(cloudLoginHost: string | undefined | null): string {
- return cloudLoginHost ?? COMMERCIAL_LOGIN_HOST;
-}
-
-export function getMicrosoftCloudFromAuth(auth: OAuth2PropertyValue): string {
- return resolveCloudHost(auth.props?.['cloud'] as string | undefined);
-}
-
-export function getGraphBaseUrl(cloudLoginHost: string | undefined | null): string {
- const host = resolveCloudHost(cloudLoginHost);
- return GRAPH_BASE_URLS[host] ?? GRAPH_BASE_URLS[COMMERCIAL_LOGIN_HOST];
-}
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/common/props.ts b/packages/pieces/community/microsoft-onenote/src/lib/common/props.ts
new file mode 100644
index 00000000000..06e9a74b821
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/common/props.ts
@@ -0,0 +1,123 @@
+import { DropdownState, Property, tryCatch } from '@activepieces/pieces-framework';
+
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from './client';
+
+import type { MicrosoftOneNoteList, Notebook, OnenotePage, OnenoteSection } from './types';
+
+function notebookId<R extends boolean>({
+ required,
+ displayName = 'Notebook',
+ description = 'The notebook to use.',
+}: PropParams<R>) {
+ return Property.Dropdown({
+ auth: microsoftOneNoteAuth,
+ displayName,
+ description,
+ required,
+ refreshers: [],
+ options: async ({ auth }) => {
+ if (!auth) {
+ return disabledOptions({ placeholder: 'Connect your account first' });
+ }
+ const client = microsoftOneNoteClient.create({ auth });
+ const { data: response, error } = await tryCatch<MicrosoftOneNoteList<Notebook>>(() =>
+ client.api('/me/onenote/notebooks').get(),
+ );
+ if (error) {
+ return disabledOptions({ placeholder: 'Failed to load notebooks' });
+ }
+ return {
+ disabled: false,
+ options: response.value.map((notebook) => ({
+ label: notebook.displayName ?? '',
+ value: notebook.id ?? '',
+ })),
+ };
+ },
+ });
+}
+
+function sectionId<R extends boolean>({
+ required,
+ displayName = 'Section',
+ description = 'The section to use.',
+}: PropParams<R>) {
+ return Property.Dropdown({
+ auth: microsoftOneNoteAuth,
+ displayName,
+ description,
+ required,
+ refreshers: ['notebook_id'],
+ options: async ({ auth, notebook_id }) => {
+ if (!auth) {
+ return disabledOptions({ placeholder: 'Connect your account first' });
+ }
+ if (!notebook_id) {
+ return disabledOptions({ placeholder: 'Select a notebook first' });
+ }
+ const client = microsoftOneNoteClient.create({ auth });
+ const { data: response, error } = await tryCatch<MicrosoftOneNoteList<OnenoteSection>>(() =>
+ client.api(`/me/onenote/notebooks/${String(notebook_id)}/sections`).get(),
+ );
+ if (error) {
+ return disabledOptions({ placeholder: 'Failed to load sections' });
+ }
+ return {
+ disabled: false,
+ options: response.value.map((section) => ({
+ label: section.displayName ?? '',
+ value: section.id ?? '',
+ })),
+ };
+ },
+ });
+}
+
+function pageId<R extends boolean>({
+ required,
+ displayName = 'Page',
+ description = 'The page to use.',
+}: PropParams<R>) {
+ return Property.Dropdown({
+ auth: microsoftOneNoteAuth,
+ displayName,
+ description,
+ required,
+ refreshers: ['section_id'],
+ options: async ({ auth, section_id }) => {
+ if (!auth) {
+ return disabledOptions({ placeholder: 'Connect your account first' });
+ }
+ if (!section_id) {
+ return disabledOptions({ placeholder: 'Select a section first' });
+ }
+ const client = microsoftOneNoteClient.create({ auth });
+ const { data: response, error } = await tryCatch<MicrosoftOneNoteList<OnenotePage>>(() =>
+ client.api(`/me/onenote/sections/${String(section_id)}/pages`).get(),
+ );
+ if (error) {
+ return disabledOptions({ placeholder: 'Failed to load pages' });
+ }
+ return {
+ disabled: false,
+ options: response.value.map((page) => ({
+ label: page.title ?? '',
+ value: page.id ?? '',
+ })),
+ };
+ },
+ });
+}
+
+function disabledOptions({ placeholder }: { placeholder: string }): DropdownState<never> {
+ return { disabled: true, options: [], placeholder };
+}
+
+export const microsoftOneNoteProps = { notebookId, sectionId, pageId };
+
+export type PropParams<R extends boolean> = {
+ required: R;
+ displayName?: string;
+ description?: string;
+};
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/common/types.ts b/packages/pieces/community/microsoft-onenote/src/lib/common/types.ts
new file mode 100644
index 00000000000..807a8196f7e
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/common/types.ts
@@ -0,0 +1,26 @@
+import type { AppConnectionType } from '@activepieces/pieces-framework';
+
+export type {
+ CopyNotebookModel,
+ Notebook,
+ OnenoteOperation,
+ OnenotePage,
+ OnenotePagePreview,
+ OnenoteSection,
+ RecentNotebook,
+ SectionGroup,
+} from '@microsoft/microsoft-graph-types';
+
+export type MicrosoftOneNoteAuthValue = {
+ type:
+ | AppConnectionType.OAUTH2
+ | AppConnectionType.CLOUD_OAUTH2
+ | AppConnectionType.PLATFORM_OAUTH2;
+ access_token: string;
+ props?: { cloud?: string | null };
+};
+
+export type MicrosoftOneNoteList<T> = {
+ value: T[];
+ '@odata.nextLink'?: string;
+};
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/common/utils.ts b/packages/pieces/community/microsoft-onenote/src/lib/common/utils.ts
new file mode 100644
index 00000000000..f6a5d6b5e68
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/common/utils.ts
@@ -0,0 +1,38 @@
+function pageSize({ limit }: { limit: number | undefined }): number {
+ const value = limit ?? DEFAULT_LIMIT;
+ if (!Number.isInteger(value) || value < 1) {
+ throw new Error('Limit must be a whole number of at least 1.');
+ }
+ return Math.min(value, MAX_LIMIT);
+}
+
+function offset({ skip }: { skip: number | undefined }): number | undefined {
+ if (skip === undefined || skip === null) {
+ return undefined;
+ }
+ if (!Number.isInteger(skip) || skip < 0) {
+ throw new Error('Skip must be a whole number of 0 or more.');
+ }
+ return skip;
+}
+
+function booleanChoice({
+ value,
+ propName,
+}: {
+ value: string | undefined;
+ propName: string;
+}): boolean | undefined {
+ if (value === undefined || value === '') {
+ return undefined;
+ }
+ if (value !== 'true' && value !== 'false') {
+ throw new Error(`${propName} must be "true" or "false".`);
+ }
+ return value === 'true';
+}
+
+export const microsoftOneNoteUtils = { pageSize, offset, booleanChoice };
+
+const DEFAULT_LIMIT = 20;
+const MAX_LIMIT = 100;
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/output-schemas.ts b/packages/pieces/community/microsoft-onenote/src/lib/output-schemas.ts
new file mode 100644
index 00000000000..3b52334f4c9
--- /dev/null
+++ b/packages/pieces/community/microsoft-onenote/src/lib/output-schemas.ts
@@ -0,0 +1,302 @@
+import { OutputSchema } from '@activepieces/pieces-framework';
+
+const identityFields: OutputSchema['fields'] = [
+ {
+ key: 'user',
+ label: 'User',
+ children: [{ key: 'displayName', label: 'Name' }],
+ },
+];
+
+const linkFields: OutputSchema['fields'] = [
+ {
+ key: 'oneNoteClientUrl',
+ label: 'OneNote App Link',
+ children: [{ key: 'href', label: 'URL' }],
+ },
+ {
+ key: 'oneNoteWebUrl',
+ label: 'OneNote Web Link',
+ children: [{ key: 'href', label: 'URL', format: 'url' }],
+ },
+];
+
+const auditFields: OutputSchema['fields'] = [
+ { key: 'createdDateTime', label: 'Created At', format: 'datetime' },
+ { key: 'lastModifiedDateTime', label: 'Last Modified At', format: 'datetime' },
+ { key: 'createdBy', label: 'Created By', children: identityFields },
+ { key: 'lastModifiedBy', label: 'Last Modified By', children: identityFields },
+];
+
+const notebookFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Notebook ID' },
+ { key: 'displayName', label: 'Name' },
+ { key: 'isDefault', label: 'Is Default', format: 'boolean' },
+ { key: 'isShared', label: 'Is Shared', format: 'boolean' },
+ { key: 'userRole', label: 'Your Role' },
+ ...auditFields,
+ { key: 'links', label: 'Links', children: linkFields },
+ { key: 'sectionsUrl', label: 'Sections API URL', format: 'url' },
+ { key: 'sectionGroupsUrl', label: 'Section Groups API URL', format: 'url' },
+ { key: 'self', label: 'API URL', format: 'url' },
+];
+
+const sectionGroupFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Section Group ID' },
+ { key: 'displayName', label: 'Name' },
+ ...auditFields,
+ { key: 'sectionsUrl', label: 'Sections API URL', format: 'url' },
+ { key: 'sectionGroupsUrl', label: 'Section Groups API URL', format: 'url' },
+ { key: 'self', label: 'API URL', format: 'url' },
+];
+
+const sectionFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Section ID' },
+ { key: 'displayName', label: 'Name' },
+ { key: 'isDefault', label: 'Is Default', format: 'boolean' },
+ ...auditFields,
+ { key: 'pagesUrl', label: 'Pages API URL', format: 'url' },
+ { key: 'self', label: 'API URL', format: 'url' },
+];
+
+const parentRefFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'ID' },
+ { key: 'displayName', label: 'Name' },
+ { key: 'self', label: 'API URL', format: 'url' },
+];
+
+const parentNotebookField: OutputSchema['fields'][number] = {
+ key: 'parentNotebook',
+ label: 'Parent Notebook',
+ children: notebookFields,
+};
+
+const parentSectionGroupField: OutputSchema['fields'][number] = {
+ key: 'parentSectionGroup',
+ label: 'Parent Section Group',
+ children: sectionGroupFields,
+};
+
+const pageFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Page ID' },
+ { key: 'title', label: 'Title' },
+ { key: 'createdDateTime', label: 'Created At', format: 'datetime' },
+ { key: 'lastModifiedDateTime', label: 'Last Modified At', format: 'datetime' },
+ { key: 'createdByAppId', label: 'Created By App ID' },
+ { key: 'links', label: 'Links', children: linkFields },
+ { key: 'contentUrl', label: 'Content API URL', format: 'url' },
+ { key: 'self', label: 'API URL', format: 'url' },
+];
+
+const operationFields: OutputSchema['fields'] = [
+ { key: 'id', label: 'Operation ID' },
+ { key: 'status', label: 'Status' },
+ { key: 'createdDateTime', label: 'Started At', format: 'datetime' },
+ { key: 'lastActionDateTime', label: 'Last Updated At', format: 'datetime' },
+];
+
+export const microsoftOnenoteDeletePageOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'pageId', label: 'Page ID' },
+ { key: 'deleted', label: 'Deleted', format: 'boolean' },
+ ],
+};
+
+export const microsoftOnenoteCreatePageOutputSchema: OutputSchema = {
+ fields: pageFields,
+};
+
+export const appendNoteOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'success', label: 'Success', format: 'boolean' },
+ { key: 'message', label: 'Message' },
+ { key: 'pageId', label: 'Page ID' },
+ { key: 'contentType', label: 'Content Type' },
+ { key: 'appendedContent', label: 'Appended Content', format: 'html' },
+ ],
+};
+
+export const createNoteInSectionOutputSchema: OutputSchema = {
+ fields: pageFields,
+};
+
+export const createImageNoteOutputSchema: OutputSchema = {
+ fields: [
+ ...pageFields,
+ { key: 'imageUrl', label: 'Image URL', format: 'image' },
+ { key: 'imageWidth', label: 'Image Width', format: 'number' },
+ { key: 'imageAltText', label: 'Image Alt Text' },
+ ],
+};
+
+export const microsoftOnenoteOperationOutputSchema: OutputSchema = {
+ fields: operationFields,
+};
+
+export const microsoftOnenoteCreateNotebookOutputSchema: OutputSchema = {
+ fields: notebookFields,
+};
+
+export const createNotebookOutputSchema: OutputSchema = {
+ fields: notebookFields,
+};
+
+export const microsoftOnenoteGetNotebookFromWebUrlOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'id', label: 'Notebook ID' },
+ { key: 'name', label: 'Name' },
+ { key: 'isDefault', label: 'Is Default', format: 'boolean' },
+ { key: 'isShared', label: 'Is Shared', format: 'boolean' },
+ { key: 'userRole', label: 'Your Role' },
+ { key: 'createdTime', label: 'Created At', format: 'datetime' },
+ { key: 'lastModifiedTime', label: 'Last Modified At', format: 'datetime' },
+ { key: 'createdBy', label: 'Created By' },
+ { key: 'createdByIdentity', label: 'Created By Identity' },
+ { key: 'lastModifiedBy', label: 'Last Modified By' },
+ { key: 'lastModifiedByIdentity', label: 'Last Modified By Identity' },
+ { key: 'links', label: 'Links', children: linkFields },
+ { key: 'sectionsUrl', label: 'Sections API URL', format: 'url' },
+ { key: 'sectionGroupsUrl', label: 'Section Groups API URL', format: 'url' },
+ { key: 'self', label: 'API URL', format: 'url' },
+ ],
+};
+
+export const microsoftOnenoteGetNotebookOutputSchema: OutputSchema = {
+ fields: notebookFields,
+};
+
+export const microsoftOnenoteListNotebooksOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'value', label: 'Notebooks', labelKey: 'displayName', listItems: notebookFields },
+ ],
+};
+
+export const microsoftOnenoteGetRecentNotebooksOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'value',
+ label: 'Recent Notebooks',
+ labelKey: 'displayName',
+ listItems: [
+ { key: 'displayName', label: 'Name' },
+ { key: 'lastAccessedTime', label: 'Last Opened At', format: 'datetime' },
+ { key: 'sourceService', label: 'Source Service' },
+ { key: 'links', label: 'Links', children: linkFields },
+ ],
+ },
+ ],
+};
+
+export const microsoftOnenoteGetPageContentOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'pageId', label: 'Page ID' },
+ { key: 'content', label: 'Content', format: 'html' },
+ ],
+};
+
+export const microsoftOnenoteGetPageOutputSchema: OutputSchema = {
+ fields: [
+ ...pageFields,
+ parentNotebookField,
+ { key: 'parentSection', label: 'Parent Section', children: sectionFields },
+ ],
+};
+
+export const microsoftOnenoteListPagesOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'value',
+ label: 'Pages',
+ labelKey: 'title',
+ listItems: [
+ ...pageFields,
+ { key: 'parentSection', label: 'Parent Section', children: parentRefFields },
+ ],
+ },
+ ],
+};
+
+export const microsoftOnenoteGetPagePreviewOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'previewText', label: 'Preview Text' },
+ {
+ key: 'links',
+ label: 'Links',
+ children: [{ key: 'previewImageUrl', label: 'Preview Image URL' }],
+ },
+ ],
+};
+
+export const microsoftOnenoteUpdatePageContentOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'pageId', label: 'Page ID' },
+ { key: 'appliedChanges', label: 'Changes Applied', format: 'number' },
+ ],
+};
+
+export const microsoftOnenoteGetResourceContentOutputSchema: OutputSchema = {
+ fields: [
+ { key: 'resourceId', label: 'Resource ID' },
+ { key: 'fileName', label: 'File Name' },
+ { key: 'size', label: 'Size', format: 'filesize' },
+ { key: 'file', label: 'File', format: 'url' },
+ ],
+};
+
+export const microsoftOnenoteCreateSectionOutputSchema: OutputSchema = {
+ fields: [...sectionFields, { key: 'links', label: 'Links', children: linkFields }],
+};
+
+export const createSectionOutputSchema: OutputSchema = {
+ fields: [...sectionFields, { key: 'links', label: 'Links', children: linkFields }],
+};
+
+export const microsoftOnenoteGetSectionOutputSchema: OutputSchema = {
+ fields: [...sectionFields, parentNotebookField, parentSectionGroupField],
+};
+
+export const microsoftOnenoteListSectionsOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'value',
+ label: 'Sections',
+ labelKey: 'displayName',
+ listItems: [
+ ...sectionFields,
+ { key: 'parentNotebook', label: 'Parent Notebook', children: parentRefFields },
+ { key: 'parentSectionGroup', label: 'Parent Section Group', children: parentRefFields },
+ ],
+ },
+ ],
+};
+
+export const microsoftOnenoteCreateSectionGroupOutputSchema: OutputSchema = {
+ fields: sectionGroupFields,
+};
+
+export const microsoftOnenoteGetSectionGroupOutputSchema: OutputSchema = {
+ fields: [...sectionGroupFields, parentNotebookField, parentSectionGroupField],
+};
+
+export const microsoftOnenoteListSectionGroupsOutputSchema: OutputSchema = {
+ fields: [
+ {
+ key: 'value',
+ label: 'Section Groups',
+ labelKey: 'displayName',
+ listItems: [
+ ...sectionGroupFields,
+ { key: 'parentNotebook', label: 'Parent Notebook', children: parentRefFields },
+ { key: 'parentSectionGroup', label: 'Parent Section Group', children: parentRefFields },
+ ],
+ },
+ ],
+};
+
+export const newNoteInSectionOutputSchema: OutputSchema = {
+ fields: [
+ ...pageFields,
+ { key: 'parentSection', label: 'Parent Section', children: parentRefFields },
+ { key: 'content', label: 'Content', format: 'html' },
+ ],
+};
diff --git a/packages/pieces/community/microsoft-onenote/src/lib/triggers/new-note-in-section.ts b/packages/pieces/community/microsoft-onenote/src/lib/triggers/new-note-in-section.ts
index ee228a7fe39..92b28392327 100644
--- a/packages/pieces/community/microsoft-onenote/src/lib/triggers/new-note-in-section.ts
+++ b/packages/pieces/community/microsoft-onenote/src/lib/triggers/new-note-in-section.ts
@@ -1,38 +1,33 @@
-import { AppConnectionValueForAuthProperty, OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';
+import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common';
-import { getGraphBaseUrl } from '../common/microsoft-cloud';
-import { getNotebooksDropdown, getSectionsByNotebookDropdown } from '../common';
-import { oneNoteAuth } from '../auth';
-import { Client, PageCollection, ResponseType } from '@microsoft/microsoft-graph-client';
+import { Client, ResponseType } from '@microsoft/microsoft-graph-client';
import dayjs from 'dayjs';
+import { microsoftOneNoteAuth } from '../auth';
+import { microsoftOneNoteClient } from '../common/client';
+import { microsoftOneNoteProps } from '../common/props';
+import type { MicrosoftOneNoteList, OnenotePage } from '../common/types';
+import { newNoteInSectionOutputSchema } from '../output-schemas';
-async function fetchPageContent(client: Client, pageId: string): Promise<string | null> {
+async function fetchPageContent({ client, pageId }: { client: Client; pageId: string | undefined }): Promise<string | null> {
try {
return await client
.api(`/me/onenote/pages/${pageId}/content`)
.responseType(ResponseType.TEXT)
.get();
- } catch (error) {
- console.error(`Failed to fetch content for page ${pageId}:`, error);
+ } catch {
return null;
}
}
-const polling: Polling<AppConnectionValueForAuthProperty<typeof oneNoteAuth>, { notebook_id: string; section_id: string }> = {
+const polling: Polling<AppConnectionValueForAuthProperty<typeof microsoftOneNoteAuth>, { notebook_id: string; section_id: string }> = {
strategy: DedupeStrategy.TIMEBASED,
- items: async ({ auth, propsValue, store, lastFetchEpochMS }) => {
+ items: async ({ auth, propsValue, lastFetchEpochMS }) => {
const sectionId = propsValue.section_id;
- const cloud = auth.props?.['cloud'] as string | undefined;
- const client = Client.initWithMiddleware({
- authProvider: {
- getAccessToken: () => Promise.resolve(auth.access_token),
- },
- baseUrl: getGraphBaseUrl(cloud),
- });
+ const client = microsoftOneNoteClient.create({ auth });
try {
- const pages = [];
+ const pages: OnenotePage[] = [];
let queryParams: string;
if (lastFetchEpochMS === 0) {
@@ -42,7 +37,7 @@ const polling: Polling<AppConnectionValueForAuthProperty<typeof oneNoteAuth>, {
queryParams = `$filter=createdDateTime gt ${lastFetchDate}&$orderby=createdDateTime desc`;
}
- let response: PageCollection = await client
+ let response: MicrosoftOneNoteList<OnenotePage> = await client
.api(`/me/onenote/sections/${sectionId}/pages?${queryParams}`)
.get();
@@ -61,7 +56,7 @@ const polling: Polling<AppConnectionValueForAuthProperty<typeof oneNoteAuth>, {
const pagesWithContent = await Promise.all(
pages.map(async (page) => ({
...page,
- content: await fetchPageContent(client, page.id),
+ content: await fetchPageContent({ client, pageId: page.id }),
})),
);
@@ -69,63 +64,30 @@ const polling: Polling<AppConnectionValueForAuthProperty<typeof oneNoteAuth>, {
epochMilliSeconds: dayjs(page.createdDateTime).valueOf(),
data: page,
}));
- } catch (error: any) {
- console.error('Error fetching new notes from section:', error);
- throw new Error(`Failed to fetch new notes: ${error.message || 'Unknown error'}`);
+ } catch (error) {
+ throw new Error(`Failed to fetch new notes: ${(error instanceof Error && error.message) || 'Unknown error'}`);
}
},
};
export const newNoteInSectionTrigger = createTrigger({
name: 'new_note_in_section',
+ outputSchema: newNoteInSectionOutputSchema,
classification: 'READ',
displayName: 'New Note in Section',
description: 'Fires when a new note is created in a specified section.',
aiMetadata: {
description: 'Fires when a new page (note) is created in a specific OneNote notebook section, detected by polling for pages newer than the last check ordered by creation time. Each event represents one newly created page.',
},
- auth: oneNoteAuth,
+ auth: microsoftOneNoteAuth,
props: {
- notebook_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Notebook',
- description: 'The notebook to monitor for new notes.',
+ notebook_id: microsoftOneNoteProps.notebookId({
required: true,
- refreshers: [],
- options: async ({ auth }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- return await getNotebooksDropdown(auth as OAuth2PropertyValue);
- },
+ description: 'The notebook to monitor for new notes.',
}),
- section_id: Property.Dropdown({
- auth: oneNoteAuth,
- displayName: 'Section',
- description: 'The section to monitor for new notes.',
+ section_id: microsoftOneNoteProps.sectionId({
required: true,
- refreshers: ['notebook_id'],
- options: async ({ auth, notebook_id }) => {
- if (!(auth as OAuth2PropertyValue)?.access_token) {
- return {
- disabled: true,
- placeholder: 'Connect your account first',
- options: [],
- };
- }
- if (!notebook_id) {
- return {
- disabled: true,
- placeholder: 'Select a notebook first',
- options: [],
- };
- }
- return await getSectionsByNotebookDropdown(auth as OAuth2PropertyValue, notebook_id as string);
- },
+ description: 'The section to monitor for new notes.',
}),
},
type: TriggerStrategy.POLLING,