feat: Convert all app files to JS
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create a scheduled event',
|
||||
@@ -8,13 +8,13 @@ export default defineAction({
|
||||
{
|
||||
label: 'Type',
|
||||
key: 'entityType',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Stage channel', value: 1 },
|
||||
{ label: 'Voice channel', value: 2 },
|
||||
{ label: 'External', value: 3 }
|
||||
{ label: 'External', value: 3 },
|
||||
],
|
||||
additionalFields: {
|
||||
type: 'query',
|
||||
@@ -34,61 +34,47 @@ export default defineAction({
|
||||
{
|
||||
label: 'Name',
|
||||
key: 'name',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Description',
|
||||
key: 'description',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Image',
|
||||
key: 'image',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: 'Image as DataURI scheme [data:image/<jpeg/png/gif>;base64,BASE64_ENCODED_<JPEG/PNG/GIF>_IMAGE_DATA]',
|
||||
description:
|
||||
'Image as DataURI scheme [data:image/<jpeg/png/gif>;base64,BASE64_ENCODED_<JPEG/PNG/GIF>_IMAGE_DATA]',
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
type entity_metadata = {
|
||||
location: string
|
||||
}
|
||||
|
||||
type guild_event = {
|
||||
channel_id: number,
|
||||
name: string,
|
||||
privacy_level: number,
|
||||
scheduled_start_time: string,
|
||||
scheduled_end_time?: string,
|
||||
description?: string,
|
||||
entity_type?: number,
|
||||
entity_metadata?: entity_metadata,
|
||||
image?: string, //data:image/jpeg;base64,BASE64_ENCODED_JPEG_IMAGE_DATA
|
||||
}
|
||||
|
||||
|
||||
const data: guild_event = {
|
||||
channel_id: $.step.parameters.channel_id as number,
|
||||
name: $.step.parameters.name as string,
|
||||
const data = {
|
||||
channel_id: $.step.parameters.channel_id,
|
||||
name: $.step.parameters.name,
|
||||
privacy_level: 2,
|
||||
scheduled_start_time: $.step.parameters.scheduledStartTime as string,
|
||||
scheduled_end_time: $.step.parameters.scheduledEndTime as string,
|
||||
description: $.step.parameters.description as string,
|
||||
entity_type: $.step.parameters.entityType as number,
|
||||
image: $.step.parameters.image as string,
|
||||
scheduled_start_time: $.step.parameters.scheduledStartTime,
|
||||
scheduled_end_time: $.step.parameters.scheduledEndTime,
|
||||
description: $.step.parameters.description,
|
||||
entity_type: $.step.parameters.entityType,
|
||||
image: $.step.parameters.image,
|
||||
};
|
||||
|
||||
const isExternal = $.step.parameters.entityType === 3;
|
||||
|
||||
if (isExternal) {
|
||||
data.entity_metadata = {
|
||||
location: $.step.parameters.location as string,
|
||||
location: $.step.parameters.location,
|
||||
};
|
||||
|
||||
data.channel_id = null;
|
||||
}
|
||||
|
4
packages/backend/src/apps/discord/actions/index.js
Normal file
4
packages/backend/src/apps/discord/actions/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import sendMessageToChannel from './send-message-to-channel/index.js';
|
||||
import createScheduledEvent from './create-scheduled-event/index.js';
|
||||
|
||||
export default [sendMessageToChannel, createScheduledEvent];
|
@@ -1,4 +0,0 @@
|
||||
import sendMessageToChannel from './send-message-to-channel';
|
||||
import createScheduledEvent from './create-scheduled-event';
|
||||
|
||||
export default [sendMessageToChannel, createScheduledEvent];
|
@@ -1,4 +1,4 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Send a message to channel',
|
||||
@@ -8,7 +8,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Channel',
|
||||
key: 'channel',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: 'Pick a channel to send the message to.',
|
||||
variables: true,
|
||||
@@ -26,7 +26,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Message text',
|
||||
key: 'message',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The content of your new message.',
|
||||
variables: true,
|
||||
@@ -35,8 +35,9 @@ export default defineAction({
|
||||
|
||||
async run($) {
|
||||
const data = {
|
||||
content: $.step.parameters.message as string,
|
||||
content: $.step.parameters.message,
|
||||
};
|
||||
|
||||
const response = await $.http?.post(
|
||||
`/channels/${$.step.parameters.channel}/messages`,
|
||||
data
|
@@ -1,15 +1,15 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import scopes from '../common/scopes';
|
||||
import scopes from '../common/scopes.js';
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
export default async function generateAuthUrl($) {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const callbackUrl = oauthRedirectUrlField.value as string;
|
||||
|
||||
const callbackUrl = oauthRedirectUrlField.value;
|
||||
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.consumerKey as string,
|
||||
client_id: $.auth.data.consumerKey,
|
||||
redirect_uri: callbackUrl,
|
||||
response_type: 'code',
|
||||
permissions: '2146958591',
|
@@ -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/discord/connections/add',
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
{
|
||||
key: 'consumerKey',
|
||||
label: 'Consumer Key',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -32,7 +32,7 @@ export default {
|
||||
{
|
||||
key: 'consumerSecret',
|
||||
label: 'Consumer Secret',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -44,7 +44,7 @@ export default {
|
||||
{
|
||||
key: 'botToken',
|
||||
label: 'Bot token',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,9 @@
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
await getCurrentUser($);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,10 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await getCurrentUser($);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,22 +1,24 @@
|
||||
import { IGlobalVariable, IField } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import scopes from '../common/scopes';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
import scopes from '../common/scopes.js';
|
||||
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 callbackUrl = oauthRedirectUrlField.value as string;
|
||||
|
||||
const callbackUrl = oauthRedirectUrlField.value;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
client_id: $.auth.data.consumerKey as string,
|
||||
client_id: $.auth.data.consumerKey,
|
||||
redirect_uri: callbackUrl,
|
||||
response_type: 'code',
|
||||
scope: scopes.join(' '),
|
||||
client_secret: $.auth.data.consumerSecret as string,
|
||||
code: $.auth.data.code as string,
|
||||
client_secret: $.auth.data.consumerSecret,
|
||||
code: $.auth.data.code,
|
||||
grant_type: 'authorization_code',
|
||||
});
|
||||
|
||||
const { data: verifiedCredentials } = await $.http.post(
|
||||
'/oauth2/token',
|
||||
params.toString()
|
@@ -1,6 +1,4 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
const { tokenType, botToken } = $.auth.data;
|
||||
if (tokenType && botToken) {
|
||||
requestConfig.headers.Authorization = `Bot ${botToken}`;
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||
const getCurrentUser = async ($) => {
|
||||
const response = await $.http.get('/users/@me');
|
||||
const currentUser = response.data;
|
||||
|
4
packages/backend/src/apps/discord/dynamic-data/index.js
Normal file
4
packages/backend/src/apps/discord/dynamic-data/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import listChannels from './list-channels/index.js';
|
||||
import listVoiceChannels from './list-voice-channels/index.js';
|
||||
|
||||
export default [listChannels, listVoiceChannels];
|
@@ -1,4 +0,0 @@
|
||||
import listChannels from './list-channels';
|
||||
import listVoiceChannels from './list-voice-channels';
|
||||
|
||||
export default [listChannels, listVoiceChannels];
|
@@ -1,14 +1,9 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List channels',
|
||||
key: 'listChannels',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const channels: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
async run($) {
|
||||
const channels = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
@@ -18,11 +13,11 @@ export default {
|
||||
);
|
||||
|
||||
channels.data = response.data
|
||||
.filter((channel: IJSONObject) => {
|
||||
.filter((channel) => {
|
||||
// filter in text channels and announcement channels only
|
||||
return channel.type === 0 || channel.type === 5;
|
||||
})
|
||||
.map((channel: IJSONObject) => {
|
||||
.map((channel) => {
|
||||
return {
|
||||
value: channel.id,
|
||||
name: channel.name,
|
@@ -1,14 +1,9 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List voice channels',
|
||||
key: 'listVoiceChannels',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const channels: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
async run($) {
|
||||
const channels = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
@@ -18,11 +13,11 @@ export default {
|
||||
);
|
||||
|
||||
channels.data = response.data
|
||||
.filter((channel: IJSONObject) => {
|
||||
.filter((channel) => {
|
||||
// filter in voice and stage channels only
|
||||
return channel.type === 2 || channel.type === 13;
|
||||
})
|
||||
.map((channel: IJSONObject) => {
|
||||
.map((channel) => {
|
||||
return {
|
||||
value: channel.id,
|
||||
name: channel.name,
|
@@ -1,3 +1,3 @@
|
||||
import listExternalScheduledEventFields from './list-external-scheduled-event-fields';
|
||||
import listExternalScheduledEventFields from './list-external-scheduled-event-fields/index.js';
|
||||
|
||||
export default [listExternalScheduledEventFields];
|
@@ -1,9 +1,8 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
export default {
|
||||
name: 'List external scheduled event fields',
|
||||
key: 'listExternalScheduledEventFields',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const isExternal = $.step.parameters.entityType === 3;
|
||||
|
||||
if (isExternal) {
|
||||
@@ -11,15 +10,16 @@ export default {
|
||||
{
|
||||
label: 'Location',
|
||||
key: 'location',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
||||
description:
|
||||
'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Start-Time',
|
||||
key: 'scheduledStartTime',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The time the event will start [ISO8601]',
|
||||
variables: true,
|
||||
@@ -27,9 +27,10 @@ export default {
|
||||
{
|
||||
label: 'End-Time',
|
||||
key: 'scheduledEndTime',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
||||
description:
|
||||
'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
||||
variables: true,
|
||||
},
|
||||
];
|
||||
@@ -39,9 +40,10 @@ export default {
|
||||
{
|
||||
label: 'Channel',
|
||||
key: 'channel_id',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: 'Pick a voice or stage channel to link the event to. This will be omitted if type is EXTERNAL',
|
||||
description:
|
||||
'Pick a voice or stage channel to link the event to. This will be omitted if type is EXTERNAL',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
@@ -57,15 +59,16 @@ export default {
|
||||
{
|
||||
label: 'Location',
|
||||
key: 'location',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: 'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
||||
description:
|
||||
'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Start-Time',
|
||||
key: 'scheduledStartTime',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The time the event will start [ISO8601]',
|
||||
variables: true,
|
||||
@@ -73,9 +76,10 @@ export default {
|
||||
{
|
||||
label: 'End-Time',
|
||||
key: 'scheduledEndTime',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: 'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
||||
description:
|
||||
'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
||||
variables: true,
|
||||
},
|
||||
];
|
@@ -1,10 +1,10 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import dynamicData from './dynamic-data';
|
||||
import actions from './actions';
|
||||
import triggers from './triggers';
|
||||
import dynamicFields from './dynamic-fields';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
import actions from './actions/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicFields from './dynamic-fields/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Discord',
|
Reference in New Issue
Block a user