@c15t/react 0.0.1-rc.21 → 0.0.1-rc.23

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 (33) hide show
  1. package/dist/components/consent-manager-dialog/__tests__/styles.spec.cjs +23 -0
  2. package/dist/components/consent-manager-dialog/__tests__/styles.spec.js +23 -0
  3. package/dist/components/consent-manager-widget/__tests__/styles.spec.cjs +28 -0
  4. package/dist/components/consent-manager-widget/__tests__/styles.spec.js +28 -0
  5. package/dist/components/consent-manager-widget/consent-manager-widget.cjs +0 -1
  6. package/dist/components/consent-manager-widget/consent-manager-widget.d.ts.map +1 -1
  7. package/dist/components/consent-manager-widget/consent-manager-widget.js +0 -1
  8. package/dist/hooks/__tests__/use-consent-manager.test.cjs +34 -0
  9. package/dist/hooks/__tests__/use-consent-manager.test.js +34 -0
  10. package/dist/hooks/index.cjs +2 -2
  11. package/dist/providers/__tests__/provider-basic.test.cjs +127 -0
  12. package/dist/providers/__tests__/provider-basic.test.d.ts +2 -0
  13. package/dist/providers/__tests__/provider-basic.test.d.ts.map +1 -0
  14. package/dist/providers/__tests__/provider-basic.test.js +121 -0
  15. package/dist/providers/__tests__/provider-context.test.cjs +139 -0
  16. package/dist/providers/__tests__/provider-context.test.d.ts +2 -0
  17. package/dist/providers/__tests__/provider-context.test.d.ts.map +1 -0
  18. package/dist/providers/__tests__/provider-context.test.js +133 -0
  19. package/dist/providers/__tests__/provider-errors.test.cjs +98 -0
  20. package/dist/providers/__tests__/provider-errors.test.d.ts +2 -0
  21. package/dist/providers/__tests__/provider-errors.test.d.ts.map +1 -0
  22. package/dist/providers/__tests__/provider-errors.test.js +92 -0
  23. package/dist/providers/__tests__/test-helpers.cjs +171 -0
  24. package/dist/providers/__tests__/test-helpers.d.ts +6 -0
  25. package/dist/providers/__tests__/test-helpers.d.ts.map +1 -0
  26. package/dist/providers/__tests__/test-helpers.js +134 -0
  27. package/dist/providers/consent-manager-provider.cjs +62 -32
  28. package/dist/providers/consent-manager-provider.d.ts +0 -4
  29. package/dist/providers/consent-manager-provider.d.ts.map +1 -1
  30. package/dist/providers/consent-manager-provider.js +62 -32
  31. package/dist/utils/test-helpers.cjs +1 -1
  32. package/dist/utils/test-helpers.js +1 -1
  33. package/package.json +7 -6
@@ -31,11 +31,11 @@ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
31
31
  const external_c15t_namespaceObject = require("c15t");
32
32
  const external_react_namespaceObject = require("react");
33
33
  const consent_manager_context_cjs_namespaceObject = require("../context/consent-manager-context.cjs");
34
- const translations_cjs_namespaceObject = require("../utils/translations.cjs");
35
34
  const theme_context_cjs_namespaceObject = require("../context/theme-context.cjs");
36
35
  const use_color_scheme_cjs_namespaceObject = require("../hooks/use-color-scheme.cjs");
