@redacto.io/consent-sdk-react 0.0.1

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.
@@ -0,0 +1,36 @@
1
+ import { useState, useEffect } from "react";
2
+
3
+ export const useMediaQuery = (query: string): boolean => {
4
+ const getMatches = () =>
5
+ typeof window !== "undefined" ? window.matchMedia(query).matches : false;
6
+ const [matches, setMatches] = useState<boolean>(getMatches);
7
+
8
+ useEffect(() => {
9
+ if (typeof window === "undefined") return;
10
+ const media = window.matchMedia(query);
11
+
12
+ // Create event listener
13
+ const listener = (e: MediaQueryListEvent) => {
14
+ setMatches(e.matches);
15
+ };
16
+
17
+ // Add listener (fallback for legacy browsers)
18
+ if (media.addEventListener) {
19
+ media.addEventListener("change", listener);
20
+ } else {
21
+ // @ts-ignore – deprecated fallback
22
+ media.addListener(listener);
23
+ }
24
+
25
+ // Clean up
26
+ return () => {
27
+ if (media.removeEventListener) {
28
+ media.removeEventListener("change", listener);
29
+ } else {
30
+ media.removeListener(listener);
31
+ }
32
+ };
33
+ }, [query]);
34
+
35
+ return matches;
36
+ };
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as RedactoNoticeConsent } from "./RedactoNoticeConsent";
@@ -0,0 +1,4 @@
1
+ declare module "*.module.css" {
2
+ const classes: { [key: string]: string };
3
+ export default classes;
4
+ }
@@ -0,0 +1,19 @@
1
+ declare module "*.png" {
2
+ const content: string;
3
+ export default content;
4
+ }
5
+
6
+ declare module "*.jpg" {
7
+ const content: string;
8
+ export default content;
9
+ }
10
+
11
+ declare module "*.jpeg" {
12
+ const content: string;
13
+ export default content;
14
+ }
15
+
16
+ declare module "*.svg" {
17
+ const content: string;
18
+ export default content;
19
+ }
package/tests/mocks.ts ADDED
@@ -0,0 +1,114 @@
1
+ import type { ConsentContent } from "../src/RedactoNoticeConsent/api/types";
2
+ import { vi } from "vitest";
3
+
4
+ export const mockConsentContent: ConsentContent = {
5
+ code: 200,
6
+ status: "success",
7
+ detail: {
8
+ uuid: "notice-123",
9
+ name: "Privacy Notice",
10
+ organisation_uuid: "org-123",
11
+ workspace_uuid: "workspace-123",
12
+ collection_point_uuids: [],
13
+ collection_points: [],
14
+ active_config: {
15
+ uuid: "config-123",
16
+ notice_uuid: "notice-123",
17
+ organisation_uuid: "org-123",
18
+ workspace_uuid: "workspace-123",
19
+ version: 1,
20
+ status: "active",
21
+ notice_text: "We care about your privacy.",
22
+ additional_text: "",
23
+ confirm_button_text: "Accept",
24
+ decline_button_text: "Decline",
25
+ logo_url: "https://example.com/logo.png",
26
+ privacy_policy_url: "https://example.com/privacy",
27
+ sub_processors_url: "https://example.com/vendors",
28
+ primary_color: "#4f87ff",
29
+ secondary_color: "#ffffff",
30
+ font_preference: "Arial",
31
+ privacy_policy_prefix_text: "",
32
+ vendor_list_prefix_text: "",
33
+ privacy_policy_anchor_text: "Privacy Policy",
34
+ vendors_list_anchor_text: "Vendors List",
35
+ purpose_section_heading: "Manage Consent",
36
+ created_at: "2023-01-01T00:00:00Z",
37
+ updated_at: "2023-01-01T00:00:00Z",
38
+ deployed_at: "2023-01-01T00:00:00Z",
39
+ supported_languages_and_translations: {
40
+ es: {
41
+ notice_text: "Nos importa tu privacidad.",
42
+ additional_text: "",
43
+ privacy_policy_prefix_text: "",
44
+ vendor_list_prefix_text: "",
45
+ privacy_policy_anchor_text: "Política de Privacidad",
46
+ vendors_list_anchor_text: "Lista de Proveedores",
47
+ confirm_button_text: "Aceptar",
48
+ decline_button_text: "Rechazar",
49
+ purpose_section_heading: "Gestionar Consentimiento",
50
+ purposes: {
51
+ "purpose-1": "Marketing",
52
+ "purpose-1-description": "Usamos datos para marketing.",
53
+ },
54
+ data_elements: {
55
+ "element-1": "Email",
56
+ "element-2": "Phone",
57
+ },
58
+ },
59
+ },
60
+ purposes: [
61
+ {
62
+ uuid: "purpose-1",
63
+ name: "Marketing",
64
+ description: "We use data for marketing purposes.",
65
+ industries: "Marketing",
66
+ data_elements: [
67
+ {
68
+ uuid: "element-1",
69
+ name: "Email",
70
+ required: false,
71
+ description: null,
72
+ industries: null,
73
+ enabled: true,
74
+ },
75
+ {
76
+ uuid: "element-2",
77
+ name: "Phone",
78
+ required: true,
79
+ description: null,
80
+ industries: null,
81
+ enabled: true,
82
+ },
83
+ ],
84
+ },
85
+ ],
86
+ default_language: "en",
87
+ },
88
+ created_at: "2023-01-01T00:00:00Z",
89
+ updated_at: "2023-01-01T00:00:00Z",
90
+ },
91
+ } as const;
92
+
93
+ export const defaultProps = {
94
+ noticeId: "notice-123",
95
+ accessToken: "mock-token",
96
+ refreshToken: "mock-refresh-token",
97
+ language: "en",
98
+ blockUI: false,
99
+ onAccept: vi.fn(),
100
+ onDecline: vi.fn(),
101
+ onError: vi.fn(),
102
+ settings: {
103
+ borderRadius: "8px",
104
+ backgroundColor: "#ffffff",
105
+ headingColor: "#101828",
106
+ textColor: "#344054",
107
+ button: {
108
+ accept: { backgroundColor: "#4f87ff", textColor: "#ffffff" },
109
+ decline: { backgroundColor: "#ffffff", textColor: "#000000" },
110
+ language: { backgroundColor: "#ffffff", textColor: "#344054" },
111
+ },
112
+ link: { color: "#4f87ff" },
113
+ },
114
+ } as const;
package/tests/setup.ts ADDED
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom";
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2019",
4
+ "module": "ESNext",
5
+ "declaration": true,
6
+ "strict": true,
7
+ "jsx": "react-jsx",
8
+ "moduleResolution": "node",
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "plugins": [
12
+ {
13
+ "name": "typescript-plugin-css-modules"
14
+ }
15
+ ]
16
+ },
17
+ "include": ["src"]
18
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: "src/index.ts",
6
+ },
7
+ format: ["esm", "cjs"],
8
+ dts: true,
9
+ external: ["react", "react-dom", "jwt-decode"],
10
+ clean: true,
11
+ loader: {
12
+ ".png": "dataurl",
13
+ ".jpg": "dataurl",
14
+ ".svg": "dataurl",
15
+ },
16
+ });
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: "jsdom",
6
+ globals: true,
7
+ setupFiles: ["./tests/setup.ts"],
8
+ coverage: {
9
+ provider: "v8",
10
+ reporter: ["text", "html"],
11
+ reportsDirectory: "./coverage",
12
+ clean: false, // Prevent cleaning coverage folder before tests
13
+ cleanOnRerun: false, // Prevent cleaning coverage folder after tests
14
+ },
15
+ },
16
+ });