feat: Convert all app files to JS
This commit is contained in:
@@ -1,11 +1,4 @@
|
||||
import { IJSONArray, IJSONObject } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
|
||||
type TBody = {
|
||||
parent: IJSONObject;
|
||||
properties: IJSONObject;
|
||||
children: IJSONArray;
|
||||
};
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create database item',
|
||||
@@ -15,7 +8,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Database',
|
||||
key: 'databaseId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
@@ -31,7 +24,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Name',
|
||||
key: 'name',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'This field has a 2000 character limit. Any characters beyond 2000 will not be included.',
|
||||
@@ -40,7 +33,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Content',
|
||||
key: 'content',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'The text to add to the page body. The max length for this field is 2000 characters. Any characters beyond 2000 will not be included.',
|
||||
@@ -49,12 +42,12 @@ export default defineAction({
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const name = $.step.parameters.name as string;
|
||||
const name = $.step.parameters.name;
|
||||
const truncatedName = name.slice(0, 2000);
|
||||
const content = $.step.parameters.content as string;
|
||||
const content = $.step.parameters.content;
|
||||
const truncatedContent = content.slice(0, 2000);
|
||||
|
||||
const body: TBody = {
|
||||
const body = {
|
||||
parent: {
|
||||
database_id: $.step.parameters.databaseId,
|
||||
},
|
@@ -1,11 +1,4 @@
|
||||
import { IJSONArray, IJSONObject } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
|
||||
type TBody = {
|
||||
parent: IJSONObject;
|
||||
properties: IJSONObject;
|
||||
children: IJSONArray;
|
||||
};
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create page',
|
||||
@@ -15,7 +8,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Parent page',
|
||||
key: 'parentPageId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: true,
|
||||
source: {
|
||||
@@ -32,7 +25,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Title',
|
||||
key: 'title',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'This field has a 2000 character limit. Any characters beyond 2000 will not be included.',
|
||||
@@ -41,7 +34,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Content',
|
||||
key: 'content',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'The text to add to the page body. The max length for this field is 2000 characters. Any characters beyond 2000 will not be included.',
|
||||
@@ -50,13 +43,13 @@ export default defineAction({
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const parentPageId = $.step.parameters.parentPageId as string;
|
||||
const title = $.step.parameters.title as string;
|
||||
const parentPageId = $.step.parameters.parentPageId;
|
||||
const title = $.step.parameters.title;
|
||||
const truncatedTitle = title.slice(0, 2000);
|
||||
const content = $.step.parameters.content as string;
|
||||
const content = $.step.parameters.content;
|
||||
const truncatedContent = content.slice(0, 2000);
|
||||
|
||||
const body: TBody = {
|
||||
const body = {
|
||||
parent: {
|
||||
page_id: parentPageId,
|
||||
},
|
@@ -1,10 +1,4 @@
|
||||
import { IJSONArray, IJSONObject } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
|
||||
type TBody = {
|
||||
filter: IJSONObject;
|
||||
sorts: IJSONArray;
|
||||
};
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Find database item',
|
||||
@@ -14,7 +8,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Database',
|
||||
key: 'databaseId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
@@ -30,7 +24,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Name',
|
||||
key: 'name',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'This field has a 2000 character limit. Any characters beyond 2000 will not be included.',
|
||||
@@ -39,11 +33,11 @@ export default defineAction({
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const databaseId = $.step.parameters.databaseId as string;
|
||||
const name = $.step.parameters.name as string;
|
||||
const databaseId = $.step.parameters.databaseId;
|
||||
const name = $.step.parameters.name;
|
||||
const truncatedName = name.slice(0, 2000);
|
||||
|
||||
const body: TBody = {
|
||||
const body = {
|
||||
filter: {
|
||||
property: 'Name',
|
||||
rich_text: {
|
5
packages/backend/src/apps/notion/actions/index.js
Normal file
5
packages/backend/src/apps/notion/actions/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import createDatabaseItem from './create-database-item/index.js';
|
||||
import createPage from './create-page/index.js';
|
||||
import findDatabaseItem from './find-database-item/index.js';
|
||||
|
||||
export default [createDatabaseItem, createPage, findDatabaseItem];
|
@@ -1,5 +0,0 @@
|
||||
import createDatabaseItem from './create-database-item';
|
||||
import createPage from './create-page';
|
||||
import findDatabaseItem from './find-database-item';
|
||||
|
||||
export default [createDatabaseItem, createPage, findDatabaseItem];
|
23
packages/backend/src/apps/notion/auth/generate-auth-url.js
Normal file
23
packages/backend/src/apps/notion/auth/generate-auth-url.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { URL, URLSearchParams } from 'url';
|
||||
|
||||
export default async function generateAuthUrl($) {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId,
|
||||
redirect_uri: redirectUri,
|
||||
response_type: 'code',
|
||||
owner: 'user',
|
||||
});
|
||||
|
||||
const url = new URL(
|
||||
`/v1/oauth/authorize?${searchParams}`,
|
||||
$.app.apiBaseUrl
|
||||
).toString();
|
||||
|
||||
await $.auth.set({
|
||||
url,
|
||||
});
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import { URL, URLSearchParams } from 'url';
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value as string;
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId as string,
|
||||
redirect_uri: redirectUri,
|
||||
response_type: 'code',
|
||||
owner: 'user',
|
||||
});
|
||||
|
||||
const url = new URL(`/v1/oauth/authorize?${searchParams}`, $.app.apiBaseUrl).toString();
|
||||
|
||||
await $.auth.set({
|
||||
url,
|
||||
});
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'oAuthRedirectUrl',
|
||||
label: 'OAuth Redirect URL',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: true,
|
||||
value: '{WEB_APP_URL}/app/notion/connections/add',
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
{
|
||||
key: 'clientId',
|
||||
label: 'Client ID',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -32,7 +32,7 @@ export default {
|
||||
{
|
||||
key: 'clientSecret',
|
||||
label: 'Client Secret',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,8 @@
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
const user = await getCurrentUser($);
|
||||
return !!user.id;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
const user = await getCurrentUser($);
|
||||
return !!user.id;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,11 +1,10 @@
|
||||
import { IGlobalVariable, IField } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const verifyCredentials = async ($) => {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value as string;
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
const response = await $.http.post(
|
||||
`${$.app.apiBaseUrl}/v1/oauth/token`,
|
||||
{
|
||||
@@ -20,8 +19,8 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
).toString('base64')}`,
|
||||
},
|
||||
additionalProperties: {
|
||||
skipAddingAuthHeader: true
|
||||
}
|
||||
skipAddingAuthHeader: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
if (requestConfig.additionalProperties?.skipAddingAuthHeader) return requestConfig;
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
if (requestConfig.additionalProperties?.skipAddingAuthHeader)
|
||||
return requestConfig;
|
||||
|
||||
if ($.auth.data?.accessToken) {
|
||||
const authorizationHeader = `Bearer ${$.auth.data.accessToken}`;
|
@@ -1,6 +1,4 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addNotionVersionHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addNotionVersionHeader = ($, requestConfig) => {
|
||||
requestConfig.headers['Notion-Version'] = '2022-06-28';
|
||||
|
||||
return requestConfig;
|
@@ -0,0 +1,9 @@
|
||||
const getCurrentUser = async ($) => {
|
||||
const userId = $.auth.data.owner.user.id;
|
||||
const response = await $.http.get(`/v1/users/${userId}`);
|
||||
|
||||
const currentUser = response.data;
|
||||
return currentUser;
|
||||
};
|
||||
|
||||
export default getCurrentUser;
|
@@ -1,17 +0,0 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Owner = {
|
||||
user: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||
const userId = ($.auth.data.owner as Owner).user.id;
|
||||
const response = await $.http.get(`/v1/users/${userId}`);
|
||||
|
||||
const currentUser = response.data;
|
||||
return currentUser;
|
||||
};
|
||||
|
||||
export default getCurrentUser;
|
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;
|
||||
},
|
||||
};
|
@@ -1,10 +1,10 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import addNotionVersionHeader from './common/add-notion-version-header';
|
||||
import auth from './auth';
|
||||
import triggers from './triggers';
|
||||
import actions from './actions';
|
||||
import dynamicData from './dynamic-data';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import addNotionVersionHeader from './common/add-notion-version-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import actions from './actions/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Notion',
|
4
packages/backend/src/apps/notion/triggers/index.js
Normal file
4
packages/backend/src/apps/notion/triggers/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import newDatabaseItems from './new-database-items/index.js';
|
||||
import updatedDatabaseItems from './updated-database-items/index.js';
|
||||
|
||||
export default [newDatabaseItems, updatedDatabaseItems];
|
@@ -1,4 +0,0 @@
|
||||
import newDatabaseItems from './new-database-items';
|
||||
import updatedDatabaseItems from './updated-database-items';
|
||||
|
||||
export default [newDatabaseItems, updatedDatabaseItems];
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newDatabaseItems from './new-database-items';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newDatabaseItems from './new-database-items.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New database items',
|
||||
@@ -10,7 +10,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Database',
|
||||
key: 'databaseId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: false,
|
||||
source: {
|
@@ -0,0 +1,29 @@
|
||||
const newDatabaseItems = async ($) => {
|
||||
const payload = {
|
||||
sorts: [
|
||||
{
|
||||
timestamp: 'created_time',
|
||||
direction: 'descending',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const databaseId = $.step.parameters.databaseId;
|
||||
const path = `/v1/databases/${databaseId}/query`;
|
||||
do {
|
||||
const response = await $.http.post(path, payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
for (const databaseItem of response.data.results) {
|
||||
$.pushTriggerItem({
|
||||
raw: databaseItem,
|
||||
meta: {
|
||||
internalId: databaseItem.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
};
|
||||
|
||||
export default newDatabaseItems;
|
@@ -1,50 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
type DatabaseItem = {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type ResponseData = {
|
||||
results: DatabaseItem[];
|
||||
next_cursor?: string;
|
||||
}
|
||||
|
||||
type Payload = {
|
||||
sorts: [
|
||||
{
|
||||
timestamp: 'created_time' | 'last_edited_time';
|
||||
direction: 'ascending' | 'descending';
|
||||
}
|
||||
];
|
||||
start_cursor?: string;
|
||||
};
|
||||
|
||||
const newDatabaseItems = async ($: IGlobalVariable) => {
|
||||
const payload: Payload = {
|
||||
sorts: [
|
||||
{
|
||||
timestamp: 'created_time',
|
||||
direction: 'descending'
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
const databaseId = $.step.parameters.databaseId as string;
|
||||
const path = `/v1/databases/${databaseId}/query`;
|
||||
do {
|
||||
const response = await $.http.post<ResponseData>(path, payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
for (const databaseItem of response.data.results) {
|
||||
$.pushTriggerItem({
|
||||
raw: databaseItem,
|
||||
meta: {
|
||||
internalId: databaseItem.id,
|
||||
}
|
||||
})
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
};
|
||||
|
||||
export default newDatabaseItems;
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import updatedDatabaseItems from './updated-database-items';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import updatedDatabaseItems from './updated-database-items.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Updated database items',
|
||||
@@ -11,7 +11,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Database',
|
||||
key: 'databaseId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: false,
|
||||
source: {
|
@@ -0,0 +1,29 @@
|
||||
const updatedDatabaseItems = async ($) => {
|
||||
const payload = {
|
||||
sorts: [
|
||||
{
|
||||
timestamp: 'last_edited_time',
|
||||
direction: 'descending',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const databaseId = $.step.parameters.databaseId;
|
||||
const path = `/v1/databases/${databaseId}/query`;
|
||||
do {
|
||||
const response = await $.http.post(path, payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
for (const databaseItem of response.data.results) {
|
||||
$.pushTriggerItem({
|
||||
raw: databaseItem,
|
||||
meta: {
|
||||
internalId: `${databaseItem.id}-${databaseItem.last_edited_time}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
};
|
||||
|
||||
export default updatedDatabaseItems;
|
@@ -1,51 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
type DatabaseItem = {
|
||||
id: string;
|
||||
last_edited_time: string;
|
||||
};
|
||||
|
||||
type ResponseData = {
|
||||
results: DatabaseItem[];
|
||||
next_cursor?: string;
|
||||
};
|
||||
|
||||
type Payload = {
|
||||
sorts: [
|
||||
{
|
||||
timestamp: 'created_time' | 'last_edited_time';
|
||||
direction: 'ascending' | 'descending';
|
||||
}
|
||||
];
|
||||
start_cursor?: string;
|
||||
};
|
||||
|
||||
const updatedDatabaseItems = async ($: IGlobalVariable) => {
|
||||
const payload: Payload = {
|
||||
sorts: [
|
||||
{
|
||||
timestamp: 'last_edited_time',
|
||||
direction: 'descending',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const databaseId = $.step.parameters.databaseId as string;
|
||||
const path = `/v1/databases/${databaseId}/query`;
|
||||
do {
|
||||
const response = await $.http.post<ResponseData>(path, payload);
|
||||
|
||||
payload.start_cursor = response.data.next_cursor;
|
||||
|
||||
for (const databaseItem of response.data.results) {
|
||||
$.pushTriggerItem({
|
||||
raw: databaseItem,
|
||||
meta: {
|
||||
internalId: `${databaseItem.id}-${databaseItem.last_edited_time}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
} while (payload.start_cursor);
|
||||
};
|
||||
|
||||
export default updatedDatabaseItems;
|
Reference in New Issue
Block a user