36
+ const translations_cjs_namespaceObject = require("../utils/translations.cjs");
37
37
  function ConsentManagerProvider({ children, options }) {
38
- const { store = {}, translations: translationConfig, react = {} } = options;
38
+ const { mode, backendURL, callbacks, store = {}, translations: translationConfig, react = {} } = options;
39
39
  const { initialGdprTypes, initialComplianceSettings } = store;
40
40
  const { theme, disableAnimation = false, scrollLock = false, trapFocus = true, colorScheme = 'system', noStyle = false } = react;
41
41
  const preparedTranslationConfig = (0, external_react_namespaceObject.useMemo)(()=>{
@@ -48,60 +48,78 @@ function ConsentManagerProvider({ children, options }) {
48
48
  }, [
49
49
  translationConfig
50
50
  ]);
51
- const consentManager = (0, external_react_namespaceObject.useMemo)(()=>{
52
- if (!options) throw new Error('ConsentManagerProvider requires options to be provided');
53
- const { store, translations, react, ...coreOpts } = options;
54
- return (0, external_c15t_namespaceObject.configureConsentManager)(coreOpts);
55
- }, [
56
- options
57
- ]);
58
51
  const isConsentDomain = (0, external_react_namespaceObject.useMemo)(()=>{
59
52
  if ('undefined' == typeof window) return false;
60
- const isC15tDomain = 'c15t' === options.mode && (options.backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
61
- return Boolean(isC15tDomain);
53
+ return Boolean(('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev')));
62
54
  }, [
55
+ mode,
56
+ backendURL
57
+ ]);
58
+ const consentManager = (0, external_react_namespaceObject.useMemo)(()=>{
59
+ if ('offline' === mode) return (0, external_c15t_namespaceObject.configureConsentManager)({
60
+ mode: 'offline',
61
+ callbacks,
62
+ store
63
+ });
64
+ if ('custom' === mode && 'endpointHandlers' in options) return (0, external_c15t_namespaceObject.configureConsentManager)({
65
+ mode: 'custom',
66
+ endpointHandlers: options.endpointHandlers,
67
+ callbacks,
68
+ store
69
+ });
70
+ return (0, external_c15t_namespaceObject.configureConsentManager)({
71
+ mode: 'c15t',
72
+ backendURL: backendURL || '/api/c15t',
73
+ callbacks,
74
+ store
75
+ });
76
+ }, [
77
+ mode,
78
+ backendURL,
79
+ callbacks,
80
+ store,
63
81
  options
64
82
  ]);
83
+ const storeRef = (0, external_react_namespaceObject.useRef)(null);
84
+ const prevBackendURLRef = (0, external_react_namespaceObject.useRef)(backendURL);
85
+ const prevModeRef = (0, external_react_namespaceObject.useRef)(mode);
65
86
  const consentStore = (0, external_react_namespaceObject.useMemo)(()=>{
66
87
  const storeWithTranslations = {
67
88
  ...store,
68
89
  translationConfig: preparedTranslationConfig,
69
90
  isConsentDomain
70
91
  };
71
- return (0, external_c15t_namespaceObject.createConsentManagerStore)(consentManager, storeWithTranslations);
92
+ const shouldRecreateStore = !storeRef.current || prevBackendURLRef.current !== backendURL || prevModeRef.current !== mode;
93
+ prevBackendURLRef.current = backendURL;
94
+ prevModeRef.current = mode;
95
+ if (shouldRecreateStore) storeRef.current = (0, external_c15t_namespaceObject.createConsentManagerStore)(consentManager, storeWithTranslations);
96
+ return storeRef.current;
72
97
  }, [
73
- store,
74
- preparedTranslationConfig,
75
98
  consentManager,
76
- isConsentDomain
99
+ isConsentDomain,
100
+ preparedTranslationConfig,
101
+ store,
102
+ backendURL,
103
+ mode
77
104
  ]);
78
- const [state, setState] = (0, external_react_namespaceObject.useState)(consentStore.getState());
105
+ const [state, setState] = (0, external_react_namespaceObject.useState)(()=>{
106
+ if (!consentStore) return {};
107
+ return consentStore.getState();
108
+ });
79
109
  (0, external_react_namespaceObject.useEffect)(()=>{
110
+ if (!consentStore) return;
80
111
  const { setGdprTypes, setComplianceSetting, setDetectedCountry } = consentStore.getState();
81
112
  if (initialGdprTypes) setGdprTypes(initialGdprTypes);
82
113
  if (initialComplianceSettings) for (const [region, settings] of Object.entries(initialComplianceSettings))setComplianceSetting(region, settings);
83
114
  const country = document.querySelector('meta[name="user-country"]')?.getAttribute('content') || 'US';
84
115
  setDetectedCountry(country);
85
- const unsubscribe = consentStore.subscribe((newState)=>{
86
- setState(newState);
87
- });
88
- return ()=>{
89
- unsubscribe();
90
- };
116
+ const unsubscribe = consentStore.subscribe(setState);
117
+ return unsubscribe;
91
118
  }, [
92
119
  consentStore,
93
120
  initialGdprTypes,
94
121
  initialComplianceSettings
95
122
  ]);
96
- const contextValue = (0, external_react_namespaceObject.useMemo)(()=>({
97
- state,
98
- store: consentStore,
99
- manager: consentManager
100
- }), [
101
- state,
102
- consentStore,
103
- consentManager
104
- ]);
105
123
  const themeContextValue = (0, external_react_namespaceObject.useMemo)(()=>({
106
124
  theme,
107
125
  noStyle,
@@ -116,8 +134,20 @@ function ConsentManagerProvider({ children, options }) {
116
134
  trapFocus
117
135
  ]);
118
136
  (0, use_color_scheme_cjs_namespaceObject.useColorScheme)(colorScheme);
137
+ const consentContextValue = (0, external_react_namespaceObject.useMemo)(()=>{
138
+ if (!consentStore) throw new Error('Consent store must be initialized before creating context value');
139
+ return {
140
+ state,
141
+ store: consentStore,
142
+ manager: consentManager
143
+ };
144
+ }, [
145
+ state,
146
+ consentStore,
147
+ consentManager
148
+ ]);
119
149
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(consent_manager_context_cjs_namespaceObject.ConsentStateContext.Provider, {
120
- value: contextValue,
150
+ value: consentContextValue,
121
151
  children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(theme_context_cjs_namespaceObject.GlobalThemeContext.Provider, {
122
152
  value: themeContextValue,
123
153
  children: children
@@ -1,8 +1,4 @@
1
1
  import type { ConsentManagerProviderProps } from '../types/consent-manager';
2
- /**
3
- * @packageDocumentation
4
- * Provider component for consent management functionality.
5
- */
6
2
  /**
7
3
  * Provider component for consent management functionality.
8
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"consent-manager-provider.d.ts","sourceRoot":"","sources":["../../src/providers/consent-manager-provider.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAQ5E;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,EACtC,QAAQ,EACR,OAAO,GACP,EAAE,2BAA2B,2CAmJ7B"}
1
+ {"version":3,"file":"consent-manager-provider.d.ts","sourceRoot":"","sources":["../../src/providers/consent-manager-provider.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAM5E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,EACtC,QAAQ,EACR,OAAO,GACP,EAAE,2BAA2B,2CAwM7B"}
@@ -3,11 +3,11 @@ import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/j
3
3
  import * as __WEBPACK_EXTERNAL_MODULE_c15t__ from "c15t";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE__context_consent_manager_context_js_ee8f06d2__ from "../context/consent-manager-context.js";
6
- import * as __WEBPACK_EXTERNAL_MODULE__utils_translations_js_c2629c1f__ from "../utils/translations.js";
7
6
  import * as __WEBPACK_EXTERNAL_MODULE__context_theme_context_js_fbb05439__ from "../context/theme-context.js";
8
7
  import * as __WEBPACK_EXTERNAL_MODULE__hooks_use_color_scheme_js_939e374b__ from "../hooks/use-color-scheme.js";
8
+ import * as __WEBPACK_EXTERNAL_MODULE__utils_translations_js_c2629c1f__ from "../utils/translations.js";
9
9
  function ConsentManagerProvider({ children, options }) {
10
- const { store = {}, translations: translationConfig, react = {} } = options;
10
+ const { mode, backendURL, callbacks, store = {}, translations: translationConfig, react = {} } = options;
11
11
  const { initialGdprTypes, initialComplianceSettings } = store;
12
12
  const { theme, disableAnimation = false, scrollLock = false, trapFocus = true, colorScheme = 'system', noStyle = false } = react;
13
13
  const preparedTranslationConfig = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
@@ -20,60 +20,78 @@ function ConsentManagerProvider({ children, options }) {
20
20
  }, [
21
21
  translationConfig
22
22
  ]);
23
- const consentManager = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
24
- if (!options) throw new Error('ConsentManagerProvider requires options to be provided');
25
- const { store, translations, react, ...coreOpts } = options;
26
- return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)(coreOpts);
27
- }, [
28
- options
29
- ]);
30
23
  const isConsentDomain = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
31
24
  if ('undefined' == typeof window) return false;
32
- const isC15tDomain = 'c15t' === options.mode && (options.backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
33
- return Boolean(isC15tDomain);
25
+ return Boolean(('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev')));
34
26
  }, [
27
+ mode,
28
+ backendURL
29
+ ]);
30
+ const consentManager = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
31
+ if ('offline' === mode) return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)({
32
+ mode: 'offline',
33
+ callbacks,
34
+ store
35
+ });
36
+ if ('custom' === mode && 'endpointHandlers' in options) return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)({
37
+ mode: 'custom',
38
+ endpointHandlers: options.endpointHandlers,
39
+ callbacks,
40
+ store
41
+ });
42
+ return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)({
43
+ mode: 'c15t',
44
+ backendURL: backendURL || '/api/c15t',
45
+ callbacks,
46
+ store
47
+ });
48
+ }, [
49
+ mode,
50
+ backendURL,
51
+ callbacks,
52
+ store,
35
53
  options
36
54
  ]);
55
+ const storeRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
56
+ const prevBackendURLRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(backendURL);
57
+ const prevModeRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(mode);
37
58
  const consentStore = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
38
59
  const storeWithTranslations = {
39
60
  ...store,
40
61
  translationConfig: preparedTranslationConfig,
41
62
  isConsentDomain
42
63
  };
43
- return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.createConsentManagerStore)(consentManager, storeWithTranslations);
64
+ const shouldRecreateStore = !storeRef.current || prevBackendURLRef.current !== backendURL || prevModeRef.current !== mode;
65
+ prevBackendURLRef.current = backendURL;
66
+ prevModeRef.current = mode;
67
+ if (shouldRecreateStore) storeRef.current = (0, __WEBPACK_EXTERNAL_MODULE_c15t__.createConsentManagerStore)(consentManager, storeWithTranslations);
68
+ return storeRef.current;
44
69
  }, [
45
- store,
46
- preparedTranslationConfig,
47
70
  consentManager,
48
- isConsentDomain
71
+ isConsentDomain,
72
+ preparedTranslationConfig,
73
+ store,
74
+ backendURL,
75
+ mode
49
76
  ]);
50
- const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(consentStore.getState());
77
+ const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>{
78
+ if (!consentStore) return {};
79
+ return consentStore.getState();
80
+ });
51
81
  (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
82
+ if (!consentStore) return;
52
83
  const { setGdprTypes, setComplianceSetting, setDetectedCountry } = consentStore.getState();
53
84
  if (initialGdprTypes) setGdprTypes(initialGdprTypes);
54
85
  if (initialComplianceSettings) for (const [region, settings] of Object.entries(initialComplianceSettings))setComplianceSetting(region, settings);
55
86
  const country = document.querySelector('meta[name="user-country"]')?.getAttribute('content') || 'US';
56
87
  setDetectedCountry(country);
57
- const unsubscribe = consentStore.subscribe((newState)=>{
58
- setState(newState);
59
- });
60
- return ()=>{
61
- unsubscribe();
62
- };
88
+ const unsubscribe = consentStore.subscribe(setState);
89
+ return unsubscribe;
63
90
  }, [
64
91
  consentStore,
65
92
  initialGdprTypes,
66
93
  initialComplianceSettings
67
94
  ]);
68
- const contextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
69
- state,
70
- store: consentStore,
71
- manager: consentManager
72
- }), [
73
- state,
74
- consentStore,
75
- consentManager
76
- ]);
77
95
  const themeContextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
78
96
  theme,
79
97
  noStyle,
@@ -88,8 +106,20 @@ function ConsentManagerProvider({ children, options }) {
88
106
  trapFocus
89
107
  ]);
90
108
  (0, __WEBPACK_EXTERNAL_MODULE__hooks_use_color_scheme_js_939e374b__.useColorScheme)(colorScheme);
109
+ const consentContextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
110
+ if (!consentStore) throw new Error('Consent store must be initialized before creating context value');
111
+ return {
112
+ state,
113
+ store: consentStore,
114
+ manager: consentManager
115
+ };
116
+ }, [
117
+ state,
118
+ consentStore,
119
+ consentManager
120
+ ]);
91
121
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_consent_manager_context_js_ee8f06d2__.ConsentStateContext.Provider, {
92
- value: contextValue,
122
+ value: consentContextValue,
93
123
  children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_theme_context_js_fbb05439__.GlobalThemeContext.Provider, {
94
124
  value: themeContextValue,
95
125
  children: children
@@ -41,7 +41,7 @@ async function testComponentStyles({ component, testCases, noStyle = false }) {
41
41
  },
42
42
  children: component
43
43
  }));
44
- await new Promise((resolve)=>setTimeout(resolve, 500));
44
+ await new Promise((resolve)=>setTimeout(resolve, 50));
45
45
  for (const { testId, styles } of testCases){
46
46
  const elementInContainer = container.querySelector(`[data-testid="${testId}"]`);
47
47
  const elementInBody = document.body.querySelector(`[data-testid="${testId}"]`);
@@ -12,7 +12,7 @@ async function testComponentStyles({ component, testCases, noStyle = false }) {
12
12
  },
13
13
  children: component
14
14
  }));
15
- await new Promise((resolve)=>setTimeout(resolve, 500));
15
+ await new Promise((resolve)=>setTimeout(resolve, 50));
16
16
  for (const { testId, styles } of testCases){
17
17
  const elementInContainer = container.querySelector(`[data-testid="${testId}"]`);
18
18
  const elementInBody = document.body.querySelector(`[data-testid="${testId}"]`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c15t/react",
3
- "version": "0.0.1-rc.21",
3
+ "version": "0.0.1-rc.23",
4
4
  "license": "GPL-3.0-only",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -65,14 +65,16 @@
65
65
  "motion": "^12.6.5",
66
66
  "tailwind-variants": "^1.0.0",
67
67
  "zustand": "^5.0.3",
68
- "c15t": "0.0.1-rc.21"
68
+ "c15t": "0.0.1-rc.23"
69
69
  },
70
70
  "devDependencies": {
71
- "@c15t/typescript-config": "0.0.1-beta.1"
71
+ "@c15t/backend": "0.0.1-rc.23",
72
+ "@c15t/typescript-config": "0.0.1-beta.1",
73
+ "@c15t/vitest-config": "0.0.1-rc.23"
72
74
  },
73
75
  "peerDependencies": {
74
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
75
- "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
76
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc",
77
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
76
78
  },
77
79
  "publishConfig": {
78
80
  "access": "public"
@@ -84,7 +86,6 @@
84
86
  "fmt": "pnpm biome format --write . && biome check --formatter-enabled=false --linter-enabled=false --organize-imports-enabled=true --write",
85
87
  "lint": "pnpm biome lint ./src",
86
88
  "test": "vitest run",
87
- "test:coverage": "vitest run --coverage",
88
89
  "test:watch": "vitest"
89
90
  }
90
91
  }