From 2fa6f223bd0d03d1890241603dcbcbeb494a6946 Mon Sep 17 00:00:00 2001 From: dubisdev Date: Sun, 4 Dec 2022 01:26:47 +0100 Subject: [PATCH] fix: delete axios & move to node 18 --- .github/workflows/pull-request.yaml | 2 +- .github/workflows/release.yml | 2 +- deploy.js | 4 +--- package.json | 3 +-- src/services/todoist-api.ts | 31 ++++++++++++++++++----------- yarn.lock | 19 ------------------ 6 files changed, 23 insertions(+), 38 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index c0389db..0d8a9c8 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -15,7 +15,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Install dependencies run: yarn diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9452582..b3433da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Install dependencies run: yarn - name: Release diff --git a/deploy.js b/deploy.js index 2ce4187..550f7e1 100644 --- a/deploy.js +++ b/deploy.js @@ -1,5 +1,3 @@ -import axios from 'axios'; - const deployWebhooksURL = process.env.DEPLOY_ENDPOINT_WEBHOOKS; -if (deployWebhooksURL) await axios.get(deployWebhooksURL); +if (deployWebhooksURL) await fetch(deployWebhooksURL); diff --git a/package.json b/package.json index c60f972..1cc368a 100644 --- a/package.json +++ b/package.json @@ -44,14 +44,13 @@ "@addtodoist/twitter-autohook": "2.2.0", "@bugsnag/js": "7.18.0", "@doist/todoist-api-typescript": "2.1.2", - "axios": "1.2.0", "crypto-js": "4.1.1", "dotenv": "16.0.3", "mongoose": "6.7.5", "twitter-api-v2": "1.12.9" }, "engines": { - "node": ">=16" + "node": ">=18" }, "repository": { "type": "git", diff --git a/src/services/todoist-api.ts b/src/services/todoist-api.ts index 98b0bdf..8981628 100644 --- a/src/services/todoist-api.ts +++ b/src/services/todoist-api.ts @@ -2,16 +2,18 @@ * This module includes tools to interact with the Todoist API. */ -import axios from 'axios'; import { TodoistApi } from '@doist/todoist-api-typescript'; export const getTodoistUserData = async (token: string) => { - const { data } = await axios.post('https://api.todoist.com/sync/v9/sync', - { sync_token: '*', resource_types: ['user'] }, - { headers: { Authorization: `Bearer ${token}` } } - ); - - const {user} = data; + const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }; + const body = JSON.stringify({ sync_token: '*', resource_types: '["user"]' }); + const requestConfig = { method: 'POST', headers, body }; + + const { user } = await fetch('https://api.todoist.com/sync/v9/sync', requestConfig ).then(res => { + if (res.ok) return res.json(); + throw new Error('Something went wrong getting your Todoist user data'); + }); + return user; }; @@ -35,11 +37,16 @@ export const getTodoistProjects = (token: string) => { export const revokeAccessToken = async (token: string) => { const revokeUrl = 'https://api.todoist.com/sync/v9/access_tokens/revoke'; - const { status } = await axios.post(revokeUrl, { - client_id: process.env.TODOIST_CLIENT_ID, - client_secret: process.env.TODOIST_CLIENT_SECRET, - access_token: token, - }); + + const status = await fetch(revokeUrl, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + client_id: process.env.TODOIST_CLIENT_ID, + client_secret: process.env.TODOIST_CLIENT_SECRET, + access_token: token, + }) + }).then(res => res.status); if (status === 204) return true; return false; diff --git a/yarn.lock b/yarn.lock index 3818c1e..38522ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1925,15 +1925,6 @@ axios-retry@^3.1.9: "@babel/runtime" "^7.15.4" is-retry-allowed "^2.2.0" -axios@1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.0.tgz#1cb65bd75162c70e9f8d118a905126c4a201d383" - integrity sha512-zT7wZyNYu3N5Bu0wuZ6QccIf93Qk1eV8LOewxgjOZFd2DenOs98cJ7+Y6703d0wkaXGY6/nZd4EweJaHz9uzQw== - dependencies: - follow-redirects "^1.15.0" - form-data "^4.0.0" - proxy-from-env "^1.1.0" - axios@^0.27.0: version "0.27.2" resolved "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz" @@ -3688,11 +3679,6 @@ follow-redirects@^1.14.9: resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz" integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ== -follow-redirects@^1.15.0: - version "1.15.2" - resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz" - integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== - foreground-child@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz" @@ -6085,11 +6071,6 @@ promzard@^0.3.0: dependencies: read "1" -proxy-from-env@^1.1.0: - version "1.1.0" - resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz" - integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== - pstree.remy@^1.1.8: version "1.1.8" resolved "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz"