Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Remove Axios Package #1350

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,719 changes: 6,530 additions & 4,189 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@sentry/profiling-node": "^8.41.0",
"@types/pg": "^8.10.9",
"ajv": "^8.11.0",
"axios": "0.27.2",
"boxen": "^5.0.0",
"chalk": "^4.1.2",
"chokidar": "^3.5.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/notification/channel/monika-notif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export const send = async (
method: 'POST',
url,
data: content,
headers: {
'Content-Type': 'application/json',
},
})
}

Expand All @@ -95,6 +98,9 @@ export const sendWithCustomContent = async (
method: 'POST',
url,
data: content,
headers: {
'Content-Type': 'application/json',
},
})
}

Expand Down
3 changes: 3 additions & 0 deletions packages/notification/channel/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const send = async (
method: 'POST',
url,
data: content,
headers: {
'Content-Type': 'application/json',
},
})
}

Expand Down
6 changes: 6 additions & 0 deletions packages/notification/channel/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const send = async (
method: 'POST',
url,
data: getContent(message),
headers: {
'Content-Type': 'application/json',
},
})
}

Expand All @@ -68,6 +71,9 @@ export const sendWithCustomContent = async (
method: 'POST',
url,
data: content,
headers: {
'Content-Type': 'application/json',
},
})
}

Expand Down
3 changes: 3 additions & 0 deletions packages/notification/channel/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const send = async (
alert: alertQuery,
},
},
headers: {
'Content-Type': 'application/json',
},
})
}

Expand Down
1 change: 1 addition & 0 deletions packages/notification/channel/workplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const send = async (
baseURL: 'https://graph.workplace.com',
headers: {
Authorization: `Bearer ${access_token}`,
'Content-Type': 'application/json',
},
method: 'POST',
url: '/me/messages',
Expand Down
36 changes: 18 additions & 18 deletions packages/notification/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperjumptech/monika-notification",
"version": "1.18.1",
"version": "1.18.2",
"description": "notification package for monika",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand All @@ -21,27 +21,27 @@
},
"homepage": "https://github.com/hyperjumptech/monika#readme",
"dependencies": {
"@sendgrid/mail": "^7.4.2",
"axios": "^0.27.2",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-spies": "^1.0.0",
"date-fns": "^2.23.0",
"form-data": "^4.0.0",
"joi": "^17.4.0",
"mailgen": "^2.0.15",
"msw": "^2.2.3",
"nodemailer": "6.9.4",
"pino": "8.14.1",
"@sendgrid/mail": "7.7.0",
"axios": "0.27.2",
"date-fns": "2.30.0",
"form-data": "4.0.2",
"joi": "17.13.3",
"mailgen": "2.0.29",
"msw": "2.7.3",
"nodemailer": "6.10.0",
"pino": "8.21.0",
"sqlite": "4.2.1",
"sqlite3": "5.1.6"
"sqlite3": "5.1.7"
},
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-spies": "^1.0.3",
"@types/nodemailer": "^6.4.9",
"tslib": "^2.6.1",
"typescript": "^5.1.6"
"@types/chai-spies": "^1.0.6",
"@types/nodemailer": "^6.4.17",
"chai": "^4.5.0",
"chai-as-promised": "^7.1.2",
"chai-spies": "^1.1.0",
"tslib": "^2.8.1",
"typescript": "^5.8.2"
}
}
8 changes: 6 additions & 2 deletions src/components/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ async function createExampleConfigFile() {
'https://raw.githubusercontent.com/hyperjumptech/monika/main/monika.example.yml'

try {
const resp = await sendHttpRequest({ url })
await writeFile(outputFilePath, resp.data, { encoding: 'utf8' })
const resp = (await sendHttpRequest({ url }).then((resp) =>
resp.text()
)) as string
await writeFile(outputFilePath, resp, {
encoding: 'utf8',
})
} catch {
const ymlConfig = `
probes:
Expand Down
5 changes: 2 additions & 3 deletions src/components/config/parser/insomnia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import type { Config } from '../../../interfaces/config'
import yml from 'js-yaml'
import { compile as compileTemplate } from 'handlebars'
import type { AxiosRequestHeaders, Method } from 'axios'
import Joi from 'joi'

const envValidator = Joi.object({
Expand Down Expand Up @@ -145,7 +144,7 @@
// eslint-disable-next-line camelcase
const url = compileTemplate(res.url)({ base_url: baseUrl })
const authorization = getAuthorizationHeader(res)
let headers: AxiosRequestHeaders | undefined
let headers: Record<string, any> | undefined

Check warning on line 147 in src/components/config/parser/insomnia.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (authorization)
headers = {
authorization,
Expand All @@ -164,7 +163,7 @@
requests: [
{
url,
method: (res?.method ?? 'GET') as Method,
method: res?.method ?? 'GET',
body: JSON.parse(res.body?.text ?? '{}'),
timeout: 10_000,
headers,
Expand Down
17 changes: 7 additions & 10 deletions src/components/config/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export async function parseByType(
return parseConfigByExt({
config,
extension,
source,
})
}

Expand All @@ -87,9 +86,12 @@ async function getConfigFileFromUrl(url: string) {

async function fetchConfigFile(url: string) {
try {
const { data } = await sendHttpRequest({ url })
const resp = await sendHttpRequest({ url })
if (!resp.ok) {
throw new Error(`The configuration file in ${url} is unreachable.`)
}

return data
return await resp.text()
} catch {
throw new Error(`The configuration file in ${url} is unreachable.`)
}
Expand All @@ -98,19 +100,14 @@ async function fetchConfigFile(url: string) {
type ParseConfigByExtParams = {
config: string
extension: string
source: string
}

function parseConfigByExt({
config,
extension,
source,
}: ParseConfigByExtParams) {
function parseConfigByExt({ config, extension }: ParseConfigByExtParams) {
const isYaml = ['.yaml', '.yml'].includes(extension)

if (isYaml) {
return yml.load(config, { json: true }) as Config
}

return isUrl(source) ? config : JSON.parse(config)
return JSON.parse(config)
}
7 changes: 1 addition & 6 deletions src/components/logger/startup-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ type LogStartupMessage = {
config: ValidatedConfig
flags: Pick<
MonikaFlags,
| 'config'
| 'symonKey'
| 'symonUrl'
| 'verbose'
| 'native-fetch'
| 'skip-start-message'
'config' | 'symonKey' | 'symonUrl' | 'verbose' | 'skip-start-message'
>
isFirstRun: boolean
}
Expand Down
49 changes: 0 additions & 49 deletions src/components/probe/prober/http/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,55 +314,6 @@ describe('probingHTTP', () => {
expect(res.status).to.eq(200)
})

it('Should handle HTTP redirect with axios', async () => {
// arrange
setContext({
...getContext(),
flags: {
...getContext().flags,
'follow-redirects': 3,
},
})
server.use(
http.get(
'https://example.com/get',
() => new HttpResponse(null, { status: 200 })
),
http.get(
'https://example.com/redirect/:nredirect',
async ({ params }) => {
const { nredirect } = params
const castRedirect = Number(nredirect)
return new HttpResponse(null, {
status: 302,
headers: [
[
'Location',
castRedirect === 1
? 'https://example.com/get'
: `https://example.com/redirect/${castRedirect - 1}`,
],
],
})
}
)
)

const requestConfig: RequestConfig = {
url: 'https://example.com/redirect/3',
method: 'GET',
body: '',
timeout: 10_000,
followRedirects: 3,
}

const res = await httpRequest({
requestConfig,
responses: [],
})

expect(res.status).to.eq(200)
})
it('Should handle HTTP redirect with fetch', async () => {
// arrange
server.use(
Expand Down
Loading
Loading