Skip to content

Commit

Permalink
🔥 The one that removed microsoft application insight (#1051)
Browse files Browse the repository at this point in the history
Since it is not actually used and it caused lot of issues with peer dependencies with pnpm v7
  • Loading branch information
wenche committed May 31, 2022
1 parent 6bda78a commit 7c895f3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 148 deletions.
14 changes: 0 additions & 14 deletions web/common/AppInsights.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions web/common/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"@equinor/eds-core-react": "0.19.0",
"@equinor/eds-icons": "^0.10.0",
"@equinor/eds-tokens": "^0.7.0",
"@microsoft/applicationinsights-react-js": "^3.3.1",
"@microsoft/applicationinsights-web": "^2.8.1",
"@next/bundle-analyzer": "^12.1.0",
"@portabletext/react": "^1.0.6",
"@portabletext/types": "^1.0.3",
Expand Down
51 changes: 25 additions & 26 deletions web/pages/api/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import soapRequest from 'easy-soap-request'
import * as xml2js from 'xml2js'
import { LoginResult, SubscribeFormParameters, NewsDistributionParameters } from '../../types/types'
import { appInsights } from '../../common'
//import { appInsights } from '../../common'

const subscriptionUrl = process.env.BRANDMASTER_EMAIL_SUBSCRIPTION_URL || ''
export const authenticationUrl = process.env.BRANDMASTER_EMAIL_AUTHENTICATION_URL || ''
Expand All @@ -26,9 +26,8 @@ const authenticate = async () => {
let apiSecret = ''
let instId = ''
xml2js.parseString(body, function (err, result) {
if (err != null) console.error("Error while authenticating from Brandmaster : ----------------\n"+err)
if(parsedError(result,"could not get apiSecret and instId ") != undefined)
return
if (err != null) console.error('Error while authenticating from Brandmaster : ----------------\n' + err)
if (parsedError(result, 'could not get apiSecret and instId ') != undefined) return

const soapBody = result['SOAP-ENV:Envelope']['SOAP-ENV:Body']['0']
const loginResult = soapBody['v1:Authentication___LoginResponse']['0']['v1:Result']['0']
Expand Down Expand Up @@ -58,12 +57,12 @@ const createSignUpRequest = async (loginResult: LoginResult, formParameters: Sub
})
xml2js.parseString(response.body, function (err, result) {
if (err != null) {
console.log("Error while creating signup request to Brandmaster : ----------------\n"+err)
console.log('Error while creating signup request to Brandmaster : ----------------\n' + err)
response.statusCode = 500
}
if(parsedError(result,"could not create sign up request ")!= undefined){
if (parsedError(result, 'could not create sign up request ') != undefined) {
response.statusCode = 500
return
return
}
})
return response.statusCode == 200
Expand All @@ -79,19 +78,22 @@ const createDistributeRequest = async (loginResult: LoginResult, parameters: New
})
xml2js.parseString(response.body, function (err, result) {
if (err != null) {
console.error("Error while creating distribute request to Brandmaster : ----------------\n"+err)
console.error('Error while creating distribute request to Brandmaster : ----------------\n' + err)
response.statusCode = 400
}
const error = parsedError(result,"could not distribute newsletter "+parameters.link+" published at "+parameters.timeStamp)
if(error != undefined)
{
const error = parsedError(
result,
'could not distribute newsletter ' + parameters.link + ' published at ' + parameters.timeStamp,
)
if (error != undefined) {
// should trigger mail...
console.log(response.body.toString())
appInsights.trackEvent({name:"Newsletter distribution failure"},{message:error})
console.log('Newsletter distribution failure', response.body.toString())
// @TODO Move to Dynatrace
// appInsights.trackEvent({name:"Newsletter distribution failure"},{message:error})
response.statusCode = 400
}
})

return response.statusCode == 200
}

Expand All @@ -103,19 +105,16 @@ export const signUp = async (formParameters: SubscribeFormParameters) => {

export const distribute = async (parameters: NewsDistributionParameters) => {
const loginResult = await authenticate()
if (loginResult.apiSecret != '' && loginResult.instId != '')
{
if (loginResult.apiSecret != '' && loginResult.instId != '') {
return createDistributeRequest(loginResult, parameters)
}
else return false
} else return false
}

const parsedError = (result:any, prefix:string)=>{
const soapBody = result['SOAP-ENV:Envelope']['SOAP-ENV:Body']['0']
if (soapBody['SOAP-ENV:Fault'] != undefined) {
const error = soapBody['SOAP-ENV:Fault']['0']['faultstring']
console.error(Date()+ " : Newsletter Failure Error: "+prefix +"\n"+error)
return error
}
const parsedError = (result: any, prefix: string) => {
const soapBody = result['SOAP-ENV:Envelope']['SOAP-ENV:Body']['0']
if (soapBody['SOAP-ENV:Fault'] != undefined) {
const error = soapBody['SOAP-ENV:Fault']['0']['faultstring']
console.error(Date() + ' : Newsletter Failure Error: ' + prefix + '\n' + error)
return error
}
}

104 changes: 0 additions & 104 deletions web/pnpm-lock.yaml

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

0 comments on commit 7c895f3

Please sign in to comment.