feat: Convert all app files to JS

This commit is contained in:
Faruk AYDIN
2024-01-05 17:44:21 +01:00
parent b95478b635
commit 43dba351c3
1030 changed files with 5114 additions and 6436 deletions

View File

@@ -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',

View File

@@ -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,

View File

@@ -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;

View File

@@ -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;

View File

@@ -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(

View File

@@ -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,
});