Skip to content

Commit

Permalink
fix: notion integration
Browse files Browse the repository at this point in the history
  • Loading branch information
saimanoj committed Jul 9, 2023
1 parent 64131b4 commit 0f959b0
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "IntegrationType" ADD VALUE 'DOCS';
2 changes: 2 additions & 0 deletions engine-server/src/modules/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -43,6 +44,7 @@ import { AppService } from './app.service';
// Categories and their modules
TicketingModule,
MailModule,
DocsModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,6 +16,9 @@ import {
PathParamsWithBlockId,
ListBlocksQueryParams,
BlocksResponse,
CommonBlockQueryParams,
CreatePageBody,
UpdatePageBody
} from './block.interface';

@Controller({
Expand All @@ -40,17 +43,19 @@ 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;
}

@Post('blocks/:block_id')
async createBlocks(
@Query() query: ListBlocksQueryParams,
@Query() query: CommonBlockQueryParams,
@Param()
params: PathParamsWithBlockId,
@Body()
createPageBody: CreatePageBody,
@GetIntegrationAccount(IntegrationType.DOCS)
integrationAccount: IntegrationAccount,
): Promise<BlocksResponse> {
Expand All @@ -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<BlocksResponse> {
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -85,9 +85,11 @@ export class UpdatePageBody {
@IsString()
block_type: string;

@IsArray()
content: Content[];
}

export class CreatePageBody {
@IsArray()
data: UpdatePageBody[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 0 additions & 24 deletions engine-server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion engine-webapp/src/layouts/sidebar_layout/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '@mantine/core';
import {
IconSettings,
IconApps,
IconArrowBarLeft,
IconArrowBarRight,
IconUser,
Expand Down
12 changes: 11 additions & 1 deletion integration_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@
"releaseStage": "ALPHA",
"sourceUrl": "https://raw.githubusercontent.com/poozlehq/build-artifacts/main/messaging/slack/0.1.0/index.js",
"integrationType": "MESSAGING"
} ]
},
{
"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"
}
]
4 changes: 2 additions & 2 deletions integrations/docs/notion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poozle/notion",
"version": "0.1.0",
"version": "0.1.2",
"description": "notion extension for Poozle",
"exports": {
".": {
Expand Down Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions integrations/docs/notion/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down
20 changes: 14 additions & 6 deletions integrations/docs/notion/src/models/page/pages.path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 4 additions & 3 deletions integrations/docs/notion/src/models/page/pages.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 3 additions & 18 deletions integrations/docs/notion/src/spec.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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'],
}
};
18 changes: 15 additions & 3 deletions integrations/docs/notion/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0f959b0

Please sign in to comment.