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';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
export default defineAction({
|
||||
@@ -9,7 +9,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Title',
|
||||
key: 'title',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description:
|
||||
'Heading for the recent post. Limited to 300 characters or less.',
|
||||
@@ -18,7 +18,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Subreddit',
|
||||
key: 'subreddit',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The subreddit for posting. Note: Exclude /r/.',
|
||||
variables: true,
|
||||
@@ -26,7 +26,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Url',
|
||||
key: 'url',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
@@ -39,9 +39,9 @@ export default defineAction({
|
||||
const params = new URLSearchParams({
|
||||
kind: 'link',
|
||||
api_type: 'json',
|
||||
title: title as string,
|
||||
sr: subreddit as string,
|
||||
url: url as string,
|
||||
title: title,
|
||||
sr: subreddit,
|
||||
url: url,
|
||||
});
|
||||
|
||||
const { data } = await $.http.post('/api/submit', params.toString());
|
3
packages/backend/src/apps/reddit/actions/index.js
Normal file
3
packages/backend/src/apps/reddit/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import createLinkPost from './create-link-post/index.js';
|
||||
|
||||
export default [createLinkPost];
|
@@ -1,3 +0,0 @@
|
||||
import createLinkPost from './create-link-post';
|
||||
|
||||
export default [createLinkPost];
|
@@ -1,15 +1,14 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import authScope from '../common/auth-scope';
|
||||
import authScope from '../common/auth-scope.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 redirectUri = oauthRedirectUrlField.value as string;
|
||||
const state = Math.random().toString() as string;
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
const state = Math.random().toString();
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId as string,
|
||||
client_id: $.auth.data.clientId,
|
||||
response_type: 'code',
|
||||
redirect_uri: redirectUri,
|
||||
duration: 'permanent',
|
@@ -1,14 +1,14 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import refreshToken from './refresh-token';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import refreshToken from './refresh-token.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/reddit/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,
|
||||
@@ -31,7 +31,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 currentUser = await getCurrentUser($);
|
||||
return !!currentUser.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 currentUser = await getCurrentUser($);
|
||||
return !!currentUser.id;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,7 +1,6 @@
|
||||
import { URLSearchParams } from 'node:url';
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const refreshToken = async ($: IGlobalVariable) => {
|
||||
const refreshToken = async ($) => {
|
||||
const headers = {
|
||||
Authorization: `Basic ${Buffer.from(
|
||||
$.auth.data.clientId + ':' + $.auth.data.clientSecret
|
||||
@@ -9,7 +8,7 @@ const refreshToken = async ($: IGlobalVariable) => {
|
||||
};
|
||||
const params = new URLSearchParams({
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: $.auth.data.refreshToken as string,
|
||||
refresh_token: $.auth.data.refreshToken,
|
||||
});
|
||||
|
||||
const { data } = await $.http.post(
|
@@ -1,15 +1,14 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const verifyCredentials = async ($) => {
|
||||
if ($.auth.data.originalState !== $.auth.data.state) {
|
||||
throw new Error(`The 'state' parameter does not match.`);
|
||||
}
|
||||
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 headers = {
|
||||
Authorization: `Basic ${Buffer.from(
|
||||
$.auth.data.clientId + ':' + $.auth.data.clientSecret
|
||||
@@ -17,7 +16,7 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
};
|
||||
const params = new URLSearchParams({
|
||||
grant_type: 'authorization_code',
|
||||
code: $.auth.data.code as string,
|
||||
code: $.auth.data.code,
|
||||
redirect_uri: redirectUri,
|
||||
});
|
||||
|
@@ -1,8 +1,7 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
import appConfig from '../../../config/app';
|
||||
import appConfig from '../../../config/app.js';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const screenName = $.auth.data?.screenName as string;
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
const screenName = $.auth.data?.screenName;
|
||||
if ($.auth.data?.accessToken) {
|
||||
requestConfig.headers.Authorization = `${$.auth.data.tokenType} ${$.auth.data.accessToken}`;
|
||||
}
|
3
packages/backend/src/apps/reddit/common/auth-scope.js
Normal file
3
packages/backend/src/apps/reddit/common/auth-scope.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const authScope = ['identity', 'read', 'account', 'submit'];
|
||||
|
||||
export default authScope;
|
@@ -1,3 +0,0 @@
|
||||
const authScope: string[] = ['identity', 'read', 'account', 'submit'];
|
||||
|
||||
export default authScope;
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable) => {
|
||||
const getCurrentUser = async ($) => {
|
||||
const { data: currentUser } = await $.http.get('/api/v1/me');
|
||||
return currentUser;
|
||||
};
|
@@ -1,8 +1,8 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import triggers from './triggers';
|
||||
import actions from './actions';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Reddit',
|
3
packages/backend/src/apps/reddit/triggers/index.js
Normal file
3
packages/backend/src/apps/reddit/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import newPostsMatchingSearch from './new-posts-matching-search/index.js';
|
||||
|
||||
export default [newPostsMatchingSearch];
|
@@ -1,3 +0,0 @@
|
||||
import newPostsMatchingSearch from './new-posts-matching-search';
|
||||
|
||||
export default [newPostsMatchingSearch];
|
@@ -1,4 +1,4 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New posts matching search',
|
||||
@@ -9,7 +9,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Search Query',
|
||||
key: 'searchQuery',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description:
|
||||
'The term or expression to look for, restricted to 512 characters. If your query contains periods (e.g., automatisch.io), ensure it is enclosed in quotes ("automatisch.io").',
|
||||
@@ -24,7 +24,7 @@ export default defineTrigger({
|
||||
type: 'link',
|
||||
sort: 'new',
|
||||
limit: 100,
|
||||
after: undefined as unknown as string,
|
||||
after: undefined,
|
||||
};
|
||||
|
||||
do {
|
Reference in New Issue
Block a user