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,20 +1,12 @@
import { Token } from 'oauth-1.0a';
import { URLSearchParams } from 'node:url';
import { IJSONObject, TBeforeRequest } from '@automatisch/types';
import oauthClient from './oauth-client';
import oauthClient from './oauth-client.js';
type RequestDataType = {
url: string;
method: string;
data?: IJSONObject;
};
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
const addAuthHeader = ($, requestConfig) => {
const { baseURL, url, method, data, params } = requestConfig;
const token: Token = {
key: $.auth.data?.accessToken as string,
secret: $.auth.data?.accessSecret as string,
const token = {
key: $.auth.data?.accessToken,
secret: $.auth.data?.accessSecret,
};
const searchParams = new URLSearchParams(params);
@@ -26,7 +18,7 @@ const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
fullUrl = `${fullUrl}?${stringifiedParams}`;
}
const requestData: RequestDataType = {
const requestData = {
url: fullUrl,
method,
};

View File

@@ -1,6 +1,4 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
const getCurrentUser = async ($) => {
const response = await $.http.get('/2/users/me');
const currentUser = response.data.data;

View File

@@ -1,11 +1,9 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
const getUserByUsername = async ($: IGlobalVariable, username: string) => {
const getUserByUsername = async ($, username) => {
const response = await $.http.get(`/2/users/by/username/${username}`);
if (response.data.errors) {
const errorMessages = response.data.errors
.map((error: IJSONObject) => error.detail)
.map((error) => error.detail)
.join(' ');
throw new Error(`Error occured while fetching user data: ${errorMessages}`);

View File

@@ -1,19 +1,12 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
import { URLSearchParams } from 'url';
import { omitBy, isEmpty } from 'lodash';
import omitBy from 'lodash/omitBy.js';
import isEmpty from 'lodash/isEmpty.js';
type GetUserFollowersOptions = {
userId: string;
};
const getUserFollowers = async (
$: IGlobalVariable,
options: GetUserFollowersOptions
) => {
const getUserFollowers = async ($, options) => {
let response;
do {
const params: IJSONObject = {
const params = {
pagination_token: response?.data?.meta?.next_token,
};
@@ -33,7 +26,7 @@ const getUserFollowers = async (
for (const follower of response.data.data) {
$.pushTriggerItem({
raw: follower,
meta: { internalId: follower.id as string },
meta: { internalId: follower.id },
});
}
}

View File

@@ -1,21 +1,16 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
import { URLSearchParams } from 'url';
import omitBy from 'lodash/omitBy';
import isEmpty from 'lodash/isEmpty';
import getCurrentUser from './get-current-user';
import getUserByUsername from './get-user-by-username';
import omitBy from 'lodash/omitBy.js';
import isEmpty from 'lodash/isEmpty.js';
import getCurrentUser from './get-current-user.js';
import getUserByUsername from './get-user-by-username.js';
type IGetUserTweetsOptions = {
currentUser: boolean;
};
const fetchTweets = async ($: IGlobalVariable, username: string) => {
const fetchTweets = async ($, username) => {
const user = await getUserByUsername($, username);
let response;
do {
const params: IJSONObject = {
const params = {
since_id: $.flow.lastInternalId,
pagination_token: response?.data?.meta?.next_token,
};
@@ -29,11 +24,11 @@ const fetchTweets = async ($: IGlobalVariable, username: string) => {
response = await $.http.get(requestPath);
if (response.data.meta.result_count > 0) {
response.data.data.forEach((tweet: IJSONObject) => {
response.data.data.forEach((tweet) => {
const dataItem = {
raw: tweet,
meta: {
internalId: tweet.id as string,
internalId: tweet.id,
},
};
@@ -45,17 +40,14 @@ const fetchTweets = async ($: IGlobalVariable, username: string) => {
return $.triggerOutput;
};
const getUserTweets = async (
$: IGlobalVariable,
options: IGetUserTweetsOptions
) => {
let username: string;
const getUserTweets = async ($, options) => {
let username;
if (options.currentUser) {
const currentUser = await getCurrentUser($);
username = currentUser.username as string;
username = currentUser.username;
} else {
username = $.step.parameters.username as string;
username = $.step.parameters.username;
}
await fetchTweets($, username);

View File

@@ -1,11 +1,10 @@
import { IGlobalVariable } from '@automatisch/types';
import crypto from 'crypto';
import OAuth from 'oauth-1.0a';
const oauthClient = ($: IGlobalVariable) => {
const oauthClient = ($) => {
const consumerData = {
key: $.auth.data.consumerKey as string,
secret: $.auth.data.consumerSecret as string,
key: $.auth.data.consumerKey,
secret: $.auth.data.consumerSecret,
};
return new OAuth({