react-lgpd-consent 0.1.13 → 0.2.0

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.
@@ -11,7 +11,7 @@ import Typography2 from "@mui/material/Typography";
11
11
  import { useEffect as useEffect2, useState as useState2 } from "react";
12
12
 
13
13
  // src/context/ConsentContext.tsx
14
- import * as React from "react";
14
+ import * as React2 from "react";
15
15
  import { ThemeProvider } from "@mui/material/styles";
16
16
 
17
17
  // src/utils/cookieUtils.ts
@@ -117,18 +117,98 @@ var defaultConsentTheme = createTheme({
117
117
  }
118
118
  });
119
119
 
120
+ // src/context/CategoriesContext.tsx
121
+ import * as React from "react";
122
+ import { jsx } from "react/jsx-runtime";
123
+ var CategoriesCtx = React.createContext([]);
124
+ function CategoriesProvider({
125
+ categories,
126
+ children
127
+ }) {
128
+ const value = React.useMemo(() => categories || [], [categories]);
129
+ return /* @__PURE__ */ jsx(CategoriesCtx.Provider, { value, children });
130
+ }
131
+ function useCustomCategories() {
132
+ return React.useContext(CategoriesCtx);
133
+ }
134
+ function useAllCategories() {
135
+ const customCategories = useCustomCategories();
136
+ return React.useMemo(() => {
137
+ const defaultCategories = [
138
+ {
139
+ id: "necessary",
140
+ name: "Cookies Necess\xE1rios",
141
+ description: "Essenciais para o funcionamento b\xE1sico do site. Incluem cookies de sess\xE3o, autentica\xE7\xE3o e seguran\xE7a.",
142
+ essential: true,
143
+ cookies: ["PHPSESSID", "JSESSIONID", "cookieConsent", "csrf_token"]
144
+ },
145
+ {
146
+ id: "analytics",
147
+ name: "Analytics e Estat\xEDsticas",
148
+ description: "Permitem medir audi\xEAncia e desempenho, gerando estat\xEDsticas an\xF4nimas de uso.",
149
+ essential: false,
150
+ cookies: ["_ga", "_ga_*", "_gid", "_gat", "gtag"]
151
+ },
152
+ {
153
+ id: "functional",
154
+ name: "Cookies Funcionais",
155
+ description: "Melhoram a experi\xEAncia do usu\xE1rio, lembrando prefer\xEAncias e configura\xE7\xF5es.",
156
+ essential: false,
157
+ cookies: ["language", "theme", "timezone", "preferences"]
158
+ },
159
+ {
160
+ id: "marketing",
161
+ name: "Marketing e Publicidade",
162
+ description: "Utilizados para publicidade direcionada e medi\xE7\xE3o de campanhas publicit\xE1rias.",
163
+ essential: false,
164
+ cookies: ["_fbp", "fr", "tr", "ads_*", "doubleclick"]
165
+ },
166
+ {
167
+ id: "social",
168
+ name: "Redes Sociais",
169
+ description: "Permitem compartilhamento e integra\xE7\xE3o com redes sociais como Facebook, YouTube, etc.",
170
+ essential: false,
171
+ cookies: ["__Secure-*", "sb", "datr", "c_user", "social_*"]
172
+ },
173
+ {
174
+ id: "personalization",
175
+ name: "Personaliza\xE7\xE3o",
176
+ description: "Adaptam o conte\xFAdo e interface \xE0s prefer\xEAncias individuais do usu\xE1rio.",
177
+ essential: false,
178
+ cookies: ["personalization_*", "content_*", "layout_*"]
179
+ }
180
+ ];
181
+ return [...defaultCategories, ...customCategories];
182
+ }, [customCategories]);
183
+ }
184
+
120
185
  // src/context/ConsentContext.tsx
