Skip to content

Commit

Permalink
Merge pull request #2465 from ORCID/lmendoza/onetrust2
Browse files Browse the repository at this point in the history
Lmendoza/onetrust2
  • Loading branch information
leomendoza123 authored Feb 11, 2025
2 parents 27ff09d + e2ed1a7 commit d9becad
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ cypress/plugins/token.json

# Packages ignore package-lock to depend only on yarn
package-lock.json
src/assets/runtime-environment.js
scripts/environment.runtime.js
10 changes: 8 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@
"src/styles.scss",
"src/assets/scss/grid.scss"
],
"scripts": ["src/assets/runtime-environment.js"]
"scripts": [
"/scripts/environment.runtime.js",
"/scripts/onetrust.runtime.js"
]
},
"configurations": {
"local": {
Expand Down Expand Up @@ -370,7 +373,10 @@
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],
"scripts": ["src/assets/runtime-environment.js"],
"scripts": [
"/scripts/environment.runtime.js",
"/scripts/onetrust.runtime.js"
],
"assets": ["src/favicon.ico", "src/assets", "src/manifest.json"],
"sourceMap": true
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start:xx": "ng serve --configuration=local-qa-xx --disable-host-check",
"test": "npm run build-runtime-env && ng test",
"test-headless": "npm run build-runtime-env && ng test --watch=false --browsers=ChromeHeadless",
"build-runtime-env": "ts-node -P scripts/tsconfig.json scripts/runtime-environment-setter.dev-runtime.ts",
"build-runtime-env": "ts-node -P scripts/tsconfig.json scripts/environment.prebuild.ts",
"lint": "echo 'temporally disable Angular linter to until eslint update'",
"e2e": "ng e2e",
"prebuild": "rimraf dist && yarn build:i18n && yarn build:browserslist && npm run build-runtime-env",
Expand Down
3 changes: 1 addition & 2 deletions scripts/build-info.postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export function buildInfo(indexHtml, options): string {
} catch (err) {}

const config = `
<!--${options.languageCode}${
options.environment ? '-' + options.environment : ''
<!--${options.languageCode} ''
} ${new Date().toJSON()}-->
${
gitInfo ? '<!--' + gitInfo.abbreviatedSha + '/' + gitInfo.lastTag + '-->' : ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ${runtimeEnvironmentScript()}`

const outputPath = path.resolve(
__dirname,
'../src/assets/runtime-environment.js'
'../scripts/environment.runtime.js'
)

fs.writeFileSync(outputPath, scriptContent, { encoding: 'utf8' })
Expand Down
64 changes: 0 additions & 64 deletions scripts/new-relic.postbuild.ts

This file was deleted.

12 changes: 12 additions & 0 deletions scripts/onetrust.postbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function addOneTrustNotAutoBlockForAppScripts(data) {
// This regex does the following:
// - `<script\b` matches the literal "<script" followed by a word boundary.
// - `(?![^>]*\bdata-ot-ignore\b)` is a negative lookahead ensuring that the attribute isn't already present.
// - `([^>]*)` captures any other attributes inside the tag (until the closing '>').
//
// The replacement inserts "data-ot-ignore" into the tag.
return data.replace(
/<script\b(?![^>]*\bdata-ot-ignore\b)([^>]*)>/gi,
'<script data-ot-ignore$1>'
)
}
36 changes: 36 additions & 0 deletions scripts/onetrust.runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;(function waitForRuntimeEnvironment() {
// Check if the runtime environment is available.
if (window.runtimeEnvironment) {
console.log('The runtime environment is available.')
console.log(JSON.stringify(window.runtimeEnvironment))
if (window.runtimeEnvironment.ONE_TRUST) {
// Retrieve your key-value (assuming it's a string).
var keyValue = window.runtimeEnvironment.ONE_TRUST

// Create the first script tag.
var script1 = document.createElement('script')
script1.type = 'text/javascript'
script1.src =
'https://cdn.cookielaw.org/consent/' + keyValue + '/OtAutoBlock.js'
document.head.appendChild(script1)

// Create the second script tag.
var script2 = document.createElement('script')
script2.type = 'text/javascript'
script2.src = 'https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'
script2.charset = 'UTF-8'
// Set data attributes as needed.
script2.setAttribute('data-document-language', 'true')
script2.setAttribute('data-domain-script', keyValue)
document.head.appendChild(script2)
console.log('OneTrust has been added.')
} else {
console.log('The runtime environment does not contain the OneTrust key.')
}
} else {
console.log('The runtime environment is not yet available.')
console.log('Checking again in 50ms...')
// If runtimeEnvironment is not yet available, check again in 50ms.
setTimeout(waitForRuntimeEnvironment, 50)
}
})()
5 changes: 2 additions & 3 deletions scripts/postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { getOptionsObjet, save } from './utils'
import { renameSync, readFileSync } from 'fs'
import { createShareAssetsFolder } from './moveToShareFolder.postbuild'
import { addOneTrustNotAutoBlockForAppScripts } from './onetrust.postbuild'

const glob = require('glob')
// Run updates on index.html files across languages
Expand All @@ -16,12 +17,10 @@ glob
.forEach((file) => {
const options = getOptionsObjet(file)
let data = readFileSync(file, 'utf8')
// data = uniqueLength(data, options) DISABLED unique leght for now, as migth not be required anymore
data = buildInfo(data, options)
// data = newRelic(data, options) TEMPORALLY DISABLE NEW RELIC

// Replace all the `*.js` references to match updated JS file names with the language code.
data = addLanguageCodeToHashesOnToHTMLFiles(data, options)
data = addOneTrustNotAutoBlockForAppScripts(data)
// data = robotsMetadata(data, options) DISABLE robots headers, as those will be handle via nginx
save(data, options)
})
Expand Down
3 changes: 1 addition & 2 deletions src/app/cdk/platform-info/browserlist.regexp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// tslint:disable-next-line: max-line-length
export const BROWSERLIST_REGEXP =
/((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(13[_.]4|13[_.]([5-9]|\d{2,})|13[_.]7|13[_.]([8-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})[_.]\d+|14[_.]0|14[_.]([1-9]|\d{2,})|14[_.]4|14[_.]([5-9]|\d{2,})|14[_.]8|14[_.](9|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})[_.]\d+|15[_.]0|15[_.]([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[_.]\d+|16[_.]0|16[_.]([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})[_.]\d+|17[_.]0|17[_.]([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})[_.]\d+)(?:[_.]\d+)?)|((?:Chrome).*OPR\/(74|(7[5-9]|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Edge\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))(?:\.\d+)?)|((Chromium|Chrome)\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))\.\d+(?:\.\d+)?)|(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+|15\.0|15\.([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+|16\.0|16\.([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})\.\d+|17\.0|17\.([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+(pre|[ab]\d+[a-z]*)?)/
export const BROWSERLIST_REGEXP = /((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(13[_.]4|13[_.]([5-9]|\d{2,})|13[_.]7|13[_.]([8-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})[_.]\d+|14[_.]0|14[_.]([1-9]|\d{2,})|14[_.]4|14[_.]([5-9]|\d{2,})|14[_.]8|14[_.](9|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})[_.]\d+|15[_.]0|15[_.]([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[_.]\d+|16[_.]0|16[_.]([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})[_.]\d+|17[_.]0|17[_.]([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})[_.]\d+)(?:[_.]\d+)?)|((?:Chrome).*OPR\/(74|(7[5-9]|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Edge\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))(?:\.\d+)?)|((Chromium|Chrome)\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))\.\d+(?:\.\d+)?)|(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+|15\.0|15\.([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+|16\.0|16\.([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})\.\d+|17\.0|17\.([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+(pre|[ab]\d+[a-z]*)?)/
1 change: 1 addition & 0 deletions src/environments/environment.int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const environment: EnvironmentInterface = {
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://homepage-prod.orcid.org',
WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org',
ONE_TRUST: "5a6d60d3-b085-4e48-8afa-d707c7afc419-test",
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.local.4200.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const environment: EnvironmentInterface = {
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://homepage-qa.orcid.org',
WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org',
ONE_TRUST: "5a6d60d3-b085-4e48-8afa-d707c7afc419-test",
NEW_RELIC_APP: '772335827',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.local.dev.orcid.org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const environment: EnvironmentInterface = {
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://homepage-qa.orcid.org',
WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org',
ONE_TRUST: "5a6d60d3-b085-4e48-8afa-d707c7afc419-test",
NEW_RELIC_APP: '772335827',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const environment: EnvironmentInterface = {
WORDPRESS_S3: 'https://homepage-prod.orcid.org',
WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org',
NEW_RELIC_APP: '772335825',
ONE_TRUST: "5a6d60d3-b085-4e48-8afa-d707c7afc419",
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.qa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const environment: EnvironmentInterface = {
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://homepage-qa.orcid.org',
WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org',
ONE_TRUST: "5a6d60d3-b085-4e48-8afa-d707c7afc419-test",
NEW_RELIC_APP: '772335827',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const environment: EnvironmentInterface = {
VERBOSE_SNACKBAR_ERRORS_REPORTS: false,
WORDPRESS_S3: 'https://homepage-prod.orcid.org',
WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org',
ONE_TRUST: "5a6d60d3-b085-4e48-8afa-d707c7afc419-test",
NEW_RELIC_APP: '772335828',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
Expand Down
1 change: 1 addition & 0 deletions src/environments/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface EnvironmentInterface {
[key: string]: string
}
proxyMode: boolean
ONE_TRUST: string
}

declare global {
Expand Down
24 changes: 0 additions & 24 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="icon" type="image/x-icon" href="./assets/icons/favicon.ico" />
<!-- NEW_RELIC_PLACEHOLDER -->
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
Expand All @@ -19,29 +18,6 @@
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,600,0,0"
/>
<meta name="theme-color" content="#1976d2" />
<script
type="text/javascript"
src="https://cdn.cookielaw.org/consent/5a6d60d3-b085-4e48-8afa-d707c7afc419-test/OtAutoBlock.js"
></script>
<script
type="text/javascript"
src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"
charset="UTF-8"
data-document-language="true"
data-domain-script="5a6d60d3-b085-4e48-8afa-d707c7afc419-test"
></script>
<script type="text/javascript">
function OptanonWrapper() {
const oneTrust = window.document.getElementById('onetrust-consent-sdk')
if (window.location !== window.parent.location && oneTrust) {
oneTrust.style.display = 'none'
}

window.document
.getElementById('onetrust-consent-sdk')
?.setAttribute('data-nosnippet', 'true')
}
</script>
<script
id="ze-snippet"
src="https://static.zdassets.com/ekr/snippet.js?key=b8313acd-6439-4894-b431-8c5a2ae9e7cb"
Expand Down

0 comments on commit d9becad

Please sign in to comment.