From 3c55b3a21a1458384de525b9d060a48d3985d013 Mon Sep 17 00:00:00 2001 From: Leonardo Mendoza Date: Tue, 11 Feb 2025 11:26:47 -0600 Subject: [PATCH 1/2] lmendoza/onetrust2 --- .gitignore | 2 +- angular.json | 10 ++++-- package.json | 2 +- ...dev-runtime.ts => environment.prebuild.ts} | 2 +- scripts/onetrust.runtime.js | 36 +++++++++++++++++++ src/environments/environment.int.ts | 1 + src/environments/environment.local.4200.ts | 1 + .../environment.local.dev.orcid.org.ts | 1 + src/environments/environment.production.ts | 1 + src/environments/environment.qa.ts | 1 + src/environments/environment.sandbox.ts | 1 + src/environments/interface.d.ts | 1 + 12 files changed, 54 insertions(+), 5 deletions(-) rename scripts/{runtime-environment-setter.dev-runtime.ts => environment.prebuild.ts} (92%) create mode 100644 scripts/onetrust.runtime.js diff --git a/.gitignore b/.gitignore index 8588024ef..0464abdea 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/angular.json b/angular.json index 02fa219a5..2c392f402 100644 --- a/angular.json +++ b/angular.json @@ -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": { @@ -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 } diff --git a/package.json b/package.json index 1d1695ddd..94c431662 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/runtime-environment-setter.dev-runtime.ts b/scripts/environment.prebuild.ts similarity index 92% rename from scripts/runtime-environment-setter.dev-runtime.ts rename to scripts/environment.prebuild.ts index 1695f810e..017d625a3 100644 --- a/scripts/runtime-environment-setter.dev-runtime.ts +++ b/scripts/environment.prebuild.ts @@ -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' }) diff --git a/scripts/onetrust.runtime.js b/scripts/onetrust.runtime.js new file mode 100644 index 000000000..d0c2211b7 --- /dev/null +++ b/scripts/onetrust.runtime.js @@ -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) + } +})() diff --git a/src/environments/environment.int.ts b/src/environments/environment.int.ts index 05eb30095..669f8defb 100644 --- a/src/environments/environment.int.ts +++ b/src/environments/environment.int.ts @@ -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', diff --git a/src/environments/environment.local.4200.ts b/src/environments/environment.local.4200.ts index 0f7c1ecbd..5c59c139e 100644 --- a/src/environments/environment.local.4200.ts +++ b/src/environments/environment.local.4200.ts @@ -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: 'العربية', diff --git a/src/environments/environment.local.dev.orcid.org.ts b/src/environments/environment.local.dev.orcid.org.ts index ce1db3123..8b102c20b 100644 --- a/src/environments/environment.local.dev.orcid.org.ts +++ b/src/environments/environment.local.dev.orcid.org.ts @@ -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: 'العربية', diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index f8a417aaf..c55a7b86b 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -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', diff --git a/src/environments/environment.qa.ts b/src/environments/environment.qa.ts index 8b1b870a0..62e736b26 100644 --- a/src/environments/environment.qa.ts +++ b/src/environments/environment.qa.ts @@ -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: 'العربية', diff --git a/src/environments/environment.sandbox.ts b/src/environments/environment.sandbox.ts index 838becb14..ebd93e0d8 100644 --- a/src/environments/environment.sandbox.ts +++ b/src/environments/environment.sandbox.ts @@ -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: 'العربية', diff --git a/src/environments/interface.d.ts b/src/environments/interface.d.ts index 49c883eee..f135ec92b 100644 --- a/src/environments/interface.d.ts +++ b/src/environments/interface.d.ts @@ -23,6 +23,7 @@ export interface EnvironmentInterface { [key: string]: string } proxyMode: boolean + ONE_TRUST: string } declare global { From e2ed1a7503afb7c9ea1bff65193e95dd819af64f Mon Sep 17 00:00:00 2001 From: Leonardo Mendoza Date: Tue, 11 Feb 2025 11:52:37 -0600 Subject: [PATCH 2/2] lmendoza/onetrust2 --- scripts/build-info.postbuild.ts | 3 +- scripts/new-relic.postbuild.ts | 64 ------------------- scripts/onetrust.postbuild.ts | 12 ++++ scripts/postbuild.ts | 5 +- .../cdk/platform-info/browserlist.regexp.ts | 3 +- src/index.html | 24 ------- 6 files changed, 16 insertions(+), 95 deletions(-) delete mode 100644 scripts/new-relic.postbuild.ts create mode 100644 scripts/onetrust.postbuild.ts diff --git a/scripts/build-info.postbuild.ts b/scripts/build-info.postbuild.ts index 71196530e..e3525f672 100644 --- a/scripts/build-info.postbuild.ts +++ b/scripts/build-info.postbuild.ts @@ -7,8 +7,7 @@ export function buildInfo(indexHtml, options): string { } catch (err) {} const config = ` - ${ gitInfo ? '' : '' diff --git a/scripts/new-relic.postbuild.ts b/scripts/new-relic.postbuild.ts deleted file mode 100644 index 8231be286..000000000 --- a/scripts/new-relic.postbuild.ts +++ /dev/null @@ -1,64 +0,0 @@ -export function newRelic(indexHtml: string, options) { - if ( - options.environmentVariables && - options.environmentVariables.NEW_RELIC_APP - ) { - return indexHtml.replace( - '', - ` ` - ) - } else { - console.warn( - 'This build will not have google analytics since the UID is not defined on the environment variables' - ) - return indexHtml - } -} diff --git a/scripts/onetrust.postbuild.ts b/scripts/onetrust.postbuild.ts new file mode 100644 index 000000000..cbf0843ae --- /dev/null +++ b/scripts/onetrust.postbuild.ts @@ -0,0 +1,12 @@ +export function addOneTrustNotAutoBlockForAppScripts(data) { + // This regex does the following: + // - `]*\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( + /]*\bdata-ot-ignore\b)([^>]*)>/gi, + ' - -