@graffico/legal 0.1.9 → 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.
- package/README.md +159 -138
- package/dist/index.d.ts +138 -25
- package/dist/index.js +1 -1
- package/dist/server.d.ts +80 -0
- package/dist/server.js +1 -0
- package/package.json +65 -42
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +0 -309
package/README.md
CHANGED
|
@@ -1,138 +1,159 @@
|
|
|
1
|
-
# @graffico/legal
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
1
|
+
# @graffico/legal
|
|
2
|
+
|
|
3
|
+
GDPR compliance per React/Next.js. Banner, modale preferenze, privacy & cookie policy server-rendered, oltre 15 service preset.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @graffico/legal
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
`app/layout.tsx` — server component, **niente `"use client"`**:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { LegalProvider } from "@graffico/legal/server";
|
|
17
|
+
|
|
18
|
+
const legalConfig = {
|
|
19
|
+
name: "Mia Azienda",
|
|
20
|
+
domain: "azienda.it",
|
|
21
|
+
owners: "Nome Proprietario",
|
|
22
|
+
addresses: "Via Roma 1, Milano",
|
|
23
|
+
vatNumbers: "01234567890",
|
|
24
|
+
email: "privacy@azienda.it",
|
|
25
|
+
services: ["google-analytics", "facebook-pixel"],
|
|
26
|
+
primaryColor: "#2c5282",
|
|
27
|
+
language: "it",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default function RootLayout({ children }) {
|
|
31
|
+
return (
|
|
32
|
+
<html>
|
|
33
|
+
<body>
|
|
34
|
+
<LegalProvider config={legalConfig}>{children}</LegalProvider>
|
|
35
|
+
</body>
|
|
36
|
+
</html>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`<LegalProvider>` monta automaticamente banner, modale preferenze e toggle flottante.
|
|
42
|
+
|
|
43
|
+
## Pagine
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
// app/privacy-policy/page.tsx
|
|
47
|
+
import { PrivacyPolicy } from "@graffico/legal/server";
|
|
48
|
+
export default () => <PrivacyPolicy config={legalConfig} />;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// app/cookie-policy/page.tsx
|
|
53
|
+
import { CookiePolicy } from "@graffico/legal/server";
|
|
54
|
+
export default () => <CookiePolicy config={legalConfig} />;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## i18n dinamico (opzionale)
|
|
58
|
+
|
|
59
|
+
Se l'app cambia lingua a runtime (es. con i18next), aggiungi un bridge:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
// components/legal-i18n-bridge.tsx
|
|
63
|
+
"use client";
|
|
64
|
+
import { useEffect } from "react";
|
|
65
|
+
import { setLanguage } from "@graffico/legal";
|
|
66
|
+
import i18n from "@/i18n";
|
|
67
|
+
|
|
68
|
+
export function LegalI18nBridge() {
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const sync = () => setLanguage(i18n.language);
|
|
71
|
+
sync();
|
|
72
|
+
i18n.on("languageChanged", sync);
|
|
73
|
+
return () => i18n.off("languageChanged", sync);
|
|
74
|
+
}, []);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Inseriscilo come figlio del provider:
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<LegalProvider config={legalConfig}>
|
|
83
|
+
<LegalI18nBridge />
|
|
84
|
+
{children}
|
|
85
|
+
</LegalProvider>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Service preset
|
|
89
|
+
|
|
90
|
+
Inserisci l'id come stringa nell'array `services`:
|
|
91
|
+
|
|
92
|
+
| Categoria | Preset disponibili |
|
|
93
|
+
|-----------|--------------------|
|
|
94
|
+
| Analytics | `google-analytics`, `facebook-pixel`, `linkedin-insight`, `tiktok-pixel`, `microsoft-clarity`, `hotjar`, `google-tag-manager` |
|
|
95
|
+
| Pagamenti | `stripe`, `paypal` |
|
|
96
|
+
| Contenuti | `youtube`, `google-maps`, `google-fonts` |
|
|
97
|
+
| Marketing | `mailchimp`, `newsletter`, `contact-form` |
|
|
98
|
+
|
|
99
|
+
Servizio custom inline:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
{
|
|
103
|
+
id: "crm",
|
|
104
|
+
name: "CRM Interno",
|
|
105
|
+
category: "provided", // "automatic" | "provided" | "marketing"
|
|
106
|
+
purposes: ["Gestione Clienti"],
|
|
107
|
+
dataCollected: ["Email", "Nome"],
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## API
|
|
112
|
+
|
|
113
|
+
### Entry `@graffico/legal/server` (server)
|
|
114
|
+
|
|
115
|
+
| Export | Tipo |
|
|
116
|
+
|--------|------|
|
|
117
|
+
| `LegalProvider` | Wrapper root, monta context + banner |
|
|
118
|
+
| `PrivacyPolicy` | Pagina privacy policy |
|
|
119
|
+
| `CookiePolicy` | Pagina cookie policy |
|
|
120
|
+
|
|
121
|
+
### Entry `@graffico/legal` (client)
|
|
122
|
+
|
|
123
|
+
| Export | Tipo |
|
|
124
|
+
|--------|------|
|
|
125
|
+
| `useLegalLanguage` | Lingua corrente |
|
|
126
|
+
| `useConsent` | Stato consenso (`{ statistical, marketing, ... }`) |
|
|
127
|
+
| `useShowBanner`, `useModalOpen`, `useT` | Hook UI |
|
|
128
|
+
| `useLegalConfig`, `useLegalConfigOptional` | Config dal context |
|
|
129
|
+
| `setLanguage`, `acceptAll`, `declineAll`, `savePreferences`, `resetConsent`, `setModalOpen` | Azioni store |
|
|
130
|
+
| `ConsentBanner`, `PreferenceModal`, `FloatingConsentToggle`, `ServiceGrid` | Componenti, già montati dal provider |
|
|
131
|
+
| `SERVICE_PRESETS`, `resolveService`, `DEFAULT_PRIMARY_COLOR` | Utility |
|
|
132
|
+
|
|
133
|
+
## Configurazione
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
interface CompanyConfig {
|
|
137
|
+
name: string;
|
|
138
|
+
domain: string;
|
|
139
|
+
owners: string;
|
|
140
|
+
addresses: string | string[];
|
|
141
|
+
vatNumbers: string | string[];
|
|
142
|
+
email: string;
|
|
143
|
+
services?: ServiceReference[];
|
|
144
|
+
togglePosition?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
145
|
+
lastUpdated?: string;
|
|
146
|
+
theme?: "light" | "dark";
|
|
147
|
+
primaryColor?: string;
|
|
148
|
+
language?: "it" | "en";
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Requisiti
|
|
153
|
+
|
|
154
|
+
- React 18+ (Next.js App Router consigliato)
|
|
155
|
+
- TailwindCSS opzionale; la lib usa classi Tailwind, integrazione via `content` oppure rimpiazzo con CSS proprio.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
Made by **Graffico Studio**.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Banner di consenso GDPR mostrato finché l'utente non sceglie le preferenze.
|
|
6
|
+
*/
|
|
7
|
+
declare const ConsentBanner: () => react_jsx_runtime.JSX.Element;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Modale per regolare in dettaglio le preferenze per categoria di tracker.
|
|
11
|
+
*/
|
|
12
|
+
declare const PreferenceModal: () => react_jsx_runtime.JSX.Element | null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Pulsante flottante che riapre il modale dopo che il consenso è stato dato.
|
|
16
|
+
*/
|
|
17
|
+
declare const FloatingConsentToggle: () => react_jsx_runtime.JSX.Element | null;
|
|
18
|
+
|
|
4
19
|
declare const TRANSLATIONS: {
|
|
5
20
|
it: {
|
|
6
21
|
legal: string;
|
|
@@ -17,6 +32,7 @@ declare const TRANSLATIONS: {
|
|
|
17
32
|
decline: string;
|
|
18
33
|
customize: string;
|
|
19
34
|
accept: string;
|
|
35
|
+
close: string;
|
|
20
36
|
preferencesTitle: string;
|
|
21
37
|
preferencesSubtitle: string;
|
|
22
38
|
preferencesDescription: string;
|
|
@@ -120,6 +136,7 @@ declare const TRANSLATIONS: {
|
|
|
120
136
|
contactForm: string;
|
|
121
137
|
youtubeWidget: string;
|
|
122
138
|
googleMapsWidget: string;
|
|
139
|
+
noActiveService: string;
|
|
123
140
|
};
|
|
124
141
|
en: {
|
|
125
142
|
legal: string;
|
|
@@ -136,6 +153,7 @@ declare const TRANSLATIONS: {
|
|
|
136
153
|
decline: string;
|
|
137
154
|
customize: string;
|
|
138
155
|
accept: string;
|
|
156
|
+
close: string;
|
|
139
157
|
preferencesTitle: string;
|
|
140
158
|
preferencesSubtitle: string;
|
|
141
159
|
preferencesDescription: string;
|
|
@@ -239,9 +257,13 @@ declare const TRANSLATIONS: {
|
|
|
239
257
|
contactForm: string;
|
|
240
258
|
youtubeWidget: string;
|
|
241
259
|
googleMapsWidget: string;
|
|
260
|
+
noActiveService: string;
|
|
242
261
|
};
|
|
243
262
|
};
|
|
244
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Tracker o servizio terzo dichiarato in cookie/privacy policy.
|
|
266
|
+
*/
|
|
245
267
|
interface LegalService {
|
|
246
268
|
id: string;
|
|
247
269
|
name: string;
|
|
@@ -250,8 +272,17 @@ interface LegalService {
|
|
|
250
272
|
purposes: string[];
|
|
251
273
|
dataCollected: string[];
|
|
252
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Riferimento a un servizio: id di un preset oppure servizio inline.
|
|
277
|
+
*/
|
|
253
278
|
type ServiceReference = string | LegalService;
|
|
279
|
+
/**
|
|
280
|
+
* Posizione del toggle floating per riaprire le preferenze.
|
|
281
|
+
*/
|
|
254
282
|
type TogglePosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
283
|
+
/**
|
|
284
|
+
* Configurazione del titolare e branding mostrati nelle policy.
|
|
285
|
+
*/
|
|
255
286
|
interface CompanyConfig {
|
|
256
287
|
name: string;
|
|
257
288
|
domain: string;
|
|
@@ -266,6 +297,9 @@ interface CompanyConfig {
|
|
|
266
297
|
primaryColor?: string;
|
|
267
298
|
language?: "it" | "en";
|
|
268
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Stato di consenso persistito per categoria, con prova legale (id + timestamp).
|
|
302
|
+
*/
|
|
269
303
|
interface ConsentState {
|
|
270
304
|
necessary: boolean;
|
|
271
305
|
statistical: boolean;
|
|
@@ -273,37 +307,116 @@ interface ConsentState {
|
|
|
273
307
|
consentId?: string;
|
|
274
308
|
timestamp?: string;
|
|
275
309
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
declare const LegalProvider: ({ children, config, }: {
|
|
289
|
-
children: ReactNode;
|
|
290
|
-
config: CompanyConfig;
|
|
291
|
-
}) => react_jsx_runtime.JSX.Element | null;
|
|
292
|
-
declare const useLegal: () => LegalContextType;
|
|
310
|
+
/**
|
|
311
|
+
* Codice lingua supportato dalla libreria.
|
|
312
|
+
*/
|
|
313
|
+
type Language = "it" | "en";
|
|
314
|
+
/**
|
|
315
|
+
* Chiave di traduzione disponibile in entrambe le lingue.
|
|
316
|
+
*/
|
|
317
|
+
type TranslationKey = keyof (typeof TRANSLATIONS)["it"];
|
|
318
|
+
/**
|
|
319
|
+
* Funzione che risolve una chiave di traduzione nella lingua corrente.
|
|
320
|
+
*/
|
|
321
|
+
type Translator = (key: TranslationKey) => string;
|
|
293
322
|
|
|
294
|
-
|
|
323
|
+
interface ServiceGridProps {
|
|
324
|
+
config?: CompanyConfig;
|
|
325
|
+
language?: Language;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Griglia paginata dei servizi terzi: divide tra dati raccolti automaticamente e forniti.
|
|
329
|
+
*/
|
|
330
|
+
declare const ServiceGrid: ({ config: configProp, language: langProp, }?: ServiceGridProps) => react_jsx_runtime.JSX.Element | null;
|
|
295
331
|
|
|
296
|
-
|
|
332
|
+
interface Props {
|
|
333
|
+
language: Language;
|
|
334
|
+
primaryColor: string;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Card "centro preferenze" della cookie policy: gestisci o resetta consenso.
|
|
338
|
+
*/
|
|
339
|
+
declare function PreferenceCard({ language, primaryColor }: Props): react_jsx_runtime.JSX.Element;
|
|
297
340
|
|
|
298
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Lingua corrente normalizzata, reattiva ai cambi via bridge i18n.
|
|
343
|
+
*/
|
|
344
|
+
declare const useLegalLanguage: () => Language;
|
|
345
|
+
/**
|
|
346
|
+
* Stato di consenso corrente (necessary/statistical/marketing + prova legale).
|
|
347
|
+
*/
|
|
348
|
+
declare const useConsent: () => ConsentState;
|
|
349
|
+
/**
|
|
350
|
+
* Indica se il banner di consenso è da mostrare (post-hydration).
|
|
351
|
+
*/
|
|
352
|
+
declare const useShowBanner: () => boolean;
|
|
353
|
+
/**
|
|
354
|
+
* Indica se il modale delle preferenze è aperto.
|
|
355
|
+
*/
|
|
356
|
+
declare const useModalOpen: () => boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Traduttore reattivo per la lingua corrente.
|
|
359
|
+
*/
|
|
360
|
+
declare function useT(): Translator;
|
|
299
361
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Boundary client root: espone la config via context, idrata il consenso
|
|
364
|
+
* persistito al mount e tiene sincronizzata la lingua dello store.
|
|
365
|
+
*/
|
|
366
|
+
declare function LegalConfigProvider({ config, children, }: {
|
|
367
|
+
config: CompanyConfig;
|
|
368
|
+
children: ReactNode;
|
|
369
|
+
}): react_jsx_runtime.JSX.Element;
|
|
370
|
+
/**
|
|
371
|
+
* Hook che legge la `CompanyConfig` dal context, errore se non avvolto.
|
|
372
|
+
*/
|
|
373
|
+
declare function useLegalConfig(): CompanyConfig;
|
|
374
|
+
/**
|
|
375
|
+
* Variante non-throwing: restituisce `null` se il provider non è montato.
|
|
376
|
+
*/
|
|
377
|
+
declare function useLegalConfigOptional(): CompanyConfig | null;
|
|
303
378
|
|
|
304
|
-
|
|
379
|
+
/**
|
|
380
|
+
* Aggiorna la lingua corrente normalizzando un codice arbitrario.
|
|
381
|
+
*/
|
|
382
|
+
declare function setLanguage(lang: string | undefined | null): void;
|
|
383
|
+
/**
|
|
384
|
+
* Carica il consenso da localStorage al mount; mostra il banner se assente.
|
|
385
|
+
*/
|
|
386
|
+
declare function hydrateFromStorage(initialLanguage?: Language): void;
|
|
387
|
+
/**
|
|
388
|
+
* Persiste le preferenze e marca prova legale (consentId + timestamp).
|
|
389
|
+
*/
|
|
390
|
+
declare function savePreferences(prefs: ConsentState): void;
|
|
391
|
+
/**
|
|
392
|
+
* Accetta tutte le categorie e chiude il banner.
|
|
393
|
+
*/
|
|
394
|
+
declare function acceptAll(): void;
|
|
395
|
+
/**
|
|
396
|
+
* Rifiuta tutte le categorie opzionali e chiude il banner.
|
|
397
|
+
*/
|
|
398
|
+
declare function declineAll(): void;
|
|
399
|
+
/**
|
|
400
|
+
* Cancella il consenso persistito e riapre il banner iniziale.
|
|
401
|
+
*/
|
|
402
|
+
declare function resetConsent(): void;
|
|
403
|
+
/**
|
|
404
|
+
* Apre o chiude il modale delle preferenze.
|
|
405
|
+
*/
|
|
406
|
+
declare function setModalOpen(open: boolean): void;
|
|
305
407
|
|
|
408
|
+
/**
|
|
409
|
+
* Catalogo di servizi pre-configurati identificati per id (es. "google-analytics").
|
|
410
|
+
*/
|
|
306
411
|
declare const SERVICE_PRESETS: Record<string, LegalService>;
|
|
412
|
+
/**
|
|
413
|
+
* Risolve un riferimento (id stringa o oggetto inline) in un `LegalService` completo.
|
|
414
|
+
*/
|
|
307
415
|
declare const resolveService: (ref: string | LegalService) => LegalService;
|
|
308
416
|
|
|
309
|
-
|
|
417
|
+
/**
|
|
418
|
+
* Colore primario di default, usato quando `config.primaryColor` non è impostato.
|
|
419
|
+
*/
|
|
420
|
+
declare const DEFAULT_PRIMARY_COLOR = "#2c5282";
|
|
421
|
+
|
|
422
|
+
export { type CompanyConfig, ConsentBanner, type ConsentState, DEFAULT_PRIMARY_COLOR, FloatingConsentToggle, type Language, LegalConfigProvider, type LegalService, PreferenceCard, PreferenceModal, SERVICE_PRESETS, ServiceGrid, type ServiceReference, type TogglePosition, type TranslationKey, type Translator, acceptAll, declineAll, hydrateFromStorage, resetConsent, resolveService, savePreferences, setLanguage, setModalOpen, useConsent, useLegalConfig, useLegalConfigOptional, useLegalLanguage, useModalOpen, useShowBanner, useT };
|