feat: Convert all app files to JS
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { URL, URLSearchParams } from 'node:url';
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
import appConfig from '../../../config/app';
|
||||
import getInstanceUrl from '../common/get-instance-url';
|
||||
import appConfig from '../../../config/app.js';
|
||||
import getInstanceUrl from '../common/get-instance-url.js';
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
export default async function generateAuthUrl($) {
|
||||
const successUrl = new URL(
|
||||
'/app/wordpress/connections/add',
|
||||
appConfig.webAppUrl
|
||||
@@ -16,7 +15,10 @@ export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
success_url: successUrl,
|
||||
});
|
||||
|
||||
const url = new URL(`/wp-admin/authorize-application.php?${searchParams}`, baseUrl).toString();
|
||||
const url = new URL(
|
||||
`/wp-admin/authorize-application.php?${searchParams}`,
|
||||
baseUrl
|
||||
).toString();
|
||||
|
||||
await $.auth.set({
|
||||
url,
|
@@ -1,13 +1,13 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'instanceUrl',
|
||||
label: 'WordPress instance URL',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,7 @@
|
||||
const isStillVerified = async ($) => {
|
||||
await $.http.get('?rest_route=/wp/v2/settings');
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await $.http.get('?rest_route=/wp/v2/settings');
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -0,0 +1,22 @@
|
||||
const verifyCredentials = async ($) => {
|
||||
const instanceUrl = $.auth.data.instanceUrl;
|
||||
const password = $.auth.data.password;
|
||||
const siteUrl = $.auth.data.site_url;
|
||||
const url = $.auth.data.url;
|
||||
const userLogin = $.auth.data.user_login;
|
||||
|
||||
if (!password) {
|
||||
throw new Error('Failed while authorizing!');
|
||||
}
|
||||
|
||||
await $.auth.set({
|
||||
screenName: `${userLogin} @ ${siteUrl}`,
|
||||
instanceUrl,
|
||||
password,
|
||||
siteUrl,
|
||||
url,
|
||||
userLogin,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
@@ -1,24 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const instanceUrl = $.auth.data.instanceUrl as string;
|
||||
const password = $.auth.data.password as string;
|
||||
const siteUrl = $.auth.data.site_url as string;
|
||||
const url = $.auth.data.url as string;
|
||||
const userLogin = $.auth.data.user_login as string;
|
||||
|
||||
if (!password) {
|
||||
throw new Error('Failed while authorizing!');
|
||||
}
|
||||
|
||||
await $.auth.set({
|
||||
screenName: `${userLogin} @ ${siteUrl}`,
|
||||
instanceUrl,
|
||||
password,
|
||||
siteUrl,
|
||||
url,
|
||||
userLogin,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
@@ -0,0 +1,15 @@
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
const userLogin = $.auth.data.userLogin;
|
||||
const password = $.auth.data.password;
|
||||
|
||||
if (userLogin && password) {
|
||||
requestConfig.auth = {
|
||||
username: userLogin,
|
||||
password,
|
||||
};
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
@@ -1,17 +0,0 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const userLogin = $.auth.data.userLogin as string;
|
||||
const password = $.auth.data.password as string;
|
||||
|
||||
if (userLogin && password) {
|
||||
requestConfig.auth = {
|
||||
username: userLogin,
|
||||
password,
|
||||
};
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
@@ -0,0 +1,5 @@
|
||||
const getInstanceUrl = ($) => {
|
||||
return $.auth.data.instanceUrl;
|
||||
};
|
||||
|
||||
export default getInstanceUrl;
|
@@ -1,7 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const getInstanceUrl = ($: IGlobalVariable): string => {
|
||||
return $.auth.data.instanceUrl as string;
|
||||
};
|
||||
|
||||
export default getInstanceUrl;
|
10
packages/backend/src/apps/wordpress/common/set-base-url.js
Normal file
10
packages/backend/src/apps/wordpress/common/set-base-url.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const setBaseUrl = ($, requestConfig) => {
|
||||
const instanceUrl = $.auth.data.instanceUrl;
|
||||
if (instanceUrl) {
|
||||
requestConfig.baseURL = instanceUrl;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default setBaseUrl;
|
@@ -1,12 +0,0 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const setBaseUrl: TBeforeRequest = ($, requestConfig) => {
|
||||
const instanceUrl = $.auth.data.instanceUrl as string;
|
||||
if (instanceUrl) {
|
||||
requestConfig.baseURL = instanceUrl;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default setBaseUrl;
|
@@ -0,0 +1,3 @@
|
||||
import listStatuses from './list-statuses/index.js';
|
||||
|
||||
export default [listStatuses];
|
@@ -1,3 +0,0 @@
|
||||
import listStatuses from './list-statuses';
|
||||
|
||||
export default [listStatuses];
|
@@ -1,23 +1,14 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Status = {
|
||||
slug: string;
|
||||
name: string;
|
||||
};
|
||||
type Statuses = Record<string, Status>;
|
||||
|
||||
export default {
|
||||
name: 'List statuses',
|
||||
key: 'listStatuses',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const statuses: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
async run($) {
|
||||
const statuses = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const { data } = await $.http.get<Statuses>('?rest_route=/wp/v2/statuses');
|
||||
const { data } =
|
||||
(await $.http.get) < Statuses > '?rest_route=/wp/v2/statuses';
|
||||
|
||||
if (!data) return statuses;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import setBaseUrl from './common/set-base-url';
|
||||
import auth from './auth';
|
||||
import triggers from './triggers';
|
||||
import dynamicData from './dynamic-data';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import setBaseUrl from './common/set-base-url.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'WordPress',
|
5
packages/backend/src/apps/wordpress/triggers/index.js
Normal file
5
packages/backend/src/apps/wordpress/triggers/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import newComment from './new-comment/index.js';
|
||||
import newPage from './new-page/index.js';
|
||||
import newPost from './new-post/index.js';
|
||||
|
||||
export default [newComment, newPage, newPost];
|
@@ -1,5 +0,0 @@
|
||||
import newComment from './new-comment';
|
||||
import newPage from './new-page';
|
||||
import newPost from './new-post';
|
||||
|
||||
export default [newComment, newPage, newPost];
|
@@ -1,4 +1,4 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New comment',
|
||||
@@ -8,7 +8,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Status',
|
||||
key: 'status',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: true,
|
||||
options: [
|
@@ -1,4 +1,4 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New page',
|
||||
@@ -8,7 +8,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Status',
|
||||
key: 'status',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: true,
|
||||
source: {
|
@@ -1,4 +1,4 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New post',
|
||||
@@ -8,7 +8,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Status',
|
||||
key: 'status',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: true,
|
||||
source: {
|
||||
@@ -35,10 +35,9 @@ export default defineTrigger({
|
||||
|
||||
let totalPages = 1;
|
||||
do {
|
||||
const {
|
||||
data,
|
||||
headers
|
||||
} = await $.http.get('?rest_route=/wp/v2/posts', { params });
|
||||
const { data, headers } = await $.http.get('?rest_route=/wp/v2/posts', {
|
||||
params,
|
||||
});
|
||||
|
||||
params.page = params.page + 1;
|
||||
totalPages = Number(headers['x-wp-totalpages']);
|
Reference in New Issue
Block a user