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

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 (32) 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/hooks/index.js +17 -1
  12. package/dist/providers/__tests__/provider-basic.test.cjs +127 -0
  13. package/dist/providers/__tests__/provider-basic.test.d.ts +2 -0
  14. package/dist/providers/__tests__/provider-basic.test.d.ts.map +1 -0
  15. package/dist/providers/__tests__/provider-basic.test.js +121 -0
  16. package/dist/providers/__tests__/provider-context.test.cjs +139 -0
  17. package/dist/providers/__tests__/provider-context.test.d.ts +2 -0
  18. package/dist/providers/__tests__/provider-context.test.d.ts.map +1 -0
  19. package/dist/providers/__tests__/provider-context.test.js +133 -0
  20. package/dist/providers/__tests__/provider-errors.test.cjs +98 -0
  21. package/dist/providers/__tests__/provider-errors.test.d.ts +2 -0
  22. package/dist/providers/__tests__/provider-errors.test.d.ts.map +1 -0
  23. package/dist/providers/__tests__/provider-errors.test.js +92 -0
  24. package/dist/providers/__tests__/test-helpers.cjs +171 -0
  25. package/dist/providers/__tests__/test-helpers.d.ts +6 -0
  26. package/dist/providers/__tests__/test-helpers.d.ts.map +1 -0
  27. package/dist/providers/__tests__/test-helpers.js +134 -0
  28. package/dist/providers/consent-manager-provider.cjs +41 -10
  29. package/dist/providers/consent-manager-provider.d.ts +0 -4
  30. package/dist/providers/consent-manager-provider.d.ts.map +1 -1
  31. package/dist/providers/consent-manager-provider.js +41 -10
  32. package/package.json +7 -6
