@tilli-pro/cookieconsent-plugin 0.2.0 → 0.2.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.cache/tsbuildinfo.json +1 -1
  2. package/dist/_types.d.ts +3 -0
  3. package/dist/_types.d.ts.map +1 -0
  4. package/dist/_types.js +1 -0
  5. package/dist/_utils.d.ts +10 -0
  6. package/dist/_utils.d.ts.map +1 -0
  7. package/dist/_utils.js +31 -0
  8. package/dist/config/gui-options/scripts/cookiePrefsButtonDragObserver.d.ts.map +1 -1
  9. package/dist/config/gui-options/scripts/cookiePrefsButtonDragObserver.js +1 -1
  10. package/dist/config/gui-options/scripts/injectManageCookiePrefsButton.d.ts +2 -0
  11. package/dist/config/gui-options/scripts/injectManageCookiePrefsButton.d.ts.map +1 -1
  12. package/dist/config/gui-options/scripts/injectManageCookiePrefsButton.js +4 -1
  13. package/dist/config/index.d.ts +26 -1
  14. package/dist/config/index.d.ts.map +1 -1
  15. package/dist/config/index.js +5 -1
  16. package/dist/config/translations/de/index.d.ts +5 -0
  17. package/dist/config/translations/de/index.d.ts.map +1 -1
  18. package/dist/config/translations/de/index.js +5 -0
  19. package/dist/config/translations/en/index.d.ts +5 -0
  20. package/dist/config/translations/en/index.d.ts.map +1 -1
  21. package/dist/config/translations/en/index.js +5 -0
  22. package/dist/config/translations/es/index.d.ts +5 -0
  23. package/dist/config/translations/es/index.d.ts.map +1 -1
  24. package/dist/config/translations/es/index.js +5 -0
  25. package/dist/config/translations/fr/index.d.ts +5 -0
  26. package/dist/config/translations/fr/index.d.ts.map +1 -1
  27. package/dist/config/translations/fr/index.js +5 -0
  28. package/dist/config/translations/index.d.ts +25 -0
  29. package/dist/config/translations/index.d.ts.map +1 -1
  30. package/dist/config/translations/it/index.d.ts +5 -0
  31. package/dist/config/translations/it/index.d.ts.map +1 -1
  32. package/dist/config/translations/it/index.js +5 -0
  33. package/dist/init/brf.d.ts +2 -0
  34. package/dist/init/brf.d.ts.map +1 -0
  35. package/dist/init/brf.js +65 -0
  36. package/dist/init/tilli-website.d.ts +2 -0
  37. package/dist/init/tilli-website.d.ts.map +1 -0
  38. package/dist/init/tilli-website.js +24 -0
  39. package/dist/init/utils.d.ts +5 -0
  40. package/dist/init/utils.d.ts.map +1 -0
  41. package/dist/init/utils.js +39 -0
  42. package/dist/init/website.d.ts +2 -0
  43. package/dist/init/website.d.ts.map +1 -0
  44. package/dist/init/website.js +73 -0
  45. package/dist/init.d.ts +15 -1
  46. package/dist/init.d.ts.map +1 -1
  47. package/dist/init.js +76 -3
  48. package/dist/react-components/CookieConsentInit.client.d.ts.map +1 -1
  49. package/dist/react-components/CookieConsentInit.client.js +2 -23
  50. package/dist/react-components/CookieConsentInit.server.d.ts +2 -2
  51. package/dist/react-components/CookieConsentInit.server.d.ts.map +1 -1
  52. package/dist/react-components/CookieConsentInit.server.js +2 -2
  53. package/dist/react-components/hooks/useCookieConsent.d.ts +4 -0
  54. package/dist/react-components/hooks/useCookieConsent.d.ts.map +1 -0
  55. package/dist/react-components/hooks/useCookieConsent.js +17 -0
  56. package/dist/styles/index.d.ts +8 -0
  57. package/dist/styles/index.d.ts.map +1 -0
  58. package/dist/styles/index.js +6 -0
  59. package/package.json +11 -11
  60. package/scripts/postbuild/inject-plugin.ts +127 -9
  61. package/src/{react-components/_utils.ts → _utils.ts} +2 -2
  62. package/src/config/gui-options/scripts/cookiePrefsButtonDragObserver.ts +2 -1
  63. package/src/config/gui-options/scripts/injectManageCookiePrefsButton.ts +13 -1
  64. package/src/config/index.ts +14 -1
  65. package/src/config/translations/de/index.ts +7 -0
  66. package/src/config/translations/en/index.ts +7 -0
  67. package/src/config/translations/es/index.ts +7 -0
  68. package/src/config/translations/fr/index.ts +7 -0
  69. package/src/config/translations/it/index.ts +7 -0
  70. package/src/init/brf.ts +78 -0
  71. package/src/init/tilli-website.ts +37 -0
  72. package/src/init/utils.ts +66 -0
  73. package/src/init.ts +102 -3
  74. package/src/react-components/CookieConsentInit.client.tsx +2 -27
  75. package/src/react-components/CookieConsentInit.server.tsx +2 -2
  76. package/src/react-components/hooks/useCookieConsent.ts +30 -0
  77. package/src/styles/index.ts +6 -0
  78. package/src/styles/tenants/freeman.css +63 -0
  79. package/src/styles/tenants/frontier.css +71 -0
  80. /package/{src/react-components → dist}/styles/tenants/freeman.css +0 -0
  81. /package/{src/react-components → dist}/styles/tenants/frontier.css +0 -0
  82. /package/src/{react-components/_types.ts → _types.ts} +0 -0
package/dist/init.d.ts CHANGED
@@ -1,2 +1,16 @@
1
- import "https://rawcdn.githack.com/tilli-pro/cookieconsent/0f888b603ba1077d94776af62d2bfb7247e5ffe4/dist/cookieconsent.umd.js?min=1";
1
+ import "https://cdn.jsdelivr.net/gh/tilli-pro/cookieconsent@0f888b603ba1077d94776af62d2bfb7247e5ffe4/dist/cookieconsent.umd.js";
2
+ import type * as _CookieConsent from "@tilli-pro/cookieconsent";
3
+ import type { CookieConsentConfig } from "@tilli-pro/cookieconsent";
4
+ import { cookieConsentTheme } from "./_utils";
5
+ declare namespace CookieConsent {
6
+ const run: typeof _CookieConsent.run;
7
+ }
8
+ declare global {
9
+ interface Window {
10
+ cookieConsentTheme: typeof cookieConsentTheme;
11
+ }
12
+ }
13
+ export declare const makeRemotePluginURL: (path: string) => string;
14
+ export declare const run: (config?: CookieConsentConfig) => ReturnType<typeof CookieConsent.run>;
15
+ export {};
2
16
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,6HAA6H,CAAC"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,wHAAwH,CAAC;AAEhI,OAAO,KAAK,KAAK,cAAc,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAK9C,OAAO,WAAQ,aAAa,CAAC;IAC3B,MAAM,GAAG,EAAE,OAAO,cAAc,CAAC,GAAG,CAAC;CACtC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;KAC/C;CACF;AAQD,eAAO,MAAM,mBAAmB,SAAU,MAAM,WACf,CAAC;AAkDlC,eAAO,MAAM,GAAG,YACN,mBAAmB,KAC1B,UAAU,CAAC,OAAO,aAAa,CAAC,GAAG,CAAoC,CAAC"}
package/dist/init.js CHANGED
@@ -1,3 +1,76 @@
1
- import "https://rawcdn.githack.com/tilli-pro/cookieconsent/0f888b603ba1077d94776af62d2bfb7247e5ffe4/dist/cookieconsent.umd.js?min=1";
2
- import config from "./config";
3
- CookieConsent.run(config);
1
+ import "https://cdn.jsdelivr.net/gh/tilli-pro/cookieconsent@0f888b603ba1077d94776af62d2bfb7247e5ffe4/dist/cookieconsent.umd.js";
2
+ import { cookieConsentTheme } from "./_utils";
3
+ import _config from "./config";
4
+ import styles from "./styles";
5
+ const GIT_SHA = "5d10d218837ca7ecd0362b35a3333eaf07efe92d";
6
+ const GIT_REPO = "tilli-pro/cookieconsent";
7
+ const GIT_CDN_BASE_URL = "https://cdn.jsdelivr.net/gh";
8
+ const GIT_CDN_URL = `${GIT_CDN_BASE_URL}/${GIT_REPO}@${GIT_SHA}`;
9
+ const GIT_DIST_URL = `${GIT_CDN_URL}/dist`;
10
+ const makeRemoteURL = (path) => `${GIT_DIST_URL}/${path}`;
11
+ export const makeRemotePluginURL = (path) => makeRemoteURL(`plugin/${path}`);
12
+ const CC_CSS_URL = makeRemoteURL("cookieconsent.css");
13
+ const getFilenameWithPathFromRemoteURL = (url) => {
14
+ const urlObj = new URL(url);
15
+ const path = urlObj.pathname;
16
+ const file = path.split("/").pop();
17
+ return file;
18
+ };
19
+ function loadCSS(url) {
20
+ if (document.querySelector(`link[href*="${getFilenameWithPathFromRemoteURL(url)}"]`)) {
21
+ // console.debug(`CSS already loaded: ${url}`);
22
+ return; // prevent duplication
23
+ }
24
+ const link = document.createElement("link");
25
+ Object.assign(link, {
26
+ rel: "stylesheet",
27
+ type: "text/css",
28
+ href: url,
29
+ });
30
+ document.head.appendChild(link);
31
+ }
32
+ function loadNestedPluginCSS(basePath, obj) {
33
+ for (const [key, value] of Object.entries(obj))
34
+ if (typeof value === "string") {
35
+ const url = makeRemotePluginURL(`${basePath}/${value}`);
36
+ // console.debug(`Loading plugin CSS from ${url}`);
37
+ loadCSS(url);
38
+ }
39
+ else if (value && typeof value === "object") {
40
+ // console.debug(`Loading nested plugin CSS from ${basePath}/${key}`);
41
+ loadNestedPluginCSS(`${basePath}/${key}`, value);
42
+ }
43
+ }
44
+ async function always() {
45
+ loadCSS(CC_CSS_URL);
46
+ loadNestedPluginCSS("styles", styles); // TODO: make dynamic (only import dependent styles - aka if a certain `init` config is specified)
47
+ window.cookieConsentTheme = cookieConsentTheme; // used to fetch the correct classname to apply a specified theme | THIS SHOULD BE INJECTED INTO THE <HTML> TAG!!! // TODO: auto-inject (?)
48
+ }
49
+ void always();
50
+ export const run = async (config = _config) => await CookieConsent.run(config);
51
+ // ⚠️ NOTE: DISABLED THIS ENTRY MODULE SINCE ALL INITS SHOULD BE USING A SPECIFICALLY-CONFIGURED ENTRY MODULE INSTEAD (e.g. `init/brf.ts`, `init/tilli-website.ts`) !!!
52
+ // function isEntryModule(): boolean {
53
+ // if (typeof document === "undefined") return false;
54
+ // try {
55
+ // const currentModuleUrl = new URL(import.meta.url, document.baseURI).href;
56
+ // const scripts = Array.from(
57
+ // document.querySelectorAll('script[type="module"]'),
58
+ // );
59
+ // return scripts.some((script) => {
60
+ // const src = script.getAttribute("src");
61
+ // if (!src) return false;
62
+ // return new URL(src, document.baseURI).href === currentModuleUrl;
63
+ // });
64
+ // } catch (err) {
65
+ // console.error("Error checking module entry:", err);
66
+ // return false;
67
+ // }
68
+ // }
69
+ // if (isEntryModule()) {
70
+ // // console.debug(
71
+ // // { config: _config },
72
+ // // "Initializing Cookie Consent (entry module)...",
73
+ // // );
74
+ // const init = makeInitFn(run, _config);
75
+ // void init();
76
+ // }
@@ -1 +1 @@
1
- {"version":3,"file":"CookieConsentInit.client.d.ts","sourceRoot":"","sources":["../../src/react-components/CookieConsentInit.client.tsx"],"names":[],"mappings":"AAWA,MAAM,CAAC,OAAO,UAAU,iBAAiB,SAsBxC"}
1
+ {"version":3,"file":"CookieConsentInit.client.d.ts","sourceRoot":"","sources":["../../src/react-components/CookieConsentInit.client.tsx"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,iBAAiB,SAIxC"}
@@ -1,27 +1,6 @@
1
1
  "use client";
2
- import { useEffect } from "react";
3
- import { run } from "@tilli-pro/cookieconsent";
4
- import { COOKIE_CONSENT_ENABLED } from "../_consts";
5
- import config from "../config";
6
- import { injectReactRemoveScrollToggle } from "../config/gui-options/scripts/forceDisableReactRemoveScroll";
7
- import injectManageCookiePrefsButton from "../config/gui-options/scripts/injectManageCookiePrefsButton";
2
+ import useCookieConsent from "./hooks/useCookieConsent";
8
3
  export default function CookieConsentInit() {
9
- useEffect(() => {
10
- if (!COOKIE_CONSENT_ENABLED)
11
- return;
12
- void (async () => {
13
- /** inject the cookie-consent banner (pop-up) */
14
- await run(config);
15
- /** ...then, inject the floating cookie consent "manage preferences" icon button into the DOM (floats @ the bottom right) */
16
- injectManageCookiePrefsButton();
17
- /** ...and, force-disable "react-remove-scroll" -- only upon opening up the "manage preferences" dialog
18
- *
19
- * > this handles the edge case where there's a shadcn (radix-ui) dialog open
20
- * underneath the cookie banner's "manage preferences" dialog, which prevents
21
- * the user from scrolling within the manage prefs dialog
22
- */
23
- injectReactRemoveScrollToggle();
24
- })();
25
- }, []);
4
+ useCookieConsent();
26
5
  return null;
27
6
  }
@@ -1,7 +1,7 @@
1
1
  import "server-only";
2
2
  import "@tilli-pro/cookieconsent/dist/cookieconsent.css";
3
- import "./styles/tenants/freeman.css";
4
- import "./styles/tenants/frontier.css";
3
+ import "../styles/tenants/freeman.css";
4
+ import "../styles/tenants/frontier.css";
5
5
  /** we use a server component to handle dynamic injection of the script all together
6
6
  * > basically, there's no need to inject the client-side cookie-consent script if it's not in scope */
7
7
  export default function CookieConsentInit(): import("react/jsx-runtime").JSX.Element | null;
@@ -1 +1 @@
1
- {"version":3,"file":"CookieConsentInit.server.d.ts","sourceRoot":"","sources":["../../src/react-components/CookieConsentInit.server.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAKrB,OAAO,iDAAiD,CAAC;AACzD,OAAO,8BAA8B,CAAC;AACtC,OAAO,+BAA+B,CAAC;AAEvC;uGACuG;AACvG,MAAM,CAAC,OAAO,UAAU,iBAAiB,mDAExC"}
1
+ {"version":3,"file":"CookieConsentInit.server.d.ts","sourceRoot":"","sources":["../../src/react-components/CookieConsentInit.server.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAKrB,OAAO,iDAAiD,CAAC;AACzD,OAAO,+BAA+B,CAAC;AACvC,OAAO,gCAAgC,CAAC;AAExC;uGACuG;AACvG,MAAM,CAAC,OAAO,UAAU,iBAAiB,mDAExC"}
@@ -3,8 +3,8 @@ import "server-only";
3
3
  import { COOKIE_CONSENT_ENABLED } from "../_consts";
4
4
  import CookieConsentInitClient from "./CookieConsentInit.client";
5
5
  import "@tilli-pro/cookieconsent/dist/cookieconsent.css";
6
- import "./styles/tenants/freeman.css";
7
- import "./styles/tenants/frontier.css";
6
+ import "../styles/tenants/freeman.css";
7
+ import "../styles/tenants/frontier.css";
8
8
  /** we use a server component to handle dynamic injection of the script all together
9
9
  * > basically, there's no need to inject the client-side cookie-consent script if it's not in scope */
10
10
  export default function CookieConsentInit() {
@@ -0,0 +1,4 @@
1
+ import type * as _CookieConsent from "@tilli-pro/cookieconsent";
2
+ export declare const run: typeof _CookieConsent.run;
3
+ export default function useCookieConsent(): void;
4
+ //# sourceMappingURL=useCookieConsent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCookieConsent.d.ts","sourceRoot":"","sources":["../../../src/react-components/hooks/useCookieConsent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,cAAc,MAAM,0BAA0B,CAAC;AAYhE,eAAO,MAAM,GAAG,2BAIoC,CAAC;AAErD,MAAM,CAAC,OAAO,UAAU,gBAAgB,SAOvC"}
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import { useEffect } from "react";
3
+ import { COOKIE_CONSENT_ENABLED } from "../../_consts";
4
+ import config from "../../config";
5
+ import { makeInitFn } from "../../init/utils";
6
+ export const run = typeof CookieConsent !== "undefined" &&
7
+ typeof CookieConsent.run === "function"
8
+ ? CookieConsent.run
9
+ : (await import("@tilli-pro/cookieconsent")).run;
10
+ export default function useCookieConsent() {
11
+ useEffect(() => {
12
+ if (!COOKIE_CONSENT_ENABLED)
13
+ return;
14
+ const init = makeInitFn(run, config);
15
+ void init();
16
+ }, []);
17
+ }
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ readonly tenants: {
3
+ readonly freeman: "freeman.css";
4
+ readonly frontier: "frontier.css";
5
+ };
6
+ };
7
+ export default _default;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":";;;;;;AAAA,wBAKW"}
@@ -0,0 +1,6 @@
1
+ export default {
2
+ tenants: {
3
+ freeman: "freeman.css",
4
+ frontier: "frontier.css",
5
+ },
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tilli-pro/cookieconsent-plugin",
3
- "version": "0.2.0",
3
+ "version": "0.2.42",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,14 +19,6 @@
19
19
  ]
20
20
  }
21
21
  },
22
- "scripts": {
23
- "build": "tsc && cpx \"src/**/*.css\" dist",
24
- "postbuild": "tsx ./scripts/postbuild/inject-plugin.ts",
25
- "clean": "git clean -xdf .cache .turbo dist node_modules",
26
- "format": "prettier --check . --ignore-path ../../.gitignore --ignore-path .gitignore",
27
- "lint": "eslint",
28
- "typecheck": "tsc --noEmit --emitDeclarationOnly false"
29
- },
30
22
  "dependencies": {
31
23
  "@tilli-pro/cookieconsent": "3.0.1",
32
24
  "next": "14.2.15",
@@ -45,5 +37,13 @@
45
37
  "tsx": "4.19.3",
46
38
  "typescript": "5.6.2"
47
39
  },
48
- "prettier": "@tilli-pro/prettier-config"
49
- }
40
+ "prettier": "@tilli-pro/prettier-config",
41
+ "scripts": {
42
+ "build": "tsc && cpx \"src/**/*.css\" dist",
43
+ "postbuild": "tsx ./scripts/postbuild/inject-plugin.ts",
44
+ "clean": "git clean -xdf .cache .turbo dist node_modules",
45
+ "format": "prettier --check . --ignore-path ../../.gitignore --ignore-path .gitignore",
46
+ "lint": "eslint",
47
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false"
48
+ }
49
+ }
@@ -7,27 +7,145 @@ const __filename = fileURLToPath(import.meta.url);
7
7
  const __dirname = path.dirname(__filename);
8
8
 
9
9
  const sourceDir = path.resolve(__dirname, "..", "..", "dist");
10
- const destDir = path.resolve(__dirname, "..", "..", "..", "dist", "plugin"); // new plugin folder
10
+ const destDir = path.resolve(__dirname, "..", "..", "..", "dist", "plugin");
11
+ const backupDestDir = path.resolve(
12
+ __dirname,
13
+ "..",
14
+ "..",
15
+ "..",
16
+ "dist",
17
+ "plugin.old",
18
+ );
11
19
 
12
20
  function injectPlugin(src: string, dest: string): void {
13
- /** ensure exists */
14
- if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
21
+ try {
22
+ if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
23
+ } catch (err) {
24
+ console.error(`Failed to create directory ${dest}:`, err);
25
+ throw err;
26
+ }
15
27
 
16
- const entries = fs.readdirSync(src, { withFileTypes: true });
28
+ let entries;
29
+ try {
30
+ entries = fs.readdirSync(src, { withFileTypes: true });
31
+ } catch (err) {
32
+ console.error(`Failed to read directory ${src}:`, err);
33
+ throw err;
34
+ }
17
35
 
18
36
  for (const entry of entries) {
19
37
  const srcPath = path.join(src, entry.name);
20
38
  const destPath = path.join(dest, entry.name);
21
39
 
22
- if (entry.isDirectory()) injectPlugin(srcPath, destPath);
23
- else if (entry.isFile()) {
40
+ if (entry.isDirectory()) {
41
+ try {
42
+ injectPlugin(srcPath, destPath);
43
+ } catch (err) {
44
+ console.error(`Error processing directory ${srcPath}:`, err);
45
+ }
46
+ } else if (entry.isFile()) {
24
47
  const ext = path.extname(entry.name);
25
48
  /** only copy .js and .css files */
26
- if (ext === ".js" || ext === ".css") fs.copyFileSync(srcPath, destPath);
49
+ if (ext === ".js" || ext === ".css") {
50
+ try {
51
+ fs.copyFileSync(srcPath, destPath);
52
+ } catch (err) {
53
+ console.error(
54
+ `Failed to copy file from ${srcPath} to ${destPath}:`,
55
+ err,
56
+ );
57
+ }
58
+ }
27
59
  }
28
60
  }
29
61
  }
30
62
 
31
- injectPlugin(sourceDir, destDir);
63
+ function transformImportPaths(filePath: string): void {
64
+ try {
65
+ let code = fs.readFileSync(filePath, "utf8");
66
+ code = code.replace(
67
+ /(import\s+(?:.*?\s+from\s+)?["'])(\.{1,2}\/[^"']+)(["'])/g,
68
+ (match, prefix, importPath, suffix) => {
69
+ /** skip if import path already has a .js or .css extension */
70
+ if (importPath.endsWith(".js") || importPath.endsWith(".css"))
71
+ return match;
72
+
73
+ const absolutePath = path.resolve(path.dirname(filePath), importPath);
74
+ if (fs.existsSync(absolutePath + ".js"))
75
+ return `${prefix}${importPath}.js${suffix}`;
76
+ else if (fs.existsSync(path.join(absolutePath, "index.js")))
77
+ return `${prefix}${importPath}/index.js${suffix}`;
78
+
79
+ return match;
80
+ },
81
+ );
82
+ fs.writeFileSync(filePath, code, "utf8");
83
+ } catch (err) {
84
+ console.error(`Error processing file ${filePath}:`, err);
85
+ }
86
+ }
87
+
88
+ function processDirectoryForTransform(dir: string): void {
89
+ let entries;
90
+ try {
91
+ entries = fs.readdirSync(dir, { withFileTypes: true });
92
+ } catch (err) {
93
+ console.error(`Failed to read directory ${dir}:`, err);
94
+ return;
95
+ }
96
+ for (const entry of entries) {
97
+ const fullPath = path.join(dir, entry.name);
98
+ if (entry.isDirectory()) processDirectoryForTransform(fullPath);
99
+ else if (entry.isFile() && path.extname(entry.name) === ".js")
100
+ transformImportPaths(fullPath);
101
+ }
102
+ }
32
103
 
33
- console.log(`Plugin files copied from ${sourceDir} to ${destDir}`);
104
+ /** backup */
105
+ let backupExists = false;
106
+ if (fs.existsSync(destDir)) {
107
+ try {
108
+ if (fs.existsSync(backupDestDir))
109
+ fs.rmSync(backupDestDir, { recursive: true, force: true });
110
+ fs.renameSync(destDir, backupDestDir);
111
+ backupExists = true;
112
+ console.log(`Existing destination directory renamed to ${backupDestDir}`);
113
+ } catch (err) {
114
+ console.error("Failed to backup existing destination directory:", err);
115
+ process.exit(1);
116
+ }
117
+ }
118
+
119
+ try {
120
+ injectPlugin(sourceDir, destDir);
121
+ console.log(`Plugin files copied from ${sourceDir} to ${destDir}`);
122
+
123
+ processDirectoryForTransform(destDir);
124
+ console.log(
125
+ "Import paths in JS files have been transformed to include explicit file extensions.",
126
+ );
127
+
128
+ if (backupExists) {
129
+ fs.rmSync(backupDestDir, { recursive: true, force: true });
130
+ console.log(`Backup directory ${backupDestDir} deleted successfully.`);
131
+ }
132
+ } catch (err) {
133
+ console.error("Error during plugin injection or transformation:", err);
134
+
135
+ /** attempt to restore from backup */
136
+ if (backupExists) {
137
+ try {
138
+ if (fs.existsSync(destDir))
139
+ fs.rmSync(destDir, { recursive: true, force: true });
140
+
141
+ fs.renameSync(backupDestDir, destDir);
142
+ console.log(
143
+ `Restored backup directory from ${backupDestDir} to ${destDir}.`,
144
+ );
145
+ } catch (restoreErr) {
146
+ console.error("Failed to restore backup directory:", restoreErr);
147
+ }
148
+ }
149
+
150
+ process.exit(1);
151
+ }
@@ -1,6 +1,6 @@
1
- import type { Language, Locale } from "../config/translations/types";
1
+ import type { Language, Locale } from "./config/translations/types";
2
2
  import type { TenantRefId, Theme } from "./_types";
3
- import { COOKIE_CONSENT_TEST_SEARCH_PARAM_KEY_PREFIX } from "../_consts";
3
+ import { COOKIE_CONSENT_TEST_SEARCH_PARAM_KEY_PREFIX } from "./_consts";
4
4
 
5
5
  type SupportedTenantThemes = Partial<Record<TenantRefId, Theme[]>>;
6
6
  const SUPPORTED_TENANT_THEMES = {
@@ -1,8 +1,9 @@
1
1
  "use client";
2
2
 
3
- import { showPreferences } from "@tilli-pro/cookieconsent";
3
+ import type * as _CookieConsent from "@tilli-pro/cookieconsent";
4
4
 
5
5
  import { buttonId } from "../html-components/ManageCookiePrefsButton";
6
+ import { showPreferences } from "./injectManageCookiePrefsButton";
6
7
 
7
8
  /**
8
9
  * attach a MutationObserver the **first time** the user hovers over–
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { showPreferences } from "@tilli-pro/cookieconsent";
3
+ import type * as _CookieConsent from "@tilli-pro/cookieconsent";
4
4
 
5
5
  import type { HTMLDivElementWithDragObserver } from "./cookiePrefsButtonDragObserver";
6
6
  import ManageCookiePrefsButton, {
@@ -11,6 +11,18 @@ import cookiePrefsButtonDragObserver, {
11
11
  ontouchstart,
12
12
  } from "./cookiePrefsButtonDragObserver";
13
13
 
14
+ declare const CookieConsent:
15
+ | {
16
+ showPreferences?: typeof _CookieConsent.showPreferences;
17
+ }
18
+ | undefined;
19
+
20
+ export const showPreferences =
21
+ typeof CookieConsent !== "undefined" &&
22
+ typeof CookieConsent.showPreferences === "function"
23
+ ? CookieConsent.showPreferences
24
+ : (await import("@tilli-pro/cookieconsent")).showPreferences;
25
+
14
26
  /** injects the floating cookie consent "manage preferences" icon button into the DOM */
15
27
  const inject = (): HTMLDivElement => {
16
28
  const container = document.body.appendChild(
@@ -5,11 +5,24 @@ import categories from "./categories";
5
5
  import guiOptions from "./gui-options";
6
6
  import translations from "./translations";
7
7
 
8
+ /** polyfill for pure JS support */
9
+ declare const process: {
10
+ env: {
11
+ NODE_ENV?: "development" | "production";
12
+ };
13
+ } | undefined;
14
+
15
+ const isProduction =
16
+ (typeof process !== "undefined" &&
17
+ typeof process.env !== "undefined" &&
18
+ typeof process.env.NODE_ENV === "string" &&
19
+ process.env.NODE_ENV === "production") || true;
20
+
8
21
  export default {
9
22
  revision: REVISION,
10
23
  guiOptions,
11
24
  categories,
12
25
  language: { default: "en", autoDetect: "browser", translations },
13
26
  cookie: { name: COOKIE_PREFERENCES_COOKIE_NAME },
14
- hideFromBots: process.env.NODE_ENV === "production", // disabled in local dev to enable ui-testing (via Playwright)
27
+ hideFromBots: isProduction, // disabled in local dev to enable ui-testing (via Playwright)
15
28
  } satisfies CookieConsentConfig;
@@ -93,6 +93,13 @@ export default {
93
93
  },
94
94
  },
95
95
 
96
+ {
97
+ title: "Marketing-Cookies",
98
+ description:
99
+ "Diese Cookies werden verwendet, um Werbung bereitzustellen, die für Ihre Interessen relevant ist. Sie können Ihr Surfverhalten auf verschiedenen Websites verfolgen und Werbetreibenden helfen, personalisierte Anzeigen anzuzeigen.",
100
+ linkedCategory: "marketing",
101
+ },
102
+
96
103
  {
97
104
  title: "Weitere Informationen",
98
105
  description:
@@ -93,6 +93,13 @@ export default {
93
93
  },
94
94
  },
95
95
 
96
+ {
97
+ title: "Marketing cookies",
98
+ description:
99
+ "These cookies are used to deliver advertisements that are relevant to your interests. They may track your browsing behaviors across different sites and help advertisers serve more personalized ads.",
100
+ linkedCategory: "marketing",
101
+ },
102
+
96
103
  {
97
104
  title: "More information",
98
105
  description:
@@ -93,6 +93,13 @@ export default {
93
93
  },
94
94
  },
95
95
 
96
+ {
97
+ title: "Cookies de marketing",
98
+ description:
99
+ "Estas cookies se utilizan para mostrar anuncios relevantes según tus intereses. Pueden rastrear tu comportamiento de navegación en diferentes sitios y ayudar a los anunciantes a ofrecer anuncios más personalizados.",
100
+ linkedCategory: "marketing",
101
+ },
102
+
96
103
  {
97
104
  title: "Más información",
98
105
  description:
@@ -93,6 +93,13 @@ export default {
93
93
  },
94
94
  },
95
95
 
96
+ {
97
+ title: "Cookies de marketing",
98
+ description:
99
+ "Ces cookies sont utilisés pour diffuser des publicités correspondant à vos centres d’intérêt. Ils peuvent suivre vos comportements de navigation sur différents sites et aider les annonceurs à proposer des annonces plus personnalisées.",
100
+ linkedCategory: "marketing",
101
+ },
102
+
96
103
  {
97
104
  title: "Plus d'informations",
98
105
  description:
@@ -93,6 +93,13 @@ export default {
93
93
  },
94
94
  },
95
95
 
96
+ {
97
+ title: "Cookie di marketing",
98
+ description:
99
+ "Questi cookie vengono utilizzati per offrire pubblicità pertinenti ai tuoi interessi. Possono tracciare i tuoi comportamenti di navigazione su diversi siti e aiutare gli inserzionisti a servire annunci più personalizzati.",
100
+ linkedCategory: "marketing",
101
+ },
102
+
96
103
  {
97
104
  title: "Ulteriori informazioni",
98
105
  description:
@@ -0,0 +1,78 @@
1
+ import type { CookieConsentConfig } from "@tilli-pro/cookieconsent";
2
+
3
+ import _config from "../config";
4
+ import { LABELS } from "../config/categories/labels";
5
+ import cookies from "../config/cookies";
6
+ import { run } from "../init";
7
+ import {
8
+ makeInitFn,
9
+ stripInvalidLinkedCategoriesFromTranslations,
10
+ } from "./utils";
11
+
12
+ // TODO: auto-detect detect language
13
+ const __LANGUAGE__ = "en"; // "English" ("English")
14
+
15
+ const categories: CookieConsentConfig["categories"] = {
16
+ necessary: {
17
+ enabled: true, // "necessary" category is always enabled.
18
+ readOnly: true,
19
+ services: {
20
+ /** tilliX (BRF) */
21
+ tilliX: {
22
+ label: LABELS.en.necessary.tilliX,
23
+ cookies: [...cookies.necessary.brf(__LANGUAGE__)],
24
+ },
25
+ },
26
+ },
27
+ functional: {
28
+ services: {
29
+ /** tilliX (BRF) */
30
+ tilliX: {
31
+ label: LABELS.en.functional.tilliX,
32
+ cookies: [...cookies.functional.brf(__LANGUAGE__)],
33
+ },
34
+ },
35
+ autoClear: {
36
+ cookies: [
37
+ {
38
+ name: /^(tx-theme)/, // tilliX theme (-> "light" | "dark")
39
+ },
40
+ ],
41
+ },
42
+ },
43
+ analytics: {
44
+ services: {
45
+ /** Datadog (RUM) */
46
+ datadog: {
47
+ label: LABELS.en.analytics.datadog,
48
+ cookies: [...cookies.analytics.datadog(__LANGUAGE__)],
49
+ },
50
+ },
51
+ autoClear: {
52
+ cookies: [
53
+ {
54
+ name: /^(_tilli_analytics_dd_)/, // Datadog (RUM)
55
+ },
56
+ ],
57
+ },
58
+ },
59
+ };
60
+
61
+ // TODO: DRY further w/ `./tilli-website.ts`
62
+ const language: CookieConsentConfig["language"] = {
63
+ ..._config.language,
64
+ translations: stripInvalidLinkedCategoriesFromTranslations(
65
+ _config.language.translations,
66
+ categories,
67
+ ),
68
+ };
69
+
70
+ const config: CookieConsentConfig = {
71
+ ..._config,
72
+ categories,
73
+ language,
74
+ };
75
+
76
+ // console.debug({ config }, "Initializing Cookie Consent (BRF)...");
77
+ const init = makeInitFn(run, config);
78
+ void init();