feat: Convert all app files to JS
This commit is contained in:
4
packages/backend/src/apps/notion/dynamic-data/index.js
Normal file
4
packages/backend/src/apps/notion/dynamic-data/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import listDatabases from './list-databases/index.js';
|
||||
import listParentPages from './list-parent-pages/index.js';
|
||||
|
||||
export default [listDatabases, listParentPages];
|
@@ -1,4 +0,0 @@
|
||||
import listDatabases from './list-databases';
|
||||
import listParentPages from './list-parent-pages';
|
||||
|
||||
export default [listDatabases, listParentPages];
|
@@ -0,0 +1,32 @@
|
||||
export default {
|
||||
name: 'List databases',
|
||||
key: 'listDatabases',
|
||||
|
||||
async run($) {
|
||||
const databases = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
const payload = {
|
||||
filter: {
|
||||
value: 'database',
|
||||
property: 'object',
|
||||
},
|
||||
};
|
||||
|
||||
do {
|
||||
const response = await $.http.post('/v1/search', payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
for (const database of response.data.results) {
|
||||
databases.data.push({
|
||||
value: database.id,
|
||||
name: database.title[0].plain_text,
|
||||
});
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
|
||||
return databases;
|
||||
},
|
||||
};
|
@@ -1,60 +0,0 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Database = {
|
||||
id: string;
|
||||
name: string;
|
||||
title: [
|
||||
{
|
||||
plain_text: string;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
type ResponseData = {
|
||||
results: Database[];
|
||||
next_cursor?: string;
|
||||
}
|
||||
|
||||
type Payload = {
|
||||
filter: {
|
||||
value: 'database';
|
||||
property: 'object';
|
||||
};
|
||||
start_cursor?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'List databases',
|
||||
key: 'listDatabases',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const databases: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
const payload: Payload = {
|
||||
filter: {
|
||||
value: 'database',
|
||||
property: 'object'
|
||||
},
|
||||
};
|
||||
|
||||
do {
|
||||
const response = await $.http.post<ResponseData>('/v1/search', payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
for (const database of response.data.results) {
|
||||
databases.data.push({
|
||||
value: database.id as string,
|
||||
name: database.title[0].plain_text as string,
|
||||
});
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
|
||||
return databases;
|
||||
},
|
||||
};
|
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
name: 'List parent pages',
|
||||
key: 'listParentPages',
|
||||
|
||||
async run($) {
|
||||
const parentPages = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
const payload = {
|
||||
filter: {
|
||||
value: 'page',
|
||||
property: 'object',
|
||||
},
|
||||
};
|
||||
|
||||
do {
|
||||
const response =
|
||||
(await $.http.post) < ResponseData > ('/v1/search', payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
const topLevelPages = response.data.results.filter(
|
||||
(page) => page.parent.workspace
|
||||
);
|
||||
|
||||
for (const pages of topLevelPages) {
|
||||
parentPages.data.push({
|
||||
value: pages.id,
|
||||
name: pages.properties.title.title[0].plain_text,
|
||||
});
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
|
||||
return parentPages;
|
||||
},
|
||||
};
|
@@ -1,70 +0,0 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Page = {
|
||||
id: string;
|
||||
properties: {
|
||||
title: {
|
||||
title: [
|
||||
{
|
||||
plain_text: string;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
parent: {
|
||||
workspace: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
type ResponseData = {
|
||||
results: Page[];
|
||||
next_cursor?: string;
|
||||
};
|
||||
|
||||
type Payload = {
|
||||
filter: {
|
||||
value: 'page';
|
||||
property: 'object';
|
||||
};
|
||||
start_cursor?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'List parent pages',
|
||||
key: 'listParentPages',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const parentPages: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
const payload: Payload = {
|
||||
filter: {
|
||||
value: 'page',
|
||||
property: 'object',
|
||||
},
|
||||
};
|
||||
|
||||
do {
|
||||
const response = await $.http.post<ResponseData>('/v1/search', payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
const topLevelPages = response.data.results.filter(
|
||||
(page) => page.parent.workspace
|
||||
);
|
||||
|
||||
for (const pages of topLevelPages) {
|
||||
parentPages.data.push({
|
||||
value: pages.id as string,
|
||||
name: pages.properties.title.title[0].plain_text as string,
|
||||
});
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
|
||||
return parentPages;
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user