@@ -0,0 +1,134 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_vitest__ from "vitest";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__index_js_cbfda0f6__ from "../../index.js";
4
+ function setupMocks() {
5
+ const mockFetch = __WEBPACK_EXTERNAL_MODULE_vitest__.vi.fn();
6
+ window.fetch = mockFetch;
7
+ const mockConfigureConsentManager = __WEBPACK_EXTERNAL_MODULE_vitest__.vi.fn();
8
+ const fetchCallMap = new Map();
9
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.beforeEach)(()=>{
10
+ fetchCallMap.clear();
11
+ });
12
+ __WEBPACK_EXTERNAL_MODULE_vitest__.vi.mock('c15t', async ()=>{
13
+ const originalModule = await __WEBPACK_EXTERNAL_MODULE_vitest__.vi.importActual('c15t');
14
+ return {
15
+ ...originalModule,
16
+ configureConsentManager: (options)=>{
17
+ mockConfigureConsentManager(options);
18
+ const backendURL = options.backendURL || '';
19
+ if ('c15t' === options.mode) return {
20
+ getCallbacks: ()=>options.callbacks,
21
+ showConsentBanner: async ()=>{
22
+ if (!fetchCallMap.has(backendURL)) {
23
+ mockFetch(`${backendURL}/show-consent-banner`, {
24
+ headers: {
25
+ 'Content-Type': 'application/json'
26
+ }
27
+ });
28
+ fetchCallMap.set(backendURL, true);
29
+ }
30
+ return {
31
+ ok: true,
32
+ data: {
33
+ showConsentBanner: true
34
+ },
35
+ error: null,
36
+ response: null
37
+ };
38
+ },
39
+ setConsent: async ()=>({
40
+ ok: true,
41
+ data: {
42
+ success: true
43
+ },
44
+ error: null,
45
+ response: null
46
+ }),
47
+ verifyConsent: async ()=>({
48
+ ok: true,
49
+ data: {
50
+ valid: true
51
+ },
52
+ error: null,
53
+ response: null
54
+ })
55
+ };
56
+ if ('offline' === options.mode) return {
57
+ getCallbacks: ()=>options.callbacks,
58
+ showConsentBanner: async ()=>({
59
+ ok: true,
60
+ data: {
61
+ showConsentBanner: true
62
+ },
63
+ error: null,
64
+ response: null
65
+ }),
66
+ setConsent: async ()=>({
67
+ ok: true,
68
+ data: {
69
+ success: true
70
+ },
71
+ error: null,
72
+ response: null
73
+ }),
74
+ verifyConsent: async ()=>({
75
+ ok: true,
76
+ data: {
77
+ valid: true
78
+ },
79
+ error: null,
80
+ response: null
81
+ })
82
+ };
83
+ if ('custom' === options.mode && 'endpointHandlers' in options) {
84
+ const handlers = options.endpointHandlers;
85
+ return {
86
+ getCallbacks: ()=>options.callbacks,
87
+ showConsentBanner: async ()=>handlers.showConsentBanner({}),
88
+ setConsent: async (data)=>handlers.setConsent(data),
89
+ verifyConsent: async (data)=>handlers.verifyConsent(data)
90
+ };
91
+ }
92
+ return {
93
+ getCallbacks: ()=>options.callbacks,
94
+ showConsentBanner: async ()=>({
95
+ ok: true,
96
+ data: {
97
+ showConsentBanner: true
98
+ },
99
+ error: null,
100
+ response: null
101
+ }),
102
+ setConsent: async ()=>({
103
+ ok: true,
104
+ data: {
105
+ success: true
106
+ },
107
+ error: null,
108
+ response: null
109
+ }),
110
+ verifyConsent: async ()=>({
111
+ ok: true,
112
+ data: {
113
+ valid: true
114
+ },
115
+ error: null,
116
+ response: null
117
+ })
118
+ };
119
+ }
120
+ };
121
+ });
122
+ return {
123
+ mockFetch,
124
+ mockConfigureConsentManager
125
+ };
126
+ }
127
+ const TestConsumer = ()=>{
128
+ const consentManager = (0, __WEBPACK_EXTERNAL_MODULE__index_js_cbfda0f6__.useConsentManager)();
129
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
130
+ "data-testid": "consumer",
131
+ children: consentManager.showPopup ? 'Show' : 'Hide'
132
+ });
133
+ };
134
+ export { TestConsumer, setupMocks };
@@ -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)(()=>{
@@ -49,18 +49,37 @@ function ConsentManagerProvider({ children, options }) {
49
49
  translationConfig
50
50
  ]);
51
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);
52
+ if ('offline' === mode) return (0, external_c15t_namespaceObject.configureConsentManager)({
53
+ mode: 'offline',
54
+ callbacks,
55
+ store
56
+ });
57
+ if ('custom' === mode && 'endpointHandlers' in options) return (0, external_c15t_namespaceObject.configureConsentManager)({
58
+ mode: 'custom',
59
+ endpointHandlers: options.endpointHandlers,
60
+ callbacks,
61
+ store
62
+ });
63
+ return (0, external_c15t_namespaceObject.configureConsentManager)({
64
+ mode: 'c15t',
65
+ backendURL: backendURL || '/api/c15t',
66
+ callbacks,
67
+ store
68
+ });
55
69
  }, [
70
+ mode,
71
+ backendURL,
72
+ callbacks,
73
+ store,
56
74
  options
57
75
  ]);
58
76
  const isConsentDomain = (0, external_react_namespaceObject.useMemo)(()=>{
59
77
  if ('undefined' == typeof window) return false;
60
- const isC15tDomain = 'c15t' === options.mode && (options.backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
78
+ const isC15tDomain = ('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
61
79
  return Boolean(isC15tDomain);
62
80
  }, [
63
- options
81
+ mode,
82
+ backendURL
64
83
  ]);
65
84
  const consentStore = (0, external_react_namespaceObject.useMemo)(()=>{
66
85
  const storeWithTranslations = {
@@ -93,14 +112,27 @@ function ConsentManagerProvider({ children, options }) {
93
112
  initialGdprTypes,
94
113
  initialComplianceSettings
95
114
  ]);
115
+ (0, use_color_scheme_cjs_namespaceObject.useColorScheme)(colorScheme);
96
116
  const contextValue = (0, external_react_namespaceObject.useMemo)(()=>({
97
117
  state,
98
118
  store: consentStore,
99
- manager: consentManager
119
+ manager: consentManager,
120
+ theme,
121
+ disableAnimation,
122
+ scrollLock,
123
+ trapFocus,
124
+ colorScheme,
125
+ noStyle
100
126
  }), [
101
127
  state,
102
128
  consentStore,
103
- consentManager
129
+ consentManager,
130
+ theme,
131
+ disableAnimation,
132
+ scrollLock,
133
+ trapFocus,
134
+ colorScheme,
135
+ noStyle
104
136
  ]);
105
137
  const themeContextValue = (0, external_react_namespaceObject.useMemo)(()=>({
106
138
  theme,
@@ -115,7 +147,6 @@ function ConsentManagerProvider({ children, options }) {
115
147
  scrollLock,
116
148
  trapFocus
117
149
  ]);
118
- (0, use_color_scheme_cjs_namespaceObject.useColorScheme)(colorScheme);
119
150
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(consent_manager_context_cjs_namespaceObject.ConsentStateContext.Provider, {
120
151
  value: contextValue,
121
152
  children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(theme_context_cjs_namespaceObject.GlobalThemeContext.Provider, {
@@ -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":"AAaA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAM5E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,EACtC,QAAQ,EACR,OAAO,GACP,EAAE,2BAA2B,2CAwL7B"}
@@ -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)(()=>{
@@ -21,18 +21,37 @@ function ConsentManagerProvider({ children, options }) {
21
21
  translationConfig
22
22
  ]);
23
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);
24
+ if ('offline' === mode) return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)({
25
+ mode: 'offline',
26
+ callbacks,
27
+ store
28
+ });
29
+ if ('custom' === mode && 'endpointHandlers' in options) return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)({
30
+ mode: 'custom',
31
+ endpointHandlers: options.endpointHandlers,
32
+ callbacks,
33
+ store
34
+ });
35
+ return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)({
36
+ mode: 'c15t',
37
+ backendURL: backendURL || '/api/c15t',
38
+ callbacks,
39
+ store
40
+ });
27
41
  }, [
42
+ mode,
43
+ backendURL,
44
+ callbacks,
45
+ store,
28
46
  options
29
47
  ]);
30
48
  const isConsentDomain = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
31
49
  if ('undefined' == typeof window) return false;
32
- const isC15tDomain = 'c15t' === options.mode && (options.backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
50
+ const isC15tDomain = ('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
33
51
  return Boolean(isC15tDomain);
34
52
  }, [
35
- options
53
+ mode,
54
+ backendURL
36
55
  ]);
37
56
  const consentStore = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
38
57
  const storeWithTranslations = {
@@ -65,14 +84,27 @@ function ConsentManagerProvider({ children, options }) {
65
84
  initialGdprTypes,
66
85
  initialComplianceSettings
67
86
  ]);
87
+ (0, __WEBPACK_EXTERNAL_MODULE__hooks_use_color_scheme_js_939e374b__.useColorScheme)(colorScheme);
68
88
  const contextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
69
89
  state,
70
90
  store: consentStore,
71
- manager: consentManager
91
+ manager: consentManager,
92
+ theme,
93
+ disableAnimation,
94
+ scrollLock,
95
+ trapFocus,
96
+ colorScheme,
97
+ noStyle
72
98
  }), [
73
99
  state,
74
100
  consentStore,
75
- consentManager
101
+ consentManager,
102
+ theme,
103
+ disableAnimation,
104
+ scrollLock,
105
+ trapFocus,
106
+ colorScheme,
107
+ noStyle
76
108
  ]);
77
109
  const themeContextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
78
110
  theme,
@@ -87,7 +119,6 @@ function ConsentManagerProvider({ children, options }) {
87
119
  scrollLock,
88
120
  trapFocus
89
121
  ]);
90
- (0, __WEBPACK_EXTERNAL_MODULE__hooks_use_color_scheme_js_939e374b__.useColorScheme)(colorScheme);
91
122
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_consent_manager_context_js_ee8f06d2__.ConsentStateContext.Provider, {
92
123
  value: contextValue,
93
124
  children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_theme_context_js_fbb05439__.GlobalThemeContext.Provider, {
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.22",
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.22"
69
69
  },
70
70
  "devDependencies": {
71
- "@c15t/typescript-config": "0.0.1-beta.1"
71
+ "@c15t/vitest-config": "0.0.1-rc.22",
72
+ "@c15t/typescript-config": "0.0.1-beta.1",
73
+ "@c15t/backend": "0.0.1-rc.22"
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
  }