Skip to content

Commit

Permalink
build(deps): update uuid, validator, request (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneRifle committed Jun 30, 2020
1 parent 178d163 commit 3e7b296
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 52 deletions.
109 changes: 72 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"reflect-metadata": "^0.1.13",
"request": "^2.88.0",
"request": "^2.88.2",
"sequelize": "^5.19.4",
"sharp": "^0.25.4",
"ua-parser-js": "^0.7.21",
"uuid": "^3.3.2",
"validator": "^10.11.0",
"uuid": "^8.2.0",
"validator": "^13.1.1",
"winston": "^3.3.3"
},
"devDependencies": {
Expand Down Expand Up @@ -118,13 +118,13 @@
"@types/react-redux": "^7.1.9",
"@types/react-router-dom": "^5.1.5",
"@types/redis-mock": "^0.17.0",
"@types/request": "^2.48.1",
"@types/request": "^2.48.5",
"@types/sharp": "^0.25.0",
"@types/sinon": "^9.0.4",
"@types/ua-parser-js": "^0.7.33",
"@types/upng-js": "^2.1.1",
"@types/uuid": "^3.4.4",
"@types/validator": "^10.11.3",
"@types/uuid": "^8.0.0",
"@types/validator": "^13.1.0",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"babel-eslint": "^10.1.0",
Expand Down
28 changes: 20 additions & 8 deletions src/server/services/googleAnalytics/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express'
import uuidv4 from 'uuid/v4'
import request from 'request'
import { v4 as uuidv4 } from 'uuid'
import fetch from 'cross-fetch'
import { gaTrackingId, logger, ogUrl } from '../../config'
import getIp from '../../util/request'
import IGaPageViewForm from './types/IGaPageViewForm'
Expand Down Expand Up @@ -83,10 +83,16 @@ export function sendTpServedEvent(req: express.Request, shortUrl: string) {
el: shortUrl, // Event label.
}

request.post(gaEndpoint, { form }, (err, httpResponse, body) => {
if (err) {
const body = new URLSearchParams((form as unknown) as Record<string, string>)

fetch(gaEndpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body,
}).then((response) => {
if (!response.ok) {
logger.error(
`GA tracking failure:\tError: ${err}\thttpResponse: ${httpResponse}\t body:${body}`,
`GA tracking failure:\tError: ${response.statusText}\thttpResponse: ${response}\t body:${response.body}`,
)
}
})
Expand Down Expand Up @@ -121,10 +127,16 @@ export function sendPageViewHit(
;[form.ul] = (req.headers['accept-language'] as string).split(',')
}

request.post(gaEndpoint, { form }, (err, httpResponse, body) => {
if (err) {
const body = new URLSearchParams((form as unknown) as Record<string, string>)

fetch(gaEndpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body,
}).then((response) => {
if (!response.ok) {
logger.error(
`GA tracking failure:\tError: ${err}\thttpResponse: ${httpResponse}\t body:${body}`,
`GA tracking failure:\tError: ${response.statusText}\thttpResponse: ${response}\t body:${response.body}`,
)
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/shared/util/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import blacklist from '../../server/resources/blacklist'

export const WHITELIST = [new RegExp('^http://localhost:4566')]

export const URL_OPTS: ValidatorJS.IsURLOptions = {
export const URL_OPTS: validator.IsURLOptions = {
protocols: ['https'],
require_tld: true,
require_protocol: true,
Expand Down

0 comments on commit 3e7b296

Please sign in to comment.