From 0f959b0de797619dc13bbc0bec1b13f98affd15a Mon Sep 17 00:00:00 2001 From: Manoj K Date: Sun, 9 Jul 2023 13:21:58 -0700 Subject: [PATCH] fix: notion integration --- .../migration.sql | 2 ++ engine-server/src/modules/app/app.module.ts | 2 ++ .../docs/models/block/block.controller.ts | 21 +++++++++++----- .../docs/models/block/block.interface.ts | 4 +++- .../docs/models/page/page.controller.ts | 3 +-- engine-server/yarn.lock | 24 ------------------- .../src/layouts/sidebar_layout/navbar.tsx | 1 - integration_definitions.json | 12 +++++++++- integrations/docs/notion/package.json | 4 ++-- integrations/docs/notion/src/index.ts | 4 ++-- .../docs/notion/src/models/page/pages.path.ts | 20 +++++++++++----- .../notion/src/models/page/pages.utils.ts | 7 +++--- integrations/docs/notion/src/spec.ts | 21 +++------------- integrations/docs/notion/yarn.lock | 18 +++++++++++--- 14 files changed, 74 insertions(+), 69 deletions(-) create mode 100644 engine-server/prisma/migrations/20230709181121_add_docs_integration_type/migration.sql diff --git a/engine-server/prisma/migrations/20230709181121_add_docs_integration_type/migration.sql b/engine-server/prisma/migrations/20230709181121_add_docs_integration_type/migration.sql new file mode 100644 index 00000000..75855f22 --- /dev/null +++ b/engine-server/prisma/migrations/20230709181121_add_docs_integration_type/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "IntegrationType" ADD VALUE 'DOCS'; diff --git a/engine-server/src/modules/app/app.module.ts b/engine-server/src/modules/app/app.module.ts index 3065c4b7..e246d318 100644 --- a/engine-server/src/modules/app/app.module.ts +++ b/engine-server/src/modules/app/app.module.ts @@ -10,6 +10,7 @@ import { loggingMiddleware } from 'common/middleware/logging.middleware'; import { AnalyticsModule } from 'modules/analytics/analytics.module'; import { AuthModule } from 'modules/auth/auth.module'; import { MailModule } from 'modules/categories/mail/mail.module'; +import { DocsModule } from 'modules/categories/docs/docs.module'; import { TicketingModule } from 'modules/categories/ticketing/ticketing.module'; import { IntegrationAccountModule } from 'modules/integration_account/integration_account.module'; import { IntegrationDefinitionModule } from 'modules/integration_definition/integration_definition.module'; @@ -43,6 +44,7 @@ import { AppService } from './app.service'; // Categories and their modules TicketingModule, MailModule, + DocsModule, ], controllers: [AppController], providers: [AppService], diff --git a/engine-server/src/modules/categories/docs/models/block/block.controller.ts b/engine-server/src/modules/categories/docs/models/block/block.controller.ts index 93755546..bddf8279 100644 --- a/engine-server/src/modules/categories/docs/models/block/block.controller.ts +++ b/engine-server/src/modules/categories/docs/models/block/block.controller.ts @@ -1,6 +1,6 @@ /** Copyright (c) 2023, Poozle, all rights reserved. **/ -import { Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common'; +import { Body, Controller, Get, Param, Patch, Post, Query, UseGuards } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { IntegrationType } from '@prisma/client'; import { Method, getDataFromAccount } from 'shared/integration_account.utils'; @@ -16,6 +16,9 @@ import { PathParamsWithBlockId, ListBlocksQueryParams, BlocksResponse, + CommonBlockQueryParams, + CreatePageBody, + UpdatePageBody } from './block.interface'; @Controller({ @@ -40,7 +43,7 @@ export class BlockController { // eslint-disable-next-line @typescript-eslint/no-explicit-any { ...defaultQueryParams, ...(query as any) }, // eslint-disable-next-line @typescript-eslint/no-explicit-any - {}, + params as any, ); return blocksResponse; @@ -48,9 +51,11 @@ export class BlockController { @Post('blocks/:block_id') async createBlocks( - @Query() query: ListBlocksQueryParams, + @Query() query: CommonBlockQueryParams, @Param() params: PathParamsWithBlockId, + @Body() + createPageBody: CreatePageBody, @GetIntegrationAccount(IntegrationType.DOCS) integrationAccount: IntegrationAccount, ): Promise { @@ -62,27 +67,31 @@ export class BlockController { { ...defaultQueryParams, ...(query as any) }, // eslint-disable-next-line @typescript-eslint/no-explicit-any params as any, + createPageBody ); return blocksResponse; } - @Post('blocks/:block_id') + @Patch('blocks/:block_id') async updateBlock( - @Query() query: ListBlocksQueryParams, + @Query() query: CommonBlockQueryParams, @Param() params: PathParamsWithBlockId, + @Body() + updatePageBody: UpdatePageBody, @GetIntegrationAccount(IntegrationType.DOCS) integrationAccount: IntegrationAccount, ): Promise { const blocksResponse = await getDataFromAccount( integrationAccount, `/blocks/${params.block_id}`, - Method.GET, + Method.PATCH, // eslint-disable-next-line @typescript-eslint/no-explicit-any { ...defaultQueryParams, ...(query as any) }, // eslint-disable-next-line @typescript-eslint/no-explicit-any params as any, + updatePageBody ); return blocksResponse; diff --git a/engine-server/src/modules/categories/docs/models/block/block.interface.ts b/engine-server/src/modules/categories/docs/models/block/block.interface.ts index c957060f..52a0d20e 100644 --- a/engine-server/src/modules/categories/docs/models/block/block.interface.ts +++ b/engine-server/src/modules/categories/docs/models/block/block.interface.ts @@ -1,6 +1,6 @@ /** Copyright (c) 2023, Poozle, all rights reserved. **/ -import { IsOptional, IsString } from 'class-validator'; +import { IsArray, IsOptional, IsString } from 'class-validator'; import { QueryParams, JustRawParams } from 'common/interfaces/query.interface'; @@ -85,9 +85,11 @@ export class UpdatePageBody { @IsString() block_type: string; + @IsArray() content: Content[]; } export class CreatePageBody { + @IsArray() data: UpdatePageBody[]; } diff --git a/engine-server/src/modules/categories/docs/models/page/page.controller.ts b/engine-server/src/modules/categories/docs/models/page/page.controller.ts index d46440bb..b707b890 100644 --- a/engine-server/src/modules/categories/docs/models/page/page.controller.ts +++ b/engine-server/src/modules/categories/docs/models/page/page.controller.ts @@ -76,10 +76,9 @@ export class PageController { return pageResponse; } - @Post('messages') + @Post('pages') async createPage( @Query() query: CommonPageQueryParams, - @Body() createPageBody: CreatePageBody, @GetIntegrationAccount(IntegrationType.DOCS) integrationAccount: IntegrationAccount, diff --git a/engine-server/yarn.lock b/engine-server/yarn.lock index d5a81e45..ab2aa431 100644 --- a/engine-server/yarn.lock +++ b/engine-server/yarn.lock @@ -1608,11 +1608,6 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f" integrity sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA== -"@types/prompt-sync@^4.2.0": - version "4.2.0" - resolved "https://registry.yarnpkg.com/@types/prompt-sync/-/prompt-sync-4.2.0.tgz#e0bcf80211e9a2edb52891926a0700b2bffe08cb" - integrity sha512-5RPQYDT7MNkt+vq6xp58tSPx4THANyQcBSaw3Ni+KV7MUAgvUUbmCsQmcPVrcc8dwuURSPixz2qTJdJF6ABSKw== - "@types/qs@*": version "6.9.7" resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb" @@ -2034,11 +2029,6 @@ ansi-escapes@^4.2.1: dependencies: type-fest "^0.21.3" -ansi-regex@^4.1.0: - version "4.1.1" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed" - integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g== - ansi-regex@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" @@ -5708,13 +5698,6 @@ progress@2.0.3: resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== -prompt-sync@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/prompt-sync/-/prompt-sync-4.2.0.tgz#0198f73c5b70e3b03e4b9033a50540a7c9a1d7f4" - integrity sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw== - dependencies: - strip-ansi "^5.0.0" - prompts@2.4.2, prompts@^2.0.1: version "2.4.2" resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069" @@ -6369,13 +6352,6 @@ strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1: dependencies: ansi-regex "^5.0.1" -strip-ansi@^5.0.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" - integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== - dependencies: - ansi-regex "^4.1.0" - strip-bom@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" diff --git a/engine-webapp/src/layouts/sidebar_layout/navbar.tsx b/engine-webapp/src/layouts/sidebar_layout/navbar.tsx index 007df836..5b54c3c1 100644 --- a/engine-webapp/src/layouts/sidebar_layout/navbar.tsx +++ b/engine-webapp/src/layouts/sidebar_layout/navbar.tsx @@ -16,7 +16,6 @@ import { } from '@mantine/core'; import { IconSettings, - IconApps, IconArrowBarLeft, IconArrowBarRight, IconUser, diff --git a/integration_definitions.json b/integration_definitions.json index d75331ce..a76b214f 100644 --- a/integration_definitions.json +++ b/integration_definitions.json @@ -33,4 +33,14 @@ "releaseStage": "ALPHA", "sourceUrl": "https://raw.githubusercontent.com/poozlehq/build-artifacts/main/messaging/slack/0.1.0/index.js", "integrationType": "MESSAGING" - } ] \ No newline at end of file + }, + { + "name": "Notion", + "key": "notion", + "icon": "notion.svg", + "version": "0.1.2", + "releaseStage": "ALPHA", + "sourceUrl": "https://raw.githubusercontent.com/poozlehq/build-artifacts/main/docs/notion/0.1.2/index.js", + "integrationType": "DOCS" + } + ] \ No newline at end of file diff --git a/integrations/docs/notion/package.json b/integrations/docs/notion/package.json index c900dfe7..3067e7a9 100644 --- a/integrations/docs/notion/package.json +++ b/integrations/docs/notion/package.json @@ -1,6 +1,6 @@ { "name": "@poozle/notion", - "version": "0.1.0", + "version": "0.1.2", "description": "notion extension for Poozle", "exports": { ".": { @@ -47,7 +47,7 @@ "access": "public" }, "dependencies": { - "@poozle/engine-idk": "file:../../../engine-idk/idk", + "@poozle/engine-idk": "^0.1.11", "axios": "^1.4.0" }, "browserslist": { diff --git a/integrations/docs/notion/src/index.ts b/integrations/docs/notion/src/index.ts index c3816710..f51f9c0c 100644 --- a/integrations/docs/notion/src/index.ts +++ b/integrations/docs/notion/src/index.ts @@ -7,7 +7,7 @@ import { NotionPageModel } from 'models/page/page.model'; import spec from './spec'; -class GmailIntegration extends BaseIntegration { +class NotionIntegration extends BaseIntegration { async spec(): SpecificationResponse { return spec; } @@ -19,7 +19,7 @@ class GmailIntegration extends BaseIntegration { // eslint-disable-next-line @typescript-eslint/no-explicit-any export async function main(command: string, allParams: any) { - const integration = new GmailIntegration(); + const integration = new NotionIntegration(); const response = await integration.runCommand(command, allParams); diff --git a/integrations/docs/notion/src/models/page/pages.path.ts b/integrations/docs/notion/src/models/page/pages.path.ts index d28f84ed..7f37ba11 100644 --- a/integrations/docs/notion/src/models/page/pages.path.ts +++ b/integrations/docs/notion/src/models/page/pages.path.ts @@ -41,20 +41,28 @@ export class GetPagesPath extends BasePath { ); next_cursor = pagesResponse.data.next_cursor; - return Promise.all( - pagesResponse.data.results?.map((data: any) => { + return pagesResponse.data.results?.map((data: any) => { return convertPage(data); - }), - ); + }) } async createPage(url: string, headers: AxiosHeaders, params: Params) { const body = { - parent: { pageId: params.requestBody?.parent_id }, - title: params.requestBody?.title, + parent: { page_id: params.requestBody?.parent_id.replace(/-/g, '')}, + properties: { + title: [ + { + text: { + content: params.requestBody?.title, + }, + }, + ], + }, }; const response = await axios.post(url, body, { headers }); + + return convertPage(response.data); } diff --git a/integrations/docs/notion/src/models/page/pages.utils.ts b/integrations/docs/notion/src/models/page/pages.utils.ts index 38ed5bc5..47a046e7 100644 --- a/integrations/docs/notion/src/models/page/pages.utils.ts +++ b/integrations/docs/notion/src/models/page/pages.utils.ts @@ -4,13 +4,14 @@ export const BASE_URL = 'https://api.notion.com/v1'; export function convertPage(pageData: any) { - const parentKey = Object.keys(pageData.properties).find( + const titleKey = Object.keys(pageData.properties).find( (key) => pageData.properties[key].id === 'title', ); + return { id: pageData.id, - parent_id: pageData.parent?.id, - title: parentKey ? pageData.properties[parentKey].title[0].plain_text : '', + parent_id: pageData.parent[pageData.parent?.type] || '', + title: titleKey ? pageData.properties[titleKey].title[0]?.plain_text : '', created_by: pageData.created_by.id, created_at: pageData.created_time, updated_at: pageData.last_edited_time, diff --git a/integrations/docs/notion/src/spec.ts b/integrations/docs/notion/src/spec.ts index 4d5b94d1..2e89b4cd 100644 --- a/integrations/docs/notion/src/spec.ts +++ b/integrations/docs/notion/src/spec.ts @@ -1,10 +1,9 @@ /** Copyright (c) 2023, Poozle, all rights reserved. **/ export default { - authSupported: ['Api Key'], - authSpecification: { + auth_specification: { 'Api Key': { - inputSpecification: { + input_specification: { type: 'object', properties: { api_key: { @@ -19,19 +18,5 @@ export default { 'Notion-Version': '2022-06-28', }, }, - }, - supportedFilters: [ - 'subject', - 'from', - 'to', - 'cc', - 'bcc', - 'labels', - 'starred', - 'unread', - 'direction', - 'received_after', - 'received_before', - ], - supportedSortBy: ['received_at'], + } }; diff --git a/integrations/docs/notion/yarn.lock b/integrations/docs/notion/yarn.lock index 3f2e865f..34decb44 100644 --- a/integrations/docs/notion/yarn.lock +++ b/integrations/docs/notion/yarn.lock @@ -1109,8 +1109,13 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@poozle/engine-idk@file:../../../engine-idk/idk": - version "0.0.0" +"@poozle/engine-idk@^0.1.11": + version "0.1.11" + resolved "https://registry.yarnpkg.com/@poozle/engine-idk/-/engine-idk-0.1.11.tgz#b42a671fbf1f741148f30e0c93a77aad064696c8" + integrity sha512-GECfyoPs9m6pA/fzZNMVxb5ePB2zbKATCHOnoCUiAEktfjcarlw1+Y/vnr9f1B9DLEaiN3W4yVs6ooF8XhS5rA== + dependencies: + axios "^1.3.2" + qs "^6.11.2" "@rollup/plugin-babel@6.0.2": version "6.0.2" @@ -1387,7 +1392,7 @@ available-typed-arrays@^1.0.5: resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== -axios@^1.4.0: +axios@^1.3.2, axios@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== @@ -2763,6 +2768,13 @@ punycode@^2.1.0: resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.0.tgz#f67fa67c94da8f4d0cfff981aee4118064199b8f" integrity sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA== +qs@^6.11.2: + version "6.11.2" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9" + integrity sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA== + dependencies: + side-channel "^1.0.4" + queue-microtask@^1.2.2: version "1.2.3" resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"