@react-lgpd-consent/core 0.7.0 → 0.7.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.
- package/CHANGELOG.md +205 -0
- package/README.md +16 -1
- package/dist/index.cjs +602 -154
- package/dist/index.d.cts +167 -13
- package/dist/index.d.ts +167 -13
- package/dist/index.js +598 -155
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,210 @@
|
|
|
1
1
|
# Changelog - @react-lgpd-consent/core
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#133](https://github.com/lucianoedipo/react-lgpd-consent/pull/133) [`33bc0eb`](https://github.com/lucianoedipo/react-lgpd-consent/commit/33bc0ebcb40ce65c70b02668d3c0a97efb1854f1) Thanks [@lucianoedipo](https://github.com/lucianoedipo)! - # 🧩 Fundamento Crítico de Consentimento — SUPER TASK v0.7.1
|
|
8
|
+
|
|
9
|
+
**Persistência + Loader + Consent Mode v2**
|
|
10
|
+
|
|
11
|
+
Esta release estabelece o **núcleo legal, técnico e funcional** da biblioteca react-lgpd-consent, garantindo um contrato sólido, seguro e auditável para uso institucional e governamental.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
## 🔹 Bloco A — Persistência de Consentimento por Cookie
|
|
16
|
+
|
|
17
|
+
### ✨ API Consolidada de Persistência
|
|
18
|
+
|
|
19
|
+
Nova API completa no `ConsentProvider`:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
<ConsentProvider
|
|
23
|
+
cookie={{
|
|
24
|
+
name: 'lgpd-consent',
|
|
25
|
+
domain: '.example.com', // Compartilha entre subdomínios
|
|
26
|
+
path: '/',
|
|
27
|
+
sameSite: 'Lax', // Default seguro
|
|
28
|
+
secure: true, // Auto em HTTPS
|
|
29
|
+
maxAge: 31536000, // Segundos (substitui maxAgeDays)
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Regras Implementadas:**
|
|
35
|
+
- ✅ Defaults seguros: `SameSite=Lax`, `Secure=true` em HTTPS
|
|
36
|
+
- ✅ Categoria `necessary` **sempre forçada como true**
|
|
37
|
+
- ✅ Nenhuma gravação de cookie durante SSR
|
|
38
|
+
- ✅ Suporte completo a subdomínios via `domain`
|
|
39
|
+
- ✅ Nova opção `maxAge` (segundos, padrão moderno)
|
|
40
|
+
- ✅ Opção `maxAgeDays` deprecated mas mantida para compatibilidade
|
|
41
|
+
|
|
42
|
+
**Ambientes Suportados:**
|
|
43
|
+
- ✅ `localhost` (desenvolvimento)
|
|
44
|
+
- ✅ `dev` / `staging` (domínios customizados)
|
|
45
|
+
- ✅ `production` (HTTPS obrigatório)
|
|
46
|
+
- ✅ Comportamento **independente de NODE_ENV**
|
|
47
|
+
|
|
48
|
+
***
|
|
49
|
+
|
|
50
|
+
## 🔹 Bloco B — ConsentScriptLoader com Bloqueio Real
|
|
51
|
+
|
|
52
|
+
### 🚫 Contrato de Bloqueio Garantido
|
|
53
|
+
|
|
54
|
+
> **Nenhum script não necessário executa antes do consentimento correspondente.**
|
|
55
|
+
|
|
56
|
+
### ✨ Sistema de Fila e Priorização
|
|
57
|
+
|
|
58
|
+
Implementado `ConsentScriptLoader` com:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
registerScript({
|
|
62
|
+
id: 'google-analytics',
|
|
63
|
+
category: 'analytics',
|
|
64
|
+
priority: 1, // Ordem de execução
|
|
65
|
+
execute: () => {
|
|
66
|
+
// Seu script aqui
|
|
67
|
+
},
|
|
68
|
+
onConsentUpdate: (granted) => {
|
|
69
|
+
// Reagir a mudanças de consentimento
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Recursos Implementados:**
|
|
75
|
+
- ✅ **Fila interna de execução** com ordenação por:
|
|
76
|
+
- 1. Categoria (`necessary` → `analytics` → `marketing`, etc.)
|
|
77
|
+
- 2. Prioridade (numérica)
|
|
78
|
+
- 3. Timestamp (ordem de registro)
|
|
79
|
+
- ✅ Scripts `necessary` executam **imediatamente**
|
|
80
|
+
- ✅ Scripts de outras categorias aguardam **consentimento explícito**
|
|
81
|
+
- ✅ Suporte a `onConsentUpdate` para reconfiguração dinâmica
|
|
82
|
+
- ✅ Snapshot de consentimento para scripts que precisam do estado atual
|
|
83
|
+
- ✅ **Otimização anti-duplicação**: integrações não são reexecutadas a cada render quando criadas inline (ex.: `integrations={[createGoogleAnalyticsIntegration(...)]}`). Sistema mantém hash estrutural para detectar mudanças reais e prevenir múltiplas inicializações do mesmo script.
|
|
84
|
+
|
|
85
|
+
**Observabilidade em DEV:**
|
|
86
|
+
- ✅ Logs detalhados de ordem de execução
|
|
87
|
+
- ✅ Indicação clara de categoria liberada
|
|
88
|
+
- ✅ Rastreamento de status de cada script
|
|
89
|
+
- ⚠️ **Silencioso em produção** (performance otimizada)
|
|
90
|
+
|
|
91
|
+
***
|
|
92
|
+
|
|
93
|
+
## 🔹 Bloco C — Integração Nativa Google Consent Mode v2
|
|
94
|
+
|
|
95
|
+
### 🎯 Implementação Automática
|
|
96
|
+
|
|
97
|
+
**Zero configuração manual necessária!**
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { createGoogleAnalyticsIntegration } from '@react-lgpd-consent/core'
|
|
101
|
+
|
|
102
|
+
const ga4 = createGoogleAnalyticsIntegration({
|
|
103
|
+
measurementId: 'G-XXXXXXXXXX'
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
<ConsentScriptLoader integrations={[ga4]} />
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**O que a biblioteca faz automaticamente:**
|
|
110
|
+
1. ✅ Inicializa `dataLayer` se não existir
|
|
111
|
+
2. ✅ Define `gtag('consent', 'default', denied)` **antes** de qualquer tag
|
|
112
|
+
3. ✅ Mapeia categorias corretamente:
|
|
113
|
+
- `analytics` → `analytics_storage`
|
|
114
|
+
- `marketing` → `ad_storage`, `ad_user_data`, `ad_personalization`
|
|
115
|
+
4. ✅ Envia `gtag('consent', 'update')` quando usuário escolhe preferências
|
|
116
|
+
5. ✅ Dispara eventos de ciclo de vida:
|
|
117
|
+
```javascript
|
|
118
|
+
{ event: 'consent_initialized' }
|
|
119
|
+
{ event: 'consent_updated', preferences: {...} }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Factories Implementadas:**
|
|
123
|
+
- ✅ `createGoogleAnalyticsIntegration` (GA4)
|
|
124
|
+
- ✅ `createGoogleTagManagerIntegration` (GTM)
|
|
125
|
+
- ✅ Suporte a `bootstrap()` para inicialização pré-consentimento
|
|
126
|
+
- ✅ Suporte a `onConsentUpdate()` para reconfiguração dinâmica
|
|
127
|
+
|
|
128
|
+
### 🔒 Ordem de Inicialização Segura
|
|
129
|
+
|
|
130
|
+
Fluxo garantido pela implementação:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
1. dataLayer criado
|
|
134
|
+
2. gtag('consent', 'default', denied)
|
|
135
|
+
3. Loader bloqueia tags
|
|
136
|
+
4. Usuário consente
|
|
137
|
+
5. gtag('consent', 'update', granted/denied)
|
|
138
|
+
6. Tags disparam conforme consentimento
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### ⚡ Compatibilidade Next.js (SSR)
|
|
142
|
+
- ✅ Nenhum acesso a `window` fora de `useEffect`
|
|
143
|
+
- ✅ App Router (Next.js 13+)
|
|
144
|
+
- ✅ Pages Router (Next.js 12+)
|
|
145
|
+
- ✅ **Zero hydration mismatch**
|
|
146
|
+
- ✅ Estratégia de renderização: `client-only` quando necessário
|
|
147
|
+
|
|
148
|
+
***
|
|
149
|
+
|
|
150
|
+
## 🆕 Novas APIs Públicas
|
|
151
|
+
|
|
152
|
+
### Core Package (`@react-lgpd-consent/core`):
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// Registro de scripts
|
|
156
|
+
registerScript(config: RegisteredScript): void
|
|
157
|
+
|
|
158
|
+
// Factories de integrações
|
|
159
|
+
createGoogleAnalyticsIntegration(config): ScriptIntegration
|
|
160
|
+
createGoogleTagManagerIntegration(config): ScriptIntegration
|
|
161
|
+
|
|
162
|
+
// Utilitários de cookie
|
|
163
|
+
readConsentCookie(name?: string): ConsentState | null
|
|
164
|
+
writeConsentCookie(state: ConsentState, options?: CookieOptions): void
|
|
165
|
+
|
|
166
|
+
// Novos tipos
|
|
167
|
+
type RegisteredScript = { ... }
|
|
168
|
+
type ScriptIntegration = { ... }
|
|
169
|
+
interface LoadScriptOptions = { ... }
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
***
|
|
173
|
+
|
|
174
|
+
## 📚 Documentação Atualizada
|
|
175
|
+
- ✅ **API.md** - Novas APIs de `registerScript` e Consent Mode v2
|
|
176
|
+
- ✅ **INTEGRACOES.md** - Guias completos de GA4, GTM, Facebook Pixel
|
|
177
|
+
- ✅ **MIGRATION.md** - Guia de migração v0.7.0 → v0.7.1
|
|
178
|
+
- ✅ **SUPER_TASK_VALIDATION.md** - Relatório técnico de validação completo
|
|
179
|
+
|
|
180
|
+
***
|
|
181
|
+
|
|
182
|
+
## 🔄 Breaking Changes
|
|
183
|
+
|
|
184
|
+
**Nenhum!** Esta release é 100% backward-compatible:
|
|
185
|
+
- ✅ Opção `maxAgeDays` deprecated mas funcional
|
|
186
|
+
- ✅ Comportamento padrão preservado
|
|
187
|
+
- ✅ APIs antigas continuam funcionando
|
|
188
|
+
- ✅ Migração gradual suportada
|
|
189
|
+
|
|
190
|
+
***
|
|
191
|
+
|
|
192
|
+
## 🎯 Melhorias Complementares
|
|
193
|
+
|
|
194
|
+
### Sistema de i18n para Diagnósticos
|
|
195
|
+
|
|
196
|
+
Sistema básico de internacionalização para mensagens de peer dependencies:
|
|
197
|
+
- ✅ Suporte a pt-BR (padrão) e en
|
|
198
|
+
- ✅ API para customização: `setPeerDepsLocale()`, `setPeerDepsMessages()`
|
|
199
|
+
- ✅ Mensagens extraídas para constantes (melhor manutenibilidade)
|
|
200
|
+
|
|
201
|
+
### Refatorações e Otimizações
|
|
202
|
+
- ✅ Strings de mensagens extraídas para constantes
|
|
203
|
+
- ✅ Separação de concerns (lógica vs conteúdo)
|
|
204
|
+
- ✅ Type safety aprimorado em toda API
|
|
205
|
+
- ✅ Performance otimizada (sem logs em produção)
|
|
206
|
+
- ✅ **Fix crítico**: Prevenção de reexecução de integrações a cada render quando `integrations` prop muda referência (inline array). Sistema agora usa hash estrutural para detectar mudanças reais e manter scripts já registrados estáveis.
|
|
207
|
+
|
|
3
208
|
## 0.7.0
|
|
4
209
|
|
|
5
210
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -62,6 +62,22 @@ function MyCustomBanner() {
|
|
|
62
62
|
- **Integrações:** Google Analytics, GTM, UserWay, Facebook Pixel, Hotjar, etc.
|
|
63
63
|
- **Tipos TypeScript:** Tipagem completa para toda a API
|
|
64
64
|
|
|
65
|
+
## 🧩 Scripts, Fila e Consent Mode v2
|
|
66
|
+
|
|
67
|
+
- **ConsentScriptLoader** agora mantém uma fila interna por categoria e prioridade. Scripts `necessary` rodam imediatamente; os demais só executam após consentimento explícito.
|
|
68
|
+
- **API programática `registerScript`**: registre callbacks inline ou integrações que não usam `<script src>` e deixe a fila disparar no momento correto. Estados da fila: `pending` → `running` → `executed` (recarrega apenas se `allowReload=true`).
|
|
69
|
+
```ts
|
|
70
|
+
const cleanup = registerScript({
|
|
71
|
+
id: 'ga-consent-mode',
|
|
72
|
+
category: 'analytics',
|
|
73
|
+
priority: 10, // maior roda antes dentro da categoria
|
|
74
|
+
execute: bootstrapConsentMode,
|
|
75
|
+
onConsentUpdate: ({ preferences }) => pushConsentSignals(preferences),
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
- **Consent Mode v2 nativo**: `createGoogleAnalyticsIntegration` e `createGoogleTagManagerIntegration` inicializam `consent=default` (denied) e enviam `consent=update` conforme as preferências do usuário, sem snippet manual.
|
|
79
|
+
- **Observabilidade dev-only**: logs ordenados de execução para depurar a fila (silenciados em produção).
|
|
80
|
+
|
|
65
81
|
## 🆕 Novidades v0.7.0
|
|
66
82
|
|
|
67
83
|
### Callbacks de Lifecycle
|
|
@@ -123,4 +139,3 @@ Para documentação completa, exemplos e API reference:
|
|
|
123
139
|
## 📄 Licença
|
|
124
140
|
|
|
125
141
|
MIT © [Luciano Édipo](https://github.com/lucianoedipo)
|
|
126
|
-
|