forlogic-core 1.10.2 → 1.11.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 +389 -0
- package/dist/README.md +389 -0
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.js +2 -2
- package/dist/tailwind/index.esm.js +141 -0
- package/dist/tailwind/index.js +144 -0
- package/dist/vite/index.esm.js +204 -0
- package/dist/vite/index.js +209 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -14,6 +14,11 @@ A biblioteca `forlogic-core` requer as seguintes **peer dependencies** instalada
|
|
|
14
14
|
# Dependências obrigatórias
|
|
15
15
|
npm install react@^18.0.0 react-dom@^18.0.0
|
|
16
16
|
npm install lucide-react@>=0.400.0
|
|
17
|
+
|
|
18
|
+
# Internacionalização (i18n)
|
|
19
|
+
npm install i18next@^25.0.0 react-i18next@^16.0.0
|
|
20
|
+
```
|
|
21
|
+
|
|
17
22
|
### Instalar a Biblioteca
|
|
18
23
|
|
|
19
24
|
```bash
|
|
@@ -22,6 +27,20 @@ npm install forlogic-core
|
|
|
22
27
|
|
|
23
28
|
**Nota**: O npm/yarn irá alertar automaticamente se alguma peer dependency estiver faltando ou com versão incompatível.
|
|
24
29
|
|
|
30
|
+
### ⚠️ IMPORTANTE: Imports de i18n
|
|
31
|
+
|
|
32
|
+
**Sempre** importe hooks de internacionalização do `forlogic-core`, nunca diretamente de `react-i18next`:
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
// ❌ ERRADO - Causa conflito de instâncias (erro NO_I18NEXT_INSTANCE)
|
|
36
|
+
import { useTranslation } from 'react-i18next';
|
|
37
|
+
|
|
38
|
+
// ✅ CORRETO - Usa a mesma instância configurada pelo CoreProviders
|
|
39
|
+
import { useTranslation } from 'forlogic-core';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Isso garante que todos os componentes compartilhem a mesma instância do i18next configurada pelo `CoreProviders`.
|
|
43
|
+
|
|
25
44
|
---
|
|
26
45
|
|
|
27
46
|
## 🤖 REGRAS CRÍTICAS
|
|
@@ -187,6 +206,277 @@ CREATE INDEX idx_processes_title ON processes.processes(title);
|
|
|
187
206
|
|
|
188
207
|
---
|
|
189
208
|
|
|
209
|
+
## ⚙️ Configuração Vite e Tailwind (Projetos Consumidores)
|
|
210
|
+
|
|
211
|
+
A biblioteca `forlogic-core` exporta configurações padronizadas de Vite e Tailwind para garantir consistência de segurança e estilo em todos os projetos.
|
|
212
|
+
|
|
213
|
+
### 📦 Instalação
|
|
214
|
+
|
|
215
|
+
As configurações estão disponíveis via subpaths do pacote:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// Configurações Vite
|
|
219
|
+
import { createSecurityHeadersPlugin, createForlogicViteConfig } from 'forlogic-core/vite';
|
|
220
|
+
|
|
221
|
+
// Preset Tailwind
|
|
222
|
+
import { forlogicTailwindPreset, forlogicContentPaths } from 'forlogic-core/tailwind';
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
### 🔒 Plugin de Headers de Segurança (Vite)
|
|
228
|
+
|
|
229
|
+
O plugin configura automaticamente:
|
|
230
|
+
- **Content Security Policy (CSP)** - Proteção contra XSS e injeção de scripts
|
|
231
|
+
- **CORS seguro** - Origens confiáveis sem usar `*`
|
|
232
|
+
- **Headers OWASP** - HSTS, X-Content-Type-Options, X-Frame-Options, etc.
|
|
233
|
+
- **Permissions Policy** - Controle de APIs do navegador
|
|
234
|
+
|
|
235
|
+
#### Uso Básico
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
// vite.config.ts
|
|
239
|
+
import { defineConfig } from 'vite';
|
|
240
|
+
import react from '@vitejs/plugin-react-swc';
|
|
241
|
+
import { createSecurityHeadersPlugin } from 'forlogic-core/vite';
|
|
242
|
+
|
|
243
|
+
export default defineConfig(({ mode }) => ({
|
|
244
|
+
plugins: [
|
|
245
|
+
react(),
|
|
246
|
+
createSecurityHeadersPlugin(mode === 'development', {
|
|
247
|
+
supabaseUrls: ['https://seu-projeto.supabase.co'],
|
|
248
|
+
}),
|
|
249
|
+
],
|
|
250
|
+
}));
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### Configuração Completa
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
// vite.config.ts
|
|
257
|
+
import { defineConfig } from 'vite';
|
|
258
|
+
import react from '@vitejs/plugin-react-swc';
|
|
259
|
+
import { createSecurityHeadersPlugin } from 'forlogic-core/vite';
|
|
260
|
+
|
|
261
|
+
export default defineConfig(({ mode }) => {
|
|
262
|
+
const isDev = mode === 'development';
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
plugins: [
|
|
266
|
+
react(),
|
|
267
|
+
createSecurityHeadersPlugin(isDev, {
|
|
268
|
+
// URLs do Supabase para permitir conexões
|
|
269
|
+
supabaseUrls: [
|
|
270
|
+
'https://seu-projeto-dev.supabase.co',
|
|
271
|
+
'https://seu-projeto-prod.supabase.co',
|
|
272
|
+
],
|
|
273
|
+
|
|
274
|
+
// Origens confiáveis adicionais para CORS
|
|
275
|
+
trustedOrigins: [
|
|
276
|
+
'https://meu-app.com',
|
|
277
|
+
'https://admin.meu-app.com',
|
|
278
|
+
],
|
|
279
|
+
|
|
280
|
+
// APIs externas para connect-src
|
|
281
|
+
additionalConnectSrc: [
|
|
282
|
+
'https://api.exemplo.com',
|
|
283
|
+
'wss://websocket.exemplo.com',
|
|
284
|
+
],
|
|
285
|
+
|
|
286
|
+
// CDNs de scripts adicionais
|
|
287
|
+
additionalScriptSrc: [
|
|
288
|
+
'https://cdn.analytics.com',
|
|
289
|
+
],
|
|
290
|
+
|
|
291
|
+
// CDNs de estilos adicionais
|
|
292
|
+
additionalStyleSrc: [
|
|
293
|
+
'https://fonts.custom.com',
|
|
294
|
+
],
|
|
295
|
+
|
|
296
|
+
// URI para reportar violações CSP
|
|
297
|
+
cspReportUri: 'https://seu-projeto.supabase.co/functions/v1/csp-report',
|
|
298
|
+
|
|
299
|
+
// Habilitar Trusted Types em produção (default: true)
|
|
300
|
+
enableTrustedTypes: true,
|
|
301
|
+
|
|
302
|
+
// Upgrade HTTP para HTTPS em produção (default: true)
|
|
303
|
+
upgradeInsecureRequests: true,
|
|
304
|
+
}),
|
|
305
|
+
],
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
#### Opções do Plugin
|
|
311
|
+
|
|
312
|
+
| Opção | Tipo | Padrão | Descrição |
|
|
313
|
+
|-------|------|--------|-----------|
|
|
314
|
+
| `supabaseUrls` | `string[]` | `[]` | URLs do Supabase para permitir conexões |
|
|
315
|
+
| `trustedOrigins` | `string[]` | `[]` | Origens confiáveis adicionais para CORS |
|
|
316
|
+
| `additionalScriptSrc` | `string[]` | `[]` | Fontes de script adicionais para CSP |
|
|
317
|
+
| `additionalStyleSrc` | `string[]` | `[]` | Fontes de estilo adicionais para CSP |
|
|
318
|
+
| `additionalConnectSrc` | `string[]` | `[]` | APIs/WebSockets adicionais para CSP |
|
|
319
|
+
| `cspReportUri` | `string` | - | URI para relatório de violações CSP |
|
|
320
|
+
| `enableTrustedTypes` | `boolean` | `true` | Habilitar Trusted Types em produção |
|
|
321
|
+
| `upgradeInsecureRequests` | `boolean` | `true` | Upgrade HTTP→HTTPS em produção |
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
### 🏗️ Factory de Configuração Vite (Opcional)
|
|
326
|
+
|
|
327
|
+
Para projetos que desejam usar a configuração completa padronizada:
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
// vite.config.ts
|
|
331
|
+
import { defineConfig } from 'vite';
|
|
332
|
+
import react from '@vitejs/plugin-react-swc';
|
|
333
|
+
import { createForlogicViteConfig } from 'forlogic-core/vite';
|
|
334
|
+
|
|
335
|
+
// Cria configuração com opções personalizadas
|
|
336
|
+
const forlogicConfig = createForlogicViteConfig({
|
|
337
|
+
srcAlias: '@', // Alias para ./src
|
|
338
|
+
libAlias: 'forlogic-core', // Alias para ./lib (desenvolvimento local)
|
|
339
|
+
security: {
|
|
340
|
+
supabaseUrls: ['https://seu-projeto.supabase.co'],
|
|
341
|
+
trustedOrigins: ['https://meu-app.com'],
|
|
342
|
+
},
|
|
343
|
+
server: {
|
|
344
|
+
host: '::',
|
|
345
|
+
port: 8080,
|
|
346
|
+
},
|
|
347
|
+
build: {
|
|
348
|
+
chunkSizeWarningLimit: 4000,
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
export default defineConfig(({ mode }) => {
|
|
353
|
+
const config = forlogicConfig(mode === 'development');
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
...config,
|
|
357
|
+
plugins: [
|
|
358
|
+
react(),
|
|
359
|
+
...config.plugins,
|
|
360
|
+
],
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
### 🎨 Preset Tailwind CSS
|
|
368
|
+
|
|
369
|
+
O preset inclui:
|
|
370
|
+
- **Cores semânticas** - primary, secondary, destructive, success, warning, etc.
|
|
371
|
+
- **Border radius** - lg, md, sm padronizados
|
|
372
|
+
- **Animações** - accordion, fade, slide, scale
|
|
373
|
+
- **Gradientes** - primary, secondary, accent
|
|
374
|
+
- **Sombras** - xs até 2xl, inner, primary
|
|
375
|
+
|
|
376
|
+
#### Uso Básico
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
// tailwind.config.ts
|
|
380
|
+
import type { Config } from 'tailwindcss';
|
|
381
|
+
import { forlogicTailwindPreset, forlogicContentPaths } from 'forlogic-core/tailwind';
|
|
382
|
+
|
|
383
|
+
export default {
|
|
384
|
+
presets: [forlogicTailwindPreset],
|
|
385
|
+
content: [
|
|
386
|
+
...forlogicContentPaths,
|
|
387
|
+
// Paths adicionais específicos do seu projeto
|
|
388
|
+
],
|
|
389
|
+
} satisfies Config;
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
#### Uso com Extensões
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
// tailwind.config.ts
|
|
396
|
+
import type { Config } from 'tailwindcss';
|
|
397
|
+
import { forlogicTailwindPreset, forlogicContentPaths } from 'forlogic-core/tailwind';
|
|
398
|
+
|
|
399
|
+
export default {
|
|
400
|
+
presets: [forlogicTailwindPreset],
|
|
401
|
+
content: [
|
|
402
|
+
...forlogicContentPaths,
|
|
403
|
+
],
|
|
404
|
+
theme: {
|
|
405
|
+
extend: {
|
|
406
|
+
// Extensões específicas do seu projeto
|
|
407
|
+
colors: {
|
|
408
|
+
brand: {
|
|
409
|
+
50: 'hsl(var(--brand-50))',
|
|
410
|
+
// ...
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
plugins: [
|
|
416
|
+
require('tailwindcss-animate'),
|
|
417
|
+
// Plugins adicionais
|
|
418
|
+
],
|
|
419
|
+
} satisfies Config;
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
#### Content Paths Padrão
|
|
423
|
+
|
|
424
|
+
O `forlogicContentPaths` inclui:
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
[
|
|
428
|
+
'./pages/**/*.{ts,tsx}',
|
|
429
|
+
'./components/**/*.{ts,tsx}',
|
|
430
|
+
'./app/**/*.{ts,tsx}',
|
|
431
|
+
'./src/**/*.{ts,tsx}',
|
|
432
|
+
'./lib/**/*.{ts,tsx}',
|
|
433
|
+
'./node_modules/forlogic-core/dist/**/*.{js,ts,jsx,tsx}',
|
|
434
|
+
]
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
### 📋 Checklist de Configuração
|
|
440
|
+
|
|
441
|
+
```markdown
|
|
442
|
+
- [ ] Instalou `forlogic-core` no projeto?
|
|
443
|
+
- [ ] Configurou `vite.config.ts` com `createSecurityHeadersPlugin`?
|
|
444
|
+
- [ ] Adicionou URLs do Supabase em `supabaseUrls`?
|
|
445
|
+
- [ ] Configurou `tailwind.config.ts` com `forlogicTailwindPreset`?
|
|
446
|
+
- [ ] Adicionou `forlogicContentPaths` ao content?
|
|
447
|
+
- [ ] Definiu variáveis CSS no `index.css` (--primary, --background, etc.)?
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
### 🔧 Configuração do package.json (Publicação da Lib)
|
|
453
|
+
|
|
454
|
+
Para projetos que estão **publicando** a `forlogic-core`, adicione os exports condicionais:
|
|
455
|
+
|
|
456
|
+
```json
|
|
457
|
+
{
|
|
458
|
+
"exports": {
|
|
459
|
+
".": {
|
|
460
|
+
"import": "./dist/index.esm.js",
|
|
461
|
+
"require": "./dist/index.js",
|
|
462
|
+
"types": "./dist/index.d.ts"
|
|
463
|
+
},
|
|
464
|
+
"./vite": {
|
|
465
|
+
"import": "./dist/vite/index.esm.js",
|
|
466
|
+
"require": "./dist/vite/index.js",
|
|
467
|
+
"types": "./dist/vite/index.d.ts"
|
|
468
|
+
},
|
|
469
|
+
"./tailwind": {
|
|
470
|
+
"import": "./dist/tailwind/index.esm.js",
|
|
471
|
+
"require": "./dist/tailwind/index.js",
|
|
472
|
+
"types": "./dist/tailwind/index.d.ts"
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
190
480
|
## 🚩 Feature Flags (Variáveis de Ambiente)
|
|
191
481
|
|
|
192
482
|
A biblioteca suporta feature flags para habilitar/desabilitar funcionalidades opcionais.
|
|
@@ -218,6 +508,105 @@ VITE_IS_QUALIEX=true
|
|
|
218
508
|
|
|
219
509
|
---
|
|
220
510
|
|
|
511
|
+
## 🚀 Quick Setup: CoreProviders
|
|
512
|
+
|
|
513
|
+
O `CoreProviders` é um componente que encapsula todos os providers essenciais da biblioteca, simplificando drasticamente a configuração de novos projetos.
|
|
514
|
+
|
|
515
|
+
### O que está incluído
|
|
516
|
+
|
|
517
|
+
O `CoreProviders` encapsula automaticamente:
|
|
518
|
+
|
|
519
|
+
| Provider | Descrição |
|
|
520
|
+
|----------|-----------|
|
|
521
|
+
| `ErrorBoundary` | Captura e trata erros de renderização React |
|
|
522
|
+
| `I18nextProvider` | Sistema de internacionalização (i18n) |
|
|
523
|
+
| `QueryClientProvider` | Cache e gerenciamento de queries (React Query) |
|
|
524
|
+
| `AuthProvider` | Autenticação e gerenciamento de sessão |
|
|
525
|
+
| `LocaleProvider` | Gerenciamento de locale (idioma, timezone, formato de data) |
|
|
526
|
+
| `TranslationLoader` | Carregamento dinâmico de traduções do banco de dados |
|
|
527
|
+
|
|
528
|
+
### Uso Básico
|
|
529
|
+
|
|
530
|
+
```tsx
|
|
531
|
+
import { CoreProviders } from 'forlogic-core';
|
|
532
|
+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
|
533
|
+
|
|
534
|
+
function App() {
|
|
535
|
+
return (
|
|
536
|
+
<CoreProviders>
|
|
537
|
+
<BrowserRouter>
|
|
538
|
+
<Routes>
|
|
539
|
+
{/* Suas rotas aqui */}
|
|
540
|
+
</Routes>
|
|
541
|
+
</BrowserRouter>
|
|
542
|
+
</CoreProviders>
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
### Com QueryClient Customizado
|
|
548
|
+
|
|
549
|
+
Se você precisar de configurações específicas para o React Query:
|
|
550
|
+
|
|
551
|
+
```tsx
|
|
552
|
+
import { CoreProviders } from 'forlogic-core';
|
|
553
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
554
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
555
|
+
|
|
556
|
+
const queryClient = new QueryClient({
|
|
557
|
+
defaultOptions: {
|
|
558
|
+
queries: {
|
|
559
|
+
staleTime: 10 * 60 * 1000, // 10 minutos
|
|
560
|
+
retry: 2,
|
|
561
|
+
refetchOnWindowFocus: false,
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
function App() {
|
|
567
|
+
return (
|
|
568
|
+
<CoreProviders queryClient={queryClient}>
|
|
569
|
+
<BrowserRouter>
|
|
570
|
+
{/* Suas rotas */}
|
|
571
|
+
</BrowserRouter>
|
|
572
|
+
</CoreProviders>
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Props
|
|
578
|
+
|
|
579
|
+
| Prop | Tipo | Obrigatório | Descrição |
|
|
580
|
+
|------|------|-------------|-----------|
|
|
581
|
+
| `children` | `ReactNode` | ✅ | Componentes filhos a serem envolvidos |
|
|
582
|
+
| `queryClient` | `QueryClient` | ❌ | Instância customizada do QueryClient. Se não fornecido, um default é criado |
|
|
583
|
+
|
|
584
|
+
### QueryClient Default
|
|
585
|
+
|
|
586
|
+
Se você não fornecer um `queryClient`, o `CoreProviders` cria um com as seguintes configurações:
|
|
587
|
+
|
|
588
|
+
```typescript
|
|
589
|
+
{
|
|
590
|
+
defaultOptions: {
|
|
591
|
+
queries: {
|
|
592
|
+
staleTime: 5 * 60 * 1000, // 5 minutos
|
|
593
|
+
retry: 1,
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
}
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
### Benefícios
|
|
600
|
+
|
|
601
|
+
- ✅ **Zero configuração de i18n** - Traduções funcionam automaticamente
|
|
602
|
+
- ✅ **Autenticação pronta** - `useAuth()` disponível em qualquer componente filho
|
|
603
|
+
- ✅ **Tratamento de erros** - ErrorBoundary captura erros de renderização
|
|
604
|
+
- ✅ **React Query configurado** - Cache e queries prontos para uso
|
|
605
|
+
- ✅ **Locale gerenciado** - Preferências de idioma, timezone e formato de data
|
|
606
|
+
- ✅ **Atualizações centralizadas** - Novos providers são adicionados automaticamente
|
|
607
|
+
|
|
608
|
+
---
|
|
609
|
+
|
|
221
610
|
<!-- AUTO_GENERATED_START -->
|
|
222
611
|
|
|
223
612
|
### 📚 Estatísticas da Documentação
|