Merge pull request #1044 from automatisch/strava
feat(strava): add action to create totals and stats report
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
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,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
3
packages/backend/src/apps/strava/actions/index.ts
Normal file
3
packages/backend/src/apps/strava/actions/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import createTotalsAndStatsReport from "./create-totals-and-stats-report";
|
||||||
|
|
||||||
|
export default [createTotalsAndStatsReport];
|
6
packages/backend/src/apps/strava/assets/favicon.svg
Normal file
6
packages/backend/src/apps/strava/assets/favicon.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
aria-label="Strava" role="img"
|
||||||
|
viewBox="0 0 512 512"><rect
|
||||||
|
width="512" height="512"
|
||||||
|
rx="15%"
|
||||||
|
fill="#fc4c01"/><path fill="#fff" d="M120 288L232 56l112 232h-72l-40-96-40 96z"/><path fill="#fda580" d="M280 288l32 72 32-72h48l-80 168-80-168z"/></svg>
|
After Width: | Height: | Size: 286 B |
20
packages/backend/src/apps/strava/auth/generate-auth-url.ts
Normal file
20
packages/backend/src/apps/strava/auth/generate-auth-url.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { URLSearchParams } from 'node:url';
|
||||||
|
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default async function createAuthData($: IGlobalVariable) {
|
||||||
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
|
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||||
|
);
|
||||||
|
const redirectUri = oauthRedirectUrlField.value as string;
|
||||||
|
const searchParams = new URLSearchParams({
|
||||||
|
client_id: $.auth.data.clientId as string,
|
||||||
|
redirect_uri: redirectUri,
|
||||||
|
approval_prompt: 'force',
|
||||||
|
response_type: 'code',
|
||||||
|
scope: 'read_all,profile:read_all,activity:read_all,activity:write',
|
||||||
|
});
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
url: `${$.app.baseUrl}/oauth/authorize?${searchParams}`,
|
||||||
|
});
|
||||||
|
}
|
48
packages/backend/src/apps/strava/auth/index.ts
Normal file
48
packages/backend/src/apps/strava/auth/index.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import generateAuthUrl from './generate-auth-url';
|
||||||
|
import verifyCredentials from './verify-credentials';
|
||||||
|
import isStillVerified from './is-still-verified';
|
||||||
|
import refreshToken from './refresh-token';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: 'oAuthRedirectUrl',
|
||||||
|
label: 'OAuth Redirect URL',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: true,
|
||||||
|
readOnly: true,
|
||||||
|
value: '{WEB_APP_URL}/app/strava/connections/add',
|
||||||
|
placeholder: null,
|
||||||
|
description:
|
||||||
|
'When asked to input an OAuth callback or redirect URL in Strava OAuth, enter the URL above.',
|
||||||
|
clickToCopy: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'clientId',
|
||||||
|
label: 'Client ID',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description: null,
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'clientSecret',
|
||||||
|
label: 'Client Secret',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description: null,
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
generateAuthUrl,
|
||||||
|
verifyCredentials,
|
||||||
|
isStillVerified,
|
||||||
|
refreshToken,
|
||||||
|
};
|
@@ -0,0 +1,9 @@
|
|||||||
|
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;
|
26
packages/backend/src/apps/strava/auth/refresh-token.ts
Normal file
26
packages/backend/src/apps/strava/auth/refresh-token.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
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;
|
25
packages/backend/src/apps/strava/auth/verify-credentials.ts
Normal file
25
packages/backend/src/apps/strava/auth/verify-credentials.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
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;
|
13
packages/backend/src/apps/strava/common/add-auth-header.ts
Normal file
13
packages/backend/src/apps/strava/common/add-auth-header.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { TBeforeRequest } from '@automatisch/types';
|
||||||
|
|
||||||
|
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||||
|
const { accessToken, tokenType } = $.auth.data;
|
||||||
|
|
||||||
|
if (accessToken && tokenType) {
|
||||||
|
requestConfig.headers.Authorization = `${tokenType} ${accessToken}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default addAuthHeader;
|
10
packages/backend/src/apps/strava/common/get-current-user.ts
Normal file
10
packages/backend/src/apps/strava/common/get-current-user.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||||
|
const response = await $.http.get('/v3/athlete');
|
||||||
|
const currentUser = response.data;
|
||||||
|
|
||||||
|
return currentUser;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getCurrentUser;
|
0
packages/backend/src/apps/strava/index.d.ts
vendored
Normal file
0
packages/backend/src/apps/strava/index.d.ts
vendored
Normal file
18
packages/backend/src/apps/strava/index.ts
Normal file
18
packages/backend/src/apps/strava/index.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import defineApp from '../../helpers/define-app';
|
||||||
|
import addAuthHeader from './common/add-auth-header';
|
||||||
|
import actions from './actions';
|
||||||
|
import auth from './auth';
|
||||||
|
|
||||||
|
export default defineApp({
|
||||||
|
name: 'Strava',
|
||||||
|
key: 'strava',
|
||||||
|
iconUrl: '{BASE_URL}/apps/strava/assets/favicon.svg',
|
||||||
|
authDocUrl: 'https://automatisch.io/docs/connections/strava',
|
||||||
|
supportsConnections: true,
|
||||||
|
baseUrl: 'https://www.strava.com',
|
||||||
|
apiBaseUrl: 'https://www.strava.com/api',
|
||||||
|
primaryColor: 'fc4c01',
|
||||||
|
beforeRequest: [addAuthHeader],
|
||||||
|
auth,
|
||||||
|
actions,
|
||||||
|
});
|
@@ -206,6 +206,15 @@ export default defineConfig({
|
|||||||
{ text: 'Connection', link: '/apps/spotify/connection' },
|
{ text: 'Connection', link: '/apps/spotify/connection' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: 'Strava',
|
||||||
|
collapsible: true,
|
||||||
|
collapsed: true,
|
||||||
|
items: [
|
||||||
|
{ text: 'Actions', link: '/apps/strava/actions' },
|
||||||
|
{ text: 'Connection', link: '/apps/strava/connection' },
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: 'Stripe',
|
text: 'Stripe',
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
|
12
packages/docs/pages/apps/strava/actions.md
Normal file
12
packages/docs/pages/apps/strava/actions.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
favicon: /favicons/strava.svg
|
||||||
|
items:
|
||||||
|
- name: Create Totals and Stats Report
|
||||||
|
desc: Creates a report with recent, year to date, and all time stats of your activities.
|
||||||
|
---
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import CustomListing from '../../components/CustomListing.vue'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<CustomListing />
|
14
packages/docs/pages/apps/strava/connection.md
Normal file
14
packages/docs/pages/apps/strava/connection.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Strava
|
||||||
|
|
||||||
|
:::info
|
||||||
|
This page explains the steps you need to follow to set up the Strava connection in Automatisch. If any of the steps are outdated, please let us know!
|
||||||
|
:::
|
||||||
|
|
||||||
|
1. Go to the [link](https://www.strava.com/settings/api) to create an app on Strava API.
|
||||||
|
1. Click on **Upload** button to upload your APP icon.
|
||||||
|
1. Click on **Edit** button.
|
||||||
|
1. Copy **OAuth Redirect URL** from Automatisch and paste it in **Authorization Callback Domain**
|
||||||
|
1. Click on **Save** button.
|
||||||
|
1. Copy **Client ID** from Strava and paste it in **Client ID** field on Automatisch.
|
||||||
|
1. Copy **Client Secret** from Strava and paste it in **Client Secret** field on Automatisch.
|
||||||
|
1. Now, you can start using the Strava connection with Automatisch.
|
@@ -24,6 +24,7 @@ Following integrations are currently supported by Automatisch.
|
|||||||
- [Slack](/apps/slack/actions)
|
- [Slack](/apps/slack/actions)
|
||||||
- [SMTP](/apps/smtp/actions)
|
- [SMTP](/apps/smtp/actions)
|
||||||
- [Spotify](/apps/spotify/actions)
|
- [Spotify](/apps/spotify/actions)
|
||||||
|
- [Strava](/apps/strava/actions)
|
||||||
- [Stripe](/apps/stripe/triggers)
|
- [Stripe](/apps/stripe/triggers)
|
||||||
- [Telegram](/apps/telegram-bot/actions)
|
- [Telegram](/apps/telegram-bot/actions)
|
||||||
- [Todoist](/apps/todoist/triggers)
|
- [Todoist](/apps/todoist/triggers)
|
||||||
|
6
packages/docs/pages/public/favicons/strava.svg
Normal file
6
packages/docs/pages/public/favicons/strava.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
aria-label="Strava" role="img"
|
||||||
|
viewBox="0 0 512 512"><rect
|
||||||
|
width="512" height="512"
|
||||||
|
rx="15%"
|
||||||
|
fill="#fc4c01"/><path fill="#fff" d="M120 288L232 56l112 232h-72l-40-96-40 96z"/><path fill="#fda580" d="M280 288l32 72 32-72h48l-80 168-80-168z"/></svg>
|
After Width: | Height: | Size: 286 B |
Reference in New Issue
Block a user