Skip to content

Commit d9becad

Browse files
Merge pull request #2465 from ORCID/lmendoza/onetrust2
Lmendoza/onetrust2
2 parents 27ff09d + e2ed1a7 commit d9becad

18 files changed

+70
-100
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ cypress/plugins/token.json
7777

7878
# Packages ignore package-lock to depend only on yarn
7979
package-lock.json
80-
src/assets/runtime-environment.js
80+
scripts/environment.runtime.js

angular.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@
133133
"src/styles.scss",
134134
"src/assets/scss/grid.scss"
135135
],
136-
"scripts": ["src/assets/runtime-environment.js"]
136+
"scripts": [
137+
"/scripts/environment.runtime.js",
138+
"/scripts/onetrust.runtime.js"
139+
]
137140
},
138141
"configurations": {
139142
"local": {
@@ -370,7 +373,10 @@
370373
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
371374
"src/styles.scss"
372375
],
373-
"scripts": ["src/assets/runtime-environment.js"],
376+
"scripts": [
377+
"/scripts/environment.runtime.js",
378+
"/scripts/onetrust.runtime.js"
379+
],
374380
"assets": ["src/favicon.ico", "src/assets", "src/manifest.json"],
375381
"sourceMap": true
376382
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start:xx": "ng serve --configuration=local-qa-xx --disable-host-check",
1212
"test": "npm run build-runtime-env && ng test",
1313
"test-headless": "npm run build-runtime-env && ng test --watch=false --browsers=ChromeHeadless",
14-
"build-runtime-env": "ts-node -P scripts/tsconfig.json scripts/runtime-environment-setter.dev-runtime.ts",
14+
"build-runtime-env": "ts-node -P scripts/tsconfig.json scripts/environment.prebuild.ts",
1515
"lint": "echo 'temporally disable Angular linter to until eslint update'",
1616
"e2e": "ng e2e",
1717
"prebuild": "rimraf dist && yarn build:i18n && yarn build:browserslist && npm run build-runtime-env",

scripts/build-info.postbuild.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export function buildInfo(indexHtml, options): string {
77
} catch (err) {}
88

99
const config = `
10-
<!--${options.languageCode}${
11-
options.environment ? '-' + options.environment : ''
10+
<!--${options.languageCode} ''
1211
} ${new Date().toJSON()}-->
1312
${
1413
gitInfo ? '<!--' + gitInfo.abbreviatedSha + '/' + gitInfo.lastTag + '-->' : ''

scripts/runtime-environment-setter.dev-runtime.ts renamed to scripts/environment.prebuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ${runtimeEnvironmentScript()}`
1010

1111
const outputPath = path.resolve(
1212
__dirname,
13-
'../src/assets/runtime-environment.js'
13+
'../scripts/environment.runtime.js'
1414
)
1515

1616
fs.writeFileSync(outputPath, scriptContent, { encoding: 'utf8' })

scripts/new-relic.postbuild.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

scripts/onetrust.postbuild.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function addOneTrustNotAutoBlockForAppScripts(data) {
2+
// This regex does the following:
3+
// - `<script\b` matches the literal "<script" followed by a word boundary.
4+
// - `(?![^>]*\bdata-ot-ignore\b)` is a negative lookahead ensuring that the attribute isn't already present.
5+
// - `([^>]*)` captures any other attributes inside the tag (until the closing '>').
6+
//
7+
// The replacement inserts "data-ot-ignore" into the tag.
8+
return data.replace(
9+
/<script\b(?![^>]*\bdata-ot-ignore\b)([^>]*)>/gi,
10+
'<script data-ot-ignore$1>'
11+
)
12+
}

scripts/onetrust.runtime.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
;(function waitForRuntimeEnvironment() {
2+
// Check if the runtime environment is available.
3+
if (window.runtimeEnvironment) {
4+
console.log('The runtime environment is available.')
5+
console.log(JSON.stringify(window.runtimeEnvironment))
6+
if (window.runtimeEnvironment.ONE_TRUST) {
7+
// Retrieve your key-value (assuming it's a string).
8+
var keyValue = window.runtimeEnvironment.ONE_TRUST
9+
10+
// Create the first script tag.
11+
var script1 = document.createElement('script')
12+
script1.type = 'text/javascript'
13+
script1.src =
14+
'https://cdn.cookielaw.org/consent/' + keyValue + '/OtAutoBlock.js'
15+
document.head.appendChild(script1)
16+
17+
// Create the second script tag.
18+
var script2 = document.createElement('script')
19+
script2.type = 'text/javascript'
20+
script2.src = 'https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'
21+
script2.charset = 'UTF-8'
22+
// Set data attributes as needed.
23+
script2.setAttribute('data-document-language', 'true')
24+
script2.setAttribute('data-domain-script', keyValue)
25+
document.head.appendChild(script2)
26+
console.log('OneTrust has been added.')
27+
} else {
28+
console.log('The runtime environment does not contain the OneTrust key.')
29+
}
30+
} else {
31+
console.log('The runtime environment is not yet available.')
32+
console.log('Checking again in 50ms...')
33+
// If runtimeEnvironment is not yet available, check again in 50ms.
34+
setTimeout(waitForRuntimeEnvironment, 50)
35+
}
36+
})()

scripts/postbuild.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { getOptionsObjet, save } from './utils'
99
import { renameSync, readFileSync } from 'fs'
1010
import { createShareAssetsFolder } from './moveToShareFolder.postbuild'
11+
import { addOneTrustNotAutoBlockForAppScripts } from './onetrust.postbuild'
1112

1213
const glob = require('glob')
1314
// Run updates on index.html files across languages
@@ -16,12 +17,10 @@ glob
1617
.forEach((file) => {
1718
const options = getOptionsObjet(file)
1819
let data = readFileSync(file, 'utf8')
19-
// data = uniqueLength(data, options) DISABLED unique leght for now, as migth not be required anymore
2020
data = buildInfo(data, options)
21-
// data = newRelic(data, options) TEMPORALLY DISABLE NEW RELIC
22-
2321
// Replace all the `*.js` references to match updated JS file names with the language code.
2422
data = addLanguageCodeToHashesOnToHTMLFiles(data, options)
23+
data = addOneTrustNotAutoBlockForAppScripts(data)
2524
// data = robotsMetadata(data, options) DISABLE robots headers, as those will be handle via nginx
2625
save(data, options)
2726
})
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
// tslint:disable-next-line: max-line-length
2-
export const BROWSERLIST_REGEXP =
3-
/((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]*)?)/
2+
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]*)?)/

0 commit comments

Comments
 (0)