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

@@ -0,0 +1,18 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Create totals and stats report',
key: 'createTotalsAndStatsReport',
description:
'Create a report with recent, year to date, and all time stats of your activities',
async run($) {
const { data } = await $.http.get(
`/v3/athletes/${$.auth.data.athleteId}/stats`
);
$.setActionItem({
raw: data,
});
},
});

View File

@@ -1,15 +0,0 @@
import defineAction from '../../../../helpers/define-action';
export default defineAction({
name: 'Create totals and stats report',
key: 'createTotalsAndStatsReport',
description: 'Create a report with recent, year to date, and all time stats of your activities',
async run($) {
const { data } = await $.http.get(`/v3/athletes/${$.auth.data.athleteId}/stats`);
$.setActionItem({
raw: data,
});
},
});

View File

@@ -0,0 +1,3 @@
import createTotalsAndStatsReport from './create-totals-and-stats-report/index.js';
export default [createTotalsAndStatsReport];

View File

@@ -1,3 +0,0 @@
import createTotalsAndStatsReport from "./create-totals-and-stats-report";
export default [createTotalsAndStatsReport];

View File

@@ -1,13 +1,12 @@
import { URLSearchParams } from 'node:url';
import { IField, IGlobalVariable } from '@automatisch/types';
export default async function createAuthData($: IGlobalVariable) {
export default async function createAuthData($) {
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 searchParams = new URLSearchParams({
client_id: $.auth.data.clientId as string,
client_id: $.auth.data.clientId,
redirect_uri: redirectUri,
approval_prompt: 'force',
response_type: 'code',

View File

@@ -1,14 +1,14 @@
import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
import refreshToken from './refresh-token';
import generateAuthUrl from './generate-auth-url.js';
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
import refreshToken from './refresh-token.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/strava/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 user = await getCurrentUser($);
return !!user;
};
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 user = await getCurrentUser($);
return !!user;
};
export default isStillVerified;

View File

@@ -0,0 +1,20 @@
const refreshToken = async ($) => {
const params = {
client_id: $.auth.data.clientId,
client_secret: $.auth.data.clientSecret,
grant_type: 'refresh_token',
refresh_token: $.auth.data.refreshToken,
};
const { data } = await $.http.post('/v3/oauth/token', null, { params });
await $.auth.set({
accessToken: data.access_token,
expiresIn: data.expires_in,
expiresAt: data.expires_at,
tokenType: data.token_type,
refreshToken: data.refresh_token,
});
};
export default refreshToken;

View File

@@ -1,26 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
const refreshToken = async ($: IGlobalVariable) => {
const params = {
client_id: $.auth.data.clientId as string,
client_secret: $.auth.data.clientSecret as string,
grant_type: 'refresh_token',
refresh_token: $.auth.data.refreshToken as string,
};
const { data } = await $.http.post(
'/v3/oauth/token',
null,
{ params }
);
await $.auth.set({
accessToken: data.access_token,
expiresIn: data.expires_in,
expiresAt: data.expires_at,
tokenType: data.token_type,
refreshToken: data.refresh_token,
});
};
export default refreshToken;

View File

@@ -0,0 +1,19 @@
const verifyCredentials = async ($) => {
const params = {
client_id: $.auth.data.clientId,
client_secret: $.auth.data.clientSecret,
code: $.auth.data.code,
grant_type: 'authorization_code',
};
const { data } = await $.http.post('/v3/oauth/token', null, { params });
await $.auth.set({
accessToken: data.access_token,
refreshToken: data.refresh_token,
tokenType: data.token_type,
athleteId: data.athlete.id,
screenName: `${data.athlete.firstname} ${data.athlete.lastname}`,
});
};
export default verifyCredentials;

View File

@@ -1,25 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => {
const params = {
client_id: $.auth.data.clientId as string,
client_secret: $.auth.data.clientSecret as string,
code: $.auth.data.code as string,
grant_type: 'authorization_code',
};
const { data } = await $.http.post(
'/v3/oauth/token',
null,
{ params }
);
await $.auth.set({
accessToken: data.access_token,
refreshToken: data.refresh_token,
tokenType: data.token_type,
athleteId: data.athlete.id,
screenName: `${data.athlete.firstname} ${data.athlete.lastname}`,
});
};
export default verifyCredentials;

View File

@@ -1,6 +1,4 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
const addAuthHeader = ($, requestConfig) => {
const { accessToken, tokenType } = $.auth.data;
if (accessToken && tokenType) {

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('/v3/athlete');
const currentUser = response.data;

View File

@@ -1,7 +1,7 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import actions from './actions';
import auth from './auth';
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import actions from './actions/index.js';
import auth from './auth/index.js';
export default defineApp({
name: 'Strava',