121
- import { jsx, jsxs } from "react/jsx-runtime";
122
- var PreferencesModal = React.lazy(
123
- () => import("./PreferencesModal-2V2W3262.js").then((m) => ({
186
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
187
+ var PreferencesModal = React2.lazy(
188
+ () => import("./PreferencesModal-QQOOLRDY.js").then((m) => ({
124
189
  default: m.PreferencesModal
125
190
  }))
126
191
  );
127
192
  var DEFAULT_PREFERENCES = {
193
+ necessary: true,
194
+ // Sempre ativo (essencial)
128
195
  analytics: false,
129
- marketing: false
196
+ functional: false,
197
+ marketing: false,
198
+ social: false,
199
+ personalization: false
130
200
  };
201
+ function createInitialPreferences(customCategories) {
202
+ const prefs = { ...DEFAULT_PREFERENCES };
203
+ if (customCategories) {
204
+ customCategories.forEach((category) => {
205
+ prefs[category.id] = category.essential === true;
206
+ });
207
+ }
208
+ return prefs;
209
+ }
131
210
  var DEFAULT_TEXTS = {
211
+ // Textos básicos
132
212
  bannerMessage: "Utilizamos cookies para melhorar sua experi\xEAncia.",
133
213
  acceptAll: "Aceitar todos",
134
214
  declineAll: "Recusar",
@@ -137,22 +217,53 @@ var DEFAULT_TEXTS = {
137
217
  modalTitle: "Prefer\xEAncias de Cookies",
138
218
  modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
139
219
  save: "Salvar prefer\xEAncias",
140
- necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)"
220
+ necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)",
221
+ // Textos ANPD expandidos (opcionais)
222
+ controllerInfo: void 0,
223
+ // Exibido se definido
224
+ dataTypes: void 0,
225
+ // Exibido se definido
226
+ thirdPartySharing: void 0,
227
+ // Exibido se definido
228
+ userRights: void 0,
229
+ // Exibido se definido
230
+ contactInfo: void 0,
231
+ // Exibido se definido
232
+ retentionPeriod: void 0,
233
+ // Exibido se definido
234
+ lawfulBasis: void 0,
235
+ // Exibido se definido
236
+ transferCountries: void 0
237
+ // Exibido se definido
141
238
  };
142
239
  function reducer(state, action) {
143
240
  switch (action.type) {
144
- case "ACCEPT_ALL":
241
+ case "ACCEPT_ALL": {
242
+ const prefs = createInitialPreferences(action.customCategories);
243
+ Object.keys(prefs).forEach((key) => {
244
+ prefs[key] = true;
245
+ });
145
246
  return {
146
247
  consented: true,
147
- preferences: { analytics: true, marketing: true },
248
+ preferences: prefs,
148
249
  isModalOpen: false
149
250
  };
150
- case "REJECT_ALL":
251
+ }
252
+ case "REJECT_ALL": {
253
+ const prefs = createInitialPreferences(action.customCategories);
254
+ if (action.customCategories) {
255
+ action.customCategories.forEach((category) => {
256
+ if (category.essential) {
257
+ prefs[category.id] = true;
258
+ }
259
+ });
260
+ }
151
261
  return {
152
262
  consented: true,
153
- preferences: { analytics: false, marketing: false },
263
+ preferences: prefs,
154
264
  isModalOpen: false
155
265
  };
266
+ }
156
267
  case "SET_CATEGORY":
157
268
  return {
158
269
  ...state,
@@ -173,26 +284,29 @@ function reducer(state, action) {
173
284
  case "CLOSE_MODAL":
174
285
  return { ...state, isModalOpen: false, consented: true };
175
286
  // houve interação
176
- case "RESET":
287
+ case "RESET": {
177
288
  return {
178
289
  consented: false,
179
- preferences: { ...DEFAULT_PREFERENCES },
290
+ preferences: createInitialPreferences(action.customCategories),
180
291
  isModalOpen: false
181
292
  };
293
+ }
182
294
  case "HYDRATE":
183
295
  return { ...action.state };
184
296
  default:
185
297
  return state;
186
298
  }
187
299
  }
188
- var StateCtx = React.createContext(null);
189
- var ActionsCtx = React.createContext(null);
190
- var TextsCtx = React.createContext(DEFAULT_TEXTS);
191
- var HydrationCtx = React.createContext(false);
300
+ var StateCtx = React2.createContext(null);
301
+ var ActionsCtx = React2.createContext(null);
302
+ var TextsCtx = React2.createContext(DEFAULT_TEXTS);
303
+ var HydrationCtx = React2.createContext(false);
192
304
  function ConsentProvider({
193
305
  initialState,
194
306
  texts: textsProp,
195
307
  theme,
308
+ customCategories,
309
+ scriptIntegrations,
196
310
  PreferencesModalComponent,
197
311
  preferencesModalProps = {},
198
312
  disableAutomaticModal = false,
@@ -202,29 +316,29 @@ function ConsentProvider({
202
316
  cookie: cookieOpts,
203
317
  children
204
318
  }) {
205
- const texts = React.useMemo(
319
+ const texts = React2.useMemo(
206
320
  () => ({ ...DEFAULT_TEXTS, ...textsProp ?? {} }),
207
321
  [textsProp]
208
322
  );
209
- const cookie = React.useMemo(
323
+ const cookie = React2.useMemo(
210
324
  () => ({ ...DEFAULT_COOKIE_OPTS, ...cookieOpts ?? {} }),
211
325
  [cookieOpts]
212
326
  );
213
- const appliedTheme = React.useMemo(
327
+ const appliedTheme = React2.useMemo(
214
328
  () => theme || defaultConsentTheme,
215
329
  [theme]
216
330
  );
217
- const boot = React.useMemo(() => {
331
+ const boot = React2.useMemo(() => {
218
332
  if (initialState) return { ...initialState, isModalOpen: false };
219
333
  return {
220
334
  consented: false,
221
- preferences: { ...DEFAULT_PREFERENCES },
335
+ preferences: createInitialPreferences(customCategories),
222
336
  isModalOpen: false
223
337
  };
224
- }, [initialState]);
225
- const [state, dispatch] = React.useReducer(reducer, boot);
226
- const [isHydrated, setIsHydrated] = React.useState(false);
227
- React.useEffect(() => {
338
+ }, [initialState, customCategories]);
339
+ const [state, dispatch] = React2.useReducer(reducer, boot);
340
+ const [isHydrated, setIsHydrated] = React2.useState(false);
341
+ React2.useEffect(() => {
228
342
  if (!initialState) {
229
343
  const saved = readConsentCookie(cookie.name);
230
344
  if (saved?.consented) {
@@ -234,33 +348,33 @@ function ConsentProvider({
234
348
  }
235
349
  setIsHydrated(true);
236
350
  }, [cookie.name, initialState]);
237
- React.useEffect(() => {
351
+ React2.useEffect(() => {
238
352
  if (state.consented) writeConsentCookie(state, cookie);
239
353
  }, [state, cookie]);
240
- const prevConsented = React.useRef(state.consented);
241
- React.useEffect(() => {
354
+ const prevConsented = React2.useRef(state.consented);
355
+ React2.useEffect(() => {
242
356
  if (!prevConsented.current && state.consented && onConsentGiven) {
243
357
  setTimeout(() => onConsentGiven(state), 150);
244
358
  }
245
359
  prevConsented.current = state.consented;
246
360
  }, [state, onConsentGiven]);
247
- const prevPrefs = React.useRef(state.preferences);
248
- React.useEffect(() => {
361
+ const prevPrefs = React2.useRef(state.preferences);
362
+ React2.useEffect(() => {
249
363
  if (state.consented && onPreferencesSaved && prevPrefs.current !== state.preferences) {
250
364
  setTimeout(() => onPreferencesSaved(state.preferences), 150);
251
365
  prevPrefs.current = state.preferences;
252
366
  }
253
367
  }, [state, onPreferencesSaved]);
254
- const api = React.useMemo(() => {
255
- const acceptAll = () => dispatch({ type: "ACCEPT_ALL" });
256
- const rejectAll = () => dispatch({ type: "REJECT_ALL" });
368
+ const api = React2.useMemo(() => {
369
+ const acceptAll = () => dispatch({ type: "ACCEPT_ALL", customCategories });
370
+ const rejectAll = () => dispatch({ type: "REJECT_ALL", customCategories });
257
371
  const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
258
372
  const setPreferences = (preferences) => dispatch({ type: "SET_PREFERENCES", preferences });
259
373
  const openPreferences = () => dispatch({ type: "OPEN_MODAL" });
260
374
  const closePreferences = () => dispatch({ type: "CLOSE_MODAL" });
261
375
  const resetConsent = () => {
262
376
  removeConsentCookie(cookie);
263
- dispatch({ type: "RESET" });
377
+ dispatch({ type: "RESET", customCategories });
264
378
  };
265
379
  return {
266
380
  consented: !!state.consented,
@@ -274,30 +388,30 @@ function ConsentProvider({
274
388
  closePreferences,
275
389
  resetConsent
276
390
  };
277
- }, [state, cookie]);
278
- return /* @__PURE__ */ jsx(ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ jsx(StateCtx.Provider, { value: state, children: /* @__PURE__ */ jsx(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ jsx(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ jsxs(HydrationCtx.Provider, { value: isHydrated, children: [
391
+ }, [state, cookie, customCategories]);
392
+ return /* @__PURE__ */ jsx2(ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ jsx2(StateCtx.Provider, { value: state, children: /* @__PURE__ */ jsx2(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ jsx2(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ jsx2(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ jsxs(CategoriesProvider, { categories: customCategories, children: [
279
393
  children,
280
- !disableAutomaticModal && /* @__PURE__ */ jsx(React.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ jsx(PreferencesModalComponent, { ...preferencesModalProps }) : /* @__PURE__ */ jsx(PreferencesModal, { hideBranding }) })
281
- ] }) }) }) }) });
394
+ !disableAutomaticModal && /* @__PURE__ */ jsx2(React2.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ jsx2(PreferencesModalComponent, { ...preferencesModalProps }) : /* @__PURE__ */ jsx2(PreferencesModal, { hideBranding }) })
395
+ ] }) }) }) }) }) });
282
396
  }
283
397
  function useConsentStateInternal() {
284
- const ctx = React.useContext(StateCtx);
398
+ const ctx = React2.useContext(StateCtx);
285
399
  if (!ctx)
286
400
  throw new Error("useConsentState must be used within ConsentProvider");
287
401
  return ctx;
288
402
  }
289
403
  function useConsentActionsInternal() {
290
- const ctx = React.useContext(ActionsCtx);
404
+ const ctx = React2.useContext(ActionsCtx);
291
405
  if (!ctx)
292
406
  throw new Error("useConsentActions must be used within ConsentProvider");
293
407
  return ctx;
294
408
  }
295
409
  function useConsentTextsInternal() {
296
- const ctx = React.useContext(TextsCtx);
410
+ const ctx = React2.useContext(TextsCtx);
297
411
  return ctx;
298
412
  }
299
413
  function useConsentHydrationInternal() {
300
- return React.useContext(HydrationCtx);
414
+ return React2.useContext(HydrationCtx);
301
415
  }
302
416
 
303
417
  // src/hooks/useConsent.ts
@@ -327,7 +441,7 @@ function useConsentHydration() {
327
441
  // src/components/Branding.tsx
328
442
  import Link from "@mui/material/Link";
329
443
  import Typography from "@mui/material/Typography";
330
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
444
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
331
445
  var brandingStyles = {
332
446
  banner: {
333
447
  fontSize: "0.65rem",
@@ -365,7 +479,7 @@ function Branding({ variant, hidden = false }) {
365
479
  children: [
366
480
  "fornecido por",
367
481
  " ",
368
- /* @__PURE__ */ jsx2(
482
+ /* @__PURE__ */ jsx3(
369
483
  Link,
370
484
  {
371
485
  href: "https://www.ledipo.eti.br",
@@ -384,7 +498,7 @@ function Branding({ variant, hidden = false }) {
384
498
  }
385
499
 
386
500
  // src/components/PreferencesModal.tsx
387
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
501
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
388
502
  function PreferencesModal2({
389
503
  DialogProps: DialogProps2,
390
504
  hideBranding = false
@@ -413,14 +527,14 @@ function PreferencesModal2({
413
527
  onClose: handleCancel,
414
528
  ...DialogProps2,
415
529
  children: [
416
- /* @__PURE__ */ jsx3(DialogTitle, { id: "cookie-pref-title", children: texts.modalTitle }),
530
+ /* @__PURE__ */ jsx4(DialogTitle, { id: "cookie-pref-title", children: texts.modalTitle }),
417
531
  /* @__PURE__ */ jsxs3(DialogContent, { dividers: true, children: [
418
- /* @__PURE__ */ jsx3(Typography2, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
532
+ /* @__PURE__ */ jsx4(Typography2, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
419
533
  /* @__PURE__ */ jsxs3(FormGroup, { children: [
420
- /* @__PURE__ */ jsx3(
534
+ /* @__PURE__ */ jsx4(
421
535
  FormControlLabel,
422
536
  {
423
- control: /* @__PURE__ */ jsx3(
537
+ control: /* @__PURE__ */ jsx4(
424
538
  Switch,
425
539
  {
426
540
  checked: tempPreferences.analytics,
@@ -433,10 +547,10 @@ function PreferencesModal2({
433
547
  label: "Cookies Anal\xEDticos (medem uso do site)"
434
548
  }
435
549
  ),
436
- /* @__PURE__ */ jsx3(
550
+ /* @__PURE__ */ jsx4(
437
551
  FormControlLabel,
438
552
  {
439
- control: /* @__PURE__ */ jsx3(
553
+ control: /* @__PURE__ */ jsx4(
440
554
  Switch,
441
555
  {
442
556
  checked: tempPreferences.marketing,
@@ -449,19 +563,19 @@ function PreferencesModal2({
449
563
  label: "Cookies de Marketing/Publicidade"
450
564
  }
451
565
  ),
452
- /* @__PURE__ */ jsx3(
566
+ /* @__PURE__ */ jsx4(
453
567
  FormControlLabel,
454
568
  {
455
- control: /* @__PURE__ */ jsx3(Switch, { checked: true, disabled: true }),
569
+ control: /* @__PURE__ */ jsx4(Switch, { checked: true, disabled: true }),
456
570
  label: texts.necessaryAlwaysOn
457
571
  }
458
572
  )
459
573
  ] })
460
574
  ] }),
461
- !hideBranding && /* @__PURE__ */ jsx3(Branding, { variant: "modal" }),
575
+ !hideBranding && /* @__PURE__ */ jsx4(Branding, { variant: "modal" }),
462
576
  /* @__PURE__ */ jsxs3(DialogActions, { children: [
463
- /* @__PURE__ */ jsx3(Button, { variant: "outlined", onClick: handleCancel, children: "Cancelar" }),
464
- /* @__PURE__ */ jsx3(Button, { variant: "contained", onClick: handleSave, children: texts.save })
577
+ /* @__PURE__ */ jsx4(Button, { variant: "outlined", onClick: handleCancel, children: "Cancelar" }),
578
+ /* @__PURE__ */ jsx4(Button, { variant: "contained", onClick: handleSave, children: texts.save })
465
579
  ] })
466
580
  ]
467
581
  }
@@ -470,6 +584,8 @@ function PreferencesModal2({
470
584
 
471
585
  export {
472
586
  defaultConsentTheme,
587
+ useCustomCategories,
588
+ useAllCategories,
473
589
  Branding,
474
590
  PreferencesModal2 as PreferencesModal,
475
591
  ConsentProvider,