@orbe-agro/client-core 5.6.362 → 5.6.364
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/dist/@ecme/components/template/Footer.js +1 -1
- package/dist/@ecme/store/localeStore.js +6 -1
- package/dist/@ecme/store/localeStore.js.map +1 -1
- package/dist/@ecme/store/themeStore.js +3 -0
- package/dist/@ecme/store/themeStore.js.map +1 -1
- package/dist/@types/@ecme/store/localeStore.d.ts.map +1 -1
- package/dist/@types/@ecme/store/themeStore.d.ts +2 -38
- package/dist/@types/@ecme/store/themeStore.d.ts.map +1 -1
- package/dist/@types/base/@types/clientCoreAxios.d.ts +16 -0
- package/dist/@types/base/@types/clientCoreAxios.d.ts.map +1 -0
- package/dist/@types/base/@types/globalLoadingDisplay.d.ts +16 -0
- package/dist/@types/base/@types/globalLoadingDisplay.d.ts.map +1 -0
- package/dist/@types/base/@types/index.d.ts +3 -0
- package/dist/@types/base/@types/index.d.ts.map +1 -1
- package/dist/@types/base/@types/requestFeedback/index.d.ts +80 -0
- package/dist/@types/base/@types/requestFeedback/index.d.ts.map +1 -0
- package/dist/@types/base/components/backgrounds/ParticleNetworkBackground.d.ts +4 -0
- package/dist/@types/base/components/backgrounds/ParticleNetworkBackground.d.ts.map +1 -1
- package/dist/@types/base/components/backgrounds/particleField.d.ts +33 -0
- package/dist/@types/base/components/backgrounds/particleField.d.ts.map +1 -0
- package/dist/@types/base/configs/endpoints.config/Ticket/ticket.endpoint.config.d.ts +1 -0
- package/dist/@types/base/configs/endpoints.config/Ticket/ticket.endpoint.config.d.ts.map +1 -1
- package/dist/@types/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.d.ts.map +1 -1
- package/dist/@types/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.d.ts +4 -0
- package/dist/@types/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.d.ts.map +1 -0
- package/dist/@types/base/locales/lang/ptBR/modules/Ticket/ticket.nav.d.ts +1 -0
- package/dist/@types/base/locales/lang/ptBR/modules/Ticket/ticket.nav.d.ts.map +1 -1
- package/dist/@types/base/services/axios/inheritClientCoreAxios.d.ts +2 -15
- package/dist/@types/base/services/axios/inheritClientCoreAxios.d.ts.map +1 -1
- package/dist/@types/base/services/modules/Ticket/TicketService.d.ts +1 -0
- package/dist/@types/base/services/modules/Ticket/TicketService.d.ts.map +1 -1
- package/dist/@types/base/services/requestFeedback/requestFeedbackTypes.d.ts +1 -38
- package/dist/@types/base/services/requestFeedback/requestFeedbackTypes.d.ts.map +1 -1
- package/dist/@types/base/services/requestFeedback/retryPolicy.d.ts +2 -11
- package/dist/@types/base/services/requestFeedback/retryPolicy.d.ts.map +1 -1
- package/dist/@types/base/store/globalLoadingDisplayStore.d.ts +2 -16
- package/dist/@types/base/store/globalLoadingDisplayStore.d.ts.map +1 -1
- package/dist/@types/base/store/loadingConfigStore.d.ts.map +1 -1
- package/dist/@types/base/store/preferences/animatedBackgroundStore.d.ts.map +1 -1
- package/dist/@types/base/store/requestFeedbackStore.d.ts +2 -30
- package/dist/@types/base/store/requestFeedbackStore.d.ts.map +1 -1
- package/dist/@types/base/utils/index.d.ts +1 -0
- package/dist/@types/base/utils/index.d.ts.map +1 -1
- package/dist/@types/base/utils/storage/index.d.ts +2 -0
- package/dist/@types/base/utils/storage/index.d.ts.map +1 -0
- package/dist/@types/base/utils/storage/persistVersion.d.ts +29 -0
- package/dist/@types/base/utils/storage/persistVersion.d.ts.map +1 -0
- package/dist/base/@types/clientCoreAxios.js +2 -0
- package/dist/base/@types/clientCoreAxios.js.map +1 -0
- package/dist/base/@types/globalLoadingDisplay.js +2 -0
- package/dist/base/@types/globalLoadingDisplay.js.map +1 -0
- package/dist/base/@types/index.js +3 -0
- package/dist/base/@types/index.js.map +1 -1
- package/dist/base/@types/requestFeedback/index.js +2 -0
- package/dist/base/@types/requestFeedback/index.js.map +1 -0
- package/dist/base/assets/styles/app.css +12 -7
- package/dist/base/assets/styles/init.css +12 -7
- package/dist/base/components/backgrounds/ParticleNetworkBackground.js +12 -18
- package/dist/base/components/backgrounds/ParticleNetworkBackground.js.map +1 -1
- package/dist/base/components/backgrounds/particleField.js +76 -0
- package/dist/base/components/backgrounds/particleField.js.map +1 -0
- package/dist/base/configs/endpoints.config/Ticket/ticket.endpoint.config.js +1 -0
- package/dist/base/configs/endpoints.config/Ticket/ticket.endpoint.config.js.map +1 -1
- package/dist/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.js +2 -0
- package/dist/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.js.map +1 -1
- package/dist/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.js +16 -0
- package/dist/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.js.map +1 -0
- package/dist/base/index.js +210 -208
- package/dist/base/index.js.map +1 -1
- package/dist/base/locales/lang/ptBR/modules/Ticket/ticket.nav.js +1 -0
- package/dist/base/locales/lang/ptBR/modules/Ticket/ticket.nav.js.map +1 -1
- package/dist/base/services/axios/inheritClientCoreAxios.js.map +1 -1
- package/dist/base/services/modules/Ticket/TicketService.js +8 -0
- package/dist/base/services/modules/Ticket/TicketService.js.map +1 -1
- package/dist/base/services/requestFeedback/requestFeedbackTypes.js +1 -1
- package/dist/base/services/requestFeedback/requestFeedbackTypes.js.map +1 -1
- package/dist/base/services/requestFeedback/retryPolicy.js.map +1 -1
- package/dist/base/store/globalLoadingDisplayStore.js.map +1 -1
- package/dist/base/store/loadingConfigStore.js +4 -1
- package/dist/base/store/loadingConfigStore.js.map +1 -1
- package/dist/base/store/preferences/animatedBackgroundStore.js +9 -2
- package/dist/base/store/preferences/animatedBackgroundStore.js.map +1 -1
- package/dist/base/store/requestFeedbackStore.js.map +1 -1
- package/dist/base/utils/index.js +3 -0
- package/dist/base/utils/index.js.map +1 -1
- package/dist/base/utils/storage/index.js +5 -0
- package/dist/base/utils/storage/index.js.map +1 -0
- package/dist/base/utils/storage/persistVersion.js +11 -0
- package/dist/base/utils/storage/persistVersion.js.map +1 -0
- package/lib/@ecme/store/localeStore.ts +7 -1
- package/lib/@ecme/store/themeStore.ts +4 -0
- package/lib/base/@types/clientCoreAxios.ts +15 -0
- package/lib/base/@types/globalLoadingDisplay.ts +15 -0
- package/lib/base/@types/index.ts +5 -0
- package/lib/base/@types/requestFeedback/index.ts +87 -0
- package/lib/base/assets/styles/app.css +12 -7
- package/lib/base/components/backgrounds/ParticleNetworkBackground.tsx +27 -22
- package/lib/base/components/backgrounds/particleField.test.ts +83 -0
- package/lib/base/components/backgrounds/particleField.ts +132 -0
- package/lib/base/configs/endpoints.config/Ticket/ticket.endpoint.config.ts +1 -0
- package/lib/base/configs/navigation.config/modules.submenu/Ticket/ticket.navigation.ts +2 -0
- package/lib/base/configs/navigation.config/submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu.ts +16 -0
- package/lib/base/locales/lang/ptBR/modules/Ticket/ticket.nav.ts +1 -0
- package/lib/base/services/axios/inheritClientCoreAxios.ts +2 -15
- package/lib/base/services/modules/Ticket/TicketService.ts +8 -0
- package/lib/base/services/requestFeedback/requestFeedbackTypes.ts +3 -40
- package/lib/base/services/requestFeedback/retryPolicy.ts +9 -12
- package/lib/base/store/globalLoadingDisplayStore.ts +2 -15
- package/lib/base/store/loadingConfigStore.ts +3 -0
- package/lib/base/store/preferences/animatedBackgroundStore.ts +9 -2
- package/lib/base/store/requestFeedbackStore.ts +13 -33
- package/lib/base/utils/index.ts +3 -0
- package/lib/base/utils/storage/index.ts +2 -0
- package/lib/base/utils/storage/persistVersion.test.ts +80 -0
- package/lib/base/utils/storage/persistVersion.ts +35 -0
- package/package.json +1 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/** Velocidade máxima de deriva com `speed = 1`, em px por quadro a 60 fps. */
|
|
2
|
+
export const BASE_SPEED = 0.3
|
|
3
|
+
|
|
4
|
+
export type TParticle = { x: number; y: number; vx: number; vy: number }
|
|
5
|
+
|
|
6
|
+
export type TFieldSize = { width: number; height: number }
|
|
7
|
+
|
|
8
|
+
function randomVelocity(speed: number) {
|
|
9
|
+
const angle = Math.random() * Math.PI * 2
|
|
10
|
+
const velocity = (0.3 + Math.random() * 0.7) * BASE_SPEED * speed
|
|
11
|
+
return { vx: Math.cos(angle) * velocity, vy: Math.sin(angle) * velocity }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Partícula em posição aleatória da área inteira. */
|
|
15
|
+
export function createParticle(size: TFieldSize, speed: number): TParticle {
|
|
16
|
+
return {
|
|
17
|
+
x: Math.random() * size.width,
|
|
18
|
+
y: Math.random() * size.height,
|
|
19
|
+
...randomVelocity(speed),
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Partícula na parte da área nova que não existia na anterior (a faixa que
|
|
25
|
+
* apareceu à direita ou embaixo). Assim a densidade continua uniforme sem
|
|
26
|
+
* mexer nas partículas que já estavam na tela.
|
|
27
|
+
*/
|
|
28
|
+
function createParticleInExposedArea(
|
|
29
|
+
previous: TFieldSize,
|
|
30
|
+
size: TFieldSize,
|
|
31
|
+
speed: number,
|
|
32
|
+
): TParticle {
|
|
33
|
+
const exposedRight = Math.max(0, size.width - previous.width) * size.height
|
|
34
|
+
const exposedBottom =
|
|
35
|
+
Math.max(0, size.height - previous.height) *
|
|
36
|
+
Math.min(previous.width, size.width)
|
|
37
|
+
|
|
38
|
+
if (exposedRight + exposedBottom <= 0) return createParticle(size, speed)
|
|
39
|
+
|
|
40
|
+
const inRight = Math.random() * (exposedRight + exposedBottom) < exposedRight
|
|
41
|
+
return inRight
|
|
42
|
+
? {
|
|
43
|
+
x: previous.width + Math.random() * (size.width - previous.width),
|
|
44
|
+
y: Math.random() * size.height,
|
|
45
|
+
...randomVelocity(speed),
|
|
46
|
+
}
|
|
47
|
+
: {
|
|
48
|
+
x: Math.random() * Math.min(previous.width, size.width),
|
|
49
|
+
y: previous.height + Math.random() * (size.height - previous.height),
|
|
50
|
+
...randomVelocity(speed),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isOutside = (particle: TParticle, size: TFieldSize) =>
|
|
55
|
+
particle.x < 0 ||
|
|
56
|
+
particle.y < 0 ||
|
|
57
|
+
particle.x > size.width ||
|
|
58
|
+
particle.y > size.height
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Ajusta as partículas a um novo tamanho de tela sem recomeçar a animação:
|
|
62
|
+
* as que já existem ficam onde estão e o número vai para `count`.
|
|
63
|
+
*
|
|
64
|
+
* - Faltando partículas, as novas nascem na faixa que apareceu (ou na área
|
|
65
|
+
* toda, se não há faixa nova ou se é a primeira vez).
|
|
66
|
+
* - Sobrando, saem primeiro as que ficaram fora da área nova; depois, as
|
|
67
|
+
* restantes são escolhidas ao acaso, para não abrir buracos numa região.
|
|
68
|
+
*
|
|
69
|
+
* Devolve um array novo; o de entrada não é alterado.
|
|
70
|
+
*/
|
|
71
|
+
export function fitParticles(
|
|
72
|
+
particles: TParticle[],
|
|
73
|
+
previous: TFieldSize,
|
|
74
|
+
size: TFieldSize,
|
|
75
|
+
count: number,
|
|
76
|
+
speed: number,
|
|
77
|
+
): TParticle[] {
|
|
78
|
+
const target = Math.max(0, Math.round(count))
|
|
79
|
+
const isFirstFit = particles.length === 0 || previous.width <= 0 || previous.height <= 0
|
|
80
|
+
|
|
81
|
+
if (particles.length < target) {
|
|
82
|
+
const added = Array.from({ length: target - particles.length }, () =>
|
|
83
|
+
isFirstFit
|
|
84
|
+
? createParticle(size, speed)
|
|
85
|
+
: createParticleInExposedArea(previous, size, speed),
|
|
86
|
+
)
|
|
87
|
+
return [...particles, ...added]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (particles.length > target) {
|
|
91
|
+
const inside = particles.filter((particle) => !isOutside(particle, size))
|
|
92
|
+
const outside = particles.filter((particle) => isOutside(particle, size))
|
|
93
|
+
if (inside.length >= target) {
|
|
94
|
+
return shuffleTake(inside, target)
|
|
95
|
+
}
|
|
96
|
+
return [...inside, ...shuffleTake(outside, target - inside.length)]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return [...particles]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `amount` itens ao acaso, mantendo a ordem relativa dos que ficam. */
|
|
103
|
+
function shuffleTake<T>(items: T[], amount: number): T[] {
|
|
104
|
+
if (amount >= items.length) return [...items]
|
|
105
|
+
const keep = new Set<number>()
|
|
106
|
+
while (keep.size < amount) {
|
|
107
|
+
keep.add(Math.floor(Math.random() * items.length))
|
|
108
|
+
}
|
|
109
|
+
return items.filter((_, index) => keep.has(index))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Ajusta a velocidade das partículas a uma nova opção `speed`, mantendo a
|
|
114
|
+
* direção. Saindo de `speed = 0` (paradas, sem direção), sorteia velocidades
|
|
115
|
+
* novas.
|
|
116
|
+
*/
|
|
117
|
+
export function rescaleSpeed(
|
|
118
|
+
particles: TParticle[],
|
|
119
|
+
previousSpeed: number,
|
|
120
|
+
speed: number,
|
|
121
|
+
): TParticle[] {
|
|
122
|
+
if (previousSpeed === speed) return particles
|
|
123
|
+
if (previousSpeed <= 0) {
|
|
124
|
+
return particles.map((particle) => ({ ...particle, ...randomVelocity(speed) }))
|
|
125
|
+
}
|
|
126
|
+
const factor = speed / previousSpeed
|
|
127
|
+
return particles.map((particle) => ({
|
|
128
|
+
...particle,
|
|
129
|
+
vx: particle.vx * factor,
|
|
130
|
+
vy: particle.vy * factor,
|
|
131
|
+
}))
|
|
132
|
+
}
|
|
@@ -5,6 +5,7 @@ const ticketEndpointConfig = {
|
|
|
5
5
|
countAll: `${TICKET_API_PATH}/count`,
|
|
6
6
|
findAll: `${TICKET_API_PATH}/find`,
|
|
7
7
|
exportExcel: `${TICKET_API_PATH}/export-excel`,
|
|
8
|
+
findNfeTransporteNaoUtilizadas: `${TICKET_API_PATH}/find-nfe-transporte-nao-utilizadas`,
|
|
8
9
|
findOne: `${TICKET_API_PATH}/`,
|
|
9
10
|
cancel: `${TICKET_API_PATH}/cancel`,
|
|
10
11
|
getPdf: `${TICKET_API_PATH}/pdf/`,
|
|
@@ -6,6 +6,7 @@ import monitorCompraRemessaArmazemTerceiroSubmenu from '../../submenu/ticket/con
|
|
|
6
6
|
import ticketSubmenu from '../../submenu/ticket/config/ticket.submenu'
|
|
7
7
|
import relatoriosSubmenu from '../../submenu/ticket/relatorios.submenu'
|
|
8
8
|
import cadastrosSubmenu from '../../submenu/ticket/cadastros.submenu'
|
|
9
|
+
import monitorNfeTransporteNaoUtilizadaSubmenu from '../../submenu/ticket/config/monitorNfeTransporteNaoUtilizadas.submenu'
|
|
9
10
|
|
|
10
11
|
const ticketNavigationConfig: NavigationTree[] = [
|
|
11
12
|
{
|
|
@@ -19,6 +20,7 @@ const ticketNavigationConfig: NavigationTree[] = [
|
|
|
19
20
|
subMenu: [
|
|
20
21
|
{ ...monitorCarregamentoSubmenu, sortOrder: 1 },
|
|
21
22
|
{ ...monitorCompraRemessaArmazemTerceiroSubmenu, sortOrder: 2 },
|
|
23
|
+
{ ...monitorNfeTransporteNaoUtilizadaSubmenu },
|
|
22
24
|
{ ...ticketSubmenu, sortOrder: 3 },
|
|
23
25
|
{
|
|
24
26
|
key: 'ticket.relatorios',
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NAV_ITEM_TYPE_ITEM } from '@/constants/navigation.constant'
|
|
2
|
+
import { ADMIN } from '@/constants/roles.constant'
|
|
3
|
+
import { NavigationTree } from '@/@types/navigation'
|
|
4
|
+
|
|
5
|
+
const monitorNfeTransporteNaoUtilizadaSubmenu: NavigationTree = {
|
|
6
|
+
key: 'ticket.monitor.nfeTransporteNaoUtilizada',
|
|
7
|
+
path: '/ticket/monitor/nfe-transporte-nao-utilizada',
|
|
8
|
+
title: 'Monitor de NFe de Transporte Não Utilizada',
|
|
9
|
+
translateKey: 'nav.modules.ticket.monitorNfeTransporteNaoUtilizada',
|
|
10
|
+
icon: '',
|
|
11
|
+
type: NAV_ITEM_TYPE_ITEM,
|
|
12
|
+
authority: [ADMIN],
|
|
13
|
+
subMenu: [],
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default monitorNfeTransporteNaoUtilizadaSubmenu
|
|
@@ -13,6 +13,7 @@ export default {
|
|
|
13
13
|
toleranciaDiferencaBiodiesel: 'Tolerância de Diferença do Biodiesel',
|
|
14
14
|
vinculoProdutoOperacao: 'Vínculo de Produto e Operação',
|
|
15
15
|
monitorCompraRemessaArmazemTerceiro: 'Monitor de Compra e Remessa/Armazem Terceiro',
|
|
16
|
+
monitorNfeTransporteNaoUtilizada: 'Monitor de NFe de Transporte Não Utilizada',
|
|
16
17
|
vinculoProdutorOperacao: 'Vínculo de Produtor e Operação',
|
|
17
18
|
extratoProdutor: 'Extrato Produtor',
|
|
18
19
|
vinculoDepositoOperacao: 'Vínculo de Depósito e Operação',
|
|
@@ -4,22 +4,9 @@ import AxiosRequestIntrceptorConfigCallback from '@/services/axios/AxiosRequestI
|
|
|
4
4
|
import AxiosResponseIntrceptorErrorCallback from '@/services/axios/AxiosResponseIntrceptorErrorCallback'
|
|
5
5
|
import { API_URL } from '@base/configs/api.config'
|
|
6
6
|
import installRequestFeedback from '@base/services/requestFeedback/installRequestFeedback'
|
|
7
|
+
import type { TClientCoreAxiosInheritance } from '@base/@types/clientCoreAxios'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
* Comportamentos do axios do client-core que uma instância própria do projeto
|
|
10
|
-
* (ex.: o `AppAxiosBase` de um microfrontend) pode herdar. Cada projeto mantém
|
|
11
|
-
* a sua instância, para recursos e decisões próprios, e escolhe o que herda
|
|
12
|
-
* por uma variável de configuração.
|
|
13
|
-
*/
|
|
14
|
-
export type TClientCoreAxiosInheritance = {
|
|
15
|
-
/**
|
|
16
|
-
* Autenticação: headers da sessão em toda requisição, sessão em cookies
|
|
17
|
-
* (refresh e repetição), 401/403 (encerra a sessão ou vai para acesso negado).
|
|
18
|
-
*/
|
|
19
|
-
auth?: boolean
|
|
20
|
-
/** Plug-in de feedback das requisições (ver `installRequestFeedback`). */
|
|
21
|
-
requestFeedback?: boolean
|
|
22
|
-
}
|
|
9
|
+
export type { TClientCoreAxiosInheritance } from '@base/@types/clientCoreAxios'
|
|
23
10
|
|
|
24
11
|
/**
|
|
25
12
|
* Aplica numa instância existente o que ela herda do client-core. Devolve uma
|
|
@@ -25,6 +25,14 @@ export async function apiExportExcel(body) {
|
|
|
25
25
|
})
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export async function apiGetNfeTransporteNaoUtilizadas(body) {
|
|
29
|
+
return ApiService.fetchDataWithAxios({
|
|
30
|
+
url: ticketEndpointConfig.findNfeTransporteNaoUtilizadas,
|
|
31
|
+
method: 'post',
|
|
32
|
+
data: body,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
export function apiGetTicket(id) {
|
|
29
37
|
return ApiService.fetchDataWithAxios({
|
|
30
38
|
url: ticketEndpointConfig.findOne + id,
|
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* O plug-in não repete requisições. Quem repete é quem chama (SWR, React Query,
|
|
5
|
-
* um botão de recarregar), seguindo a regra de negócio da chamada. O plug-in só
|
|
6
|
-
* percebe que a mesma requisição está sendo tentada de novo e troca o loading
|
|
7
|
-
* de tela cheia por um aviso que não bloqueia a tela.
|
|
8
|
-
*/
|
|
9
|
-
export type TRequestFeedbackOptions = {
|
|
10
|
-
/**
|
|
11
|
-
* Novas tentativas não bloqueiam a tela e mostram "Tentando novamente".
|
|
12
|
-
* Padrão: `true`.
|
|
13
|
-
*/
|
|
14
|
-
retry?: boolean
|
|
15
|
-
/** Aviso de "não encontrado" quando a resposta é 404. Padrão: `true`. */
|
|
16
|
-
notFound?: boolean
|
|
17
|
-
/** Aviso de "requisição inválida" quando a resposta é 400. Padrão: `true`. */
|
|
18
|
-
badRequest?: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Tipos de aviso exibidos para respostas que não adianta repetir */
|
|
22
|
-
export type TRequestNoticeKind = 'notFound' | 'badRequest'
|
|
23
|
-
|
|
24
|
-
declare module 'axios' {
|
|
25
|
-
interface AxiosRequestConfig {
|
|
26
|
-
/**
|
|
27
|
-
* Nome amigável da requisição, exibido ao usuário (ex.: "Documentos do
|
|
28
|
-
* produtor"). É só um dado: sozinho não muda nenhum comportamento.
|
|
29
|
-
*/
|
|
30
|
-
label?: string
|
|
31
|
-
/**
|
|
32
|
-
* Liga o plug-in de feedback nesta requisição (opt-in). Só tem efeito
|
|
33
|
-
* nas instâncias com `installRequestFeedback` e com o plug-in ligado no
|
|
34
|
-
* frontend (`configureRequestFeedback({ enabled: true })`).
|
|
35
|
-
*/
|
|
36
|
-
requestFeedback?: boolean | TRequestFeedbackOptions
|
|
37
|
-
/** Uso interno do plug-in: identifica a requisição entre tentativas. */
|
|
38
|
-
requestFeedbackKey?: string
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
// Tipos do plug-in de feedback das requisições, mantidos aqui para quem já
|
|
2
|
+
// importava deste caminho. A definição fica em `@base/@types/requestFeedback`.
|
|
3
|
+
export * from '@base/@types/requestFeedback'
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { AxiosError } from 'axios'
|
|
2
|
+
import type {
|
|
3
|
+
TRetryPolicyOptions,
|
|
4
|
+
TSwrRetryPolicyOptions,
|
|
5
|
+
} from '@base/@types/requestFeedback'
|
|
6
|
+
|
|
7
|
+
export type {
|
|
8
|
+
TRetryPolicyOptions,
|
|
9
|
+
TSwrRetryPolicyOptions,
|
|
10
|
+
} from '@base/@types/requestFeedback'
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* Regras de nova tentativa para quem chama a API. A decisão de repetir continua
|
|
@@ -11,13 +20,6 @@ import type { AxiosError } from 'axios'
|
|
|
11
20
|
|
|
12
21
|
export const NON_RETRYABLE_STATUSES = [400, 404]
|
|
13
22
|
|
|
14
|
-
export type TRetryPolicyOptions = {
|
|
15
|
-
/** Quantas novas tentativas, além da primeira chamada. */
|
|
16
|
-
maxRetries?: number
|
|
17
|
-
/** Status HTTP que não são repetidos. Padrão: 400 e 404. */
|
|
18
|
-
nonRetryableStatuses?: number[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
23
|
/** Status HTTP do erro, quando houver resposta do servidor. */
|
|
22
24
|
export function getErrorStatus(error: unknown): number | undefined {
|
|
23
25
|
return (error as AxiosError | undefined)?.response?.status
|
|
@@ -48,11 +50,6 @@ export function queryRetryPolicy({
|
|
|
48
50
|
type TSwrRetryConfig = { errorRetryInterval: number }
|
|
49
51
|
type TSwrRevalidate = (options: { retryCount: number }) => unknown
|
|
50
52
|
|
|
51
|
-
export type TSwrRetryPolicyOptions = TRetryPolicyOptions & {
|
|
52
|
-
/** Intervalo base entre tentativas (ms). Padrão: `errorRetryInterval` do SWR. */
|
|
53
|
-
intervalMs?: number
|
|
54
|
-
}
|
|
55
|
-
|
|
56
53
|
/**
|
|
57
54
|
* Regra para o `onErrorRetry` do SWR
|
|
58
55
|
* (`useSWR(key, fetcher, { ...swrRetryPolicy({ maxRetries: 2 }) })`).
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { create } from 'zustand'
|
|
2
|
+
import type { TGlobalLoadingDisplayConfig } from '@base/@types/globalLoadingDisplay'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
* Exibição do loading global de tela cheia (`GlobalLoading`). Não é persistido.
|
|
5
|
-
*
|
|
6
|
-
* Com os padrões (`0`), o loading aparece e some junto com as requisições,
|
|
7
|
-
* como sempre foi. Os atrasos são opt-in por frontend.
|
|
8
|
-
*/
|
|
9
|
-
export type TGlobalLoadingDisplayConfig = {
|
|
10
|
-
/**
|
|
11
|
-
* Só mostra o loading se as requisições passarem deste tempo (ms). Evita o
|
|
12
|
-
* piscar em requisições rápidas, inclusive nas que falham na hora.
|
|
13
|
-
*/
|
|
14
|
-
showDelayMs: number
|
|
15
|
-
/** Depois de aparecer, o loading fica pelo menos este tempo (ms). */
|
|
16
|
-
minVisibleMs: number
|
|
17
|
-
}
|
|
4
|
+
export type { TGlobalLoadingDisplayConfig } from '@base/@types/globalLoadingDisplay'
|
|
18
5
|
|
|
19
6
|
export const DEFAULT_GLOBAL_LOADING_DISPLAY_CONFIG: TGlobalLoadingDisplayConfig =
|
|
20
7
|
{
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
import { persist } from "zustand/middleware";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
+
import persistVersion from "@base/utils/storage/persistVersion";
|
|
4
5
|
|
|
5
6
|
// Configurações por microfrontend
|
|
6
7
|
interface MicrofrontendLoadingConfig {
|
|
@@ -49,6 +50,8 @@ export const useLoadingConfigStore = create<LoadingConfigState & LoadingConfigAc
|
|
|
49
50
|
}),
|
|
50
51
|
{
|
|
51
52
|
name: "loading-config",
|
|
53
|
+
// Versão 1 mantém o que foi gravado antes de haver versão (0)
|
|
54
|
+
...persistVersion<LoadingConfigState & LoadingConfigActions>(1, { keepFrom: [0] }),
|
|
52
55
|
}
|
|
53
56
|
)
|
|
54
57
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { create } from 'zustand'
|
|
2
2
|
import { persist } from 'zustand/middleware'
|
|
3
|
+
import persistVersion from '@base/utils/storage/persistVersion'
|
|
3
4
|
|
|
4
5
|
/** Fundos animados disponíveis no `AnimatedBackground`. `nenhum` desliga a animação. */
|
|
5
6
|
export type TAnimatedBackgroundId = 'none' | 'network' | 'particles'
|
|
@@ -18,9 +19,15 @@ export const useAnimatedBackgroundStore = create<
|
|
|
18
19
|
>()(
|
|
19
20
|
persist(
|
|
20
21
|
(set) => ({
|
|
21
|
-
backgroundId: '
|
|
22
|
+
backgroundId: 'none',
|
|
22
23
|
setBackgroundId: (backgroundId) => set(() => ({ backgroundId })),
|
|
23
24
|
}),
|
|
24
|
-
{
|
|
25
|
+
{
|
|
26
|
+
name: 'animatedBackground',
|
|
27
|
+
// Versão 1 mantém o que foi gravado antes de haver versão (0)
|
|
28
|
+
...persistVersion<TAnimatedBackgroundState & TAnimatedBackgroundAction>(1, {
|
|
29
|
+
keepFrom: [0],
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
25
32
|
),
|
|
26
33
|
)
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { create } from 'zustand'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
TRequestFeedbackConfig,
|
|
4
|
+
TRequestNotice,
|
|
5
|
+
TRequestNoticeKind,
|
|
6
|
+
TRetryEntry,
|
|
7
|
+
} from '@base/@types/requestFeedback'
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
TRequestFeedbackConfig,
|
|
11
|
+
TRequestNotice,
|
|
12
|
+
TRetryEntry,
|
|
13
|
+
TRetryEntryStatus,
|
|
14
|
+
} from '@base/@types/requestFeedback'
|
|
3
15
|
|
|
4
16
|
/**
|
|
5
17
|
* Estado do plug-in de feedback das requisições (`installRequestFeedback`).
|
|
@@ -9,38 +21,6 @@ import type { TRequestNoticeKind } from '@base/services/requestFeedback/requestF
|
|
|
9
21
|
* `configureRequestFeedback`.
|
|
10
22
|
*/
|
|
11
23
|
|
|
12
|
-
export type TRequestFeedbackConfig = {
|
|
13
|
-
/** Liga o plug-in neste frontend. Desligado por padrão. */
|
|
14
|
-
enabled: boolean
|
|
15
|
-
/**
|
|
16
|
-
* Quanto tempo (ms) o aviso de nova tentativa espera pela próxima tentativa
|
|
17
|
-
* depois de uma falha. Sem nova tentativa nesse tempo, o aviso some e a
|
|
18
|
-
* próxima chamada volta a ser tratada como primeira tentativa.
|
|
19
|
-
*/
|
|
20
|
-
retryLingerMs: number
|
|
21
|
-
/** Quanto tempo (ms) os avisos de 400 e 404 ficam visíveis. `0` mantém até fechar. */
|
|
22
|
-
noticeDurationMs: number
|
|
23
|
-
/** Quantos avisos de 400 e 404 ficam visíveis ao mesmo tempo. */
|
|
24
|
-
maxNotices: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type TRetryEntryStatus = 'retrying' | 'waiting'
|
|
28
|
-
|
|
29
|
-
export type TRetryEntry = {
|
|
30
|
-
key: string
|
|
31
|
-
label?: string
|
|
32
|
-
/** Tentativa atual: 1 é a primeira chamada, 2 a primeira nova tentativa... */
|
|
33
|
-
attempt: number
|
|
34
|
-
/** `retrying`: tentativa em andamento; `waiting`: falhou e aguarda a próxima. */
|
|
35
|
-
status: TRetryEntryStatus
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type TRequestNotice = {
|
|
39
|
-
id: number
|
|
40
|
-
kind: TRequestNoticeKind
|
|
41
|
-
label?: string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
24
|
type TRequestFeedbackState = {
|
|
45
25
|
config: TRequestFeedbackConfig
|
|
46
26
|
retries: Record<string, TRetryEntry>
|
package/lib/base/utils/index.ts
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { create } from 'zustand'
|
|
3
|
+
import { persist } from 'zustand/middleware'
|
|
4
|
+
import persistVersion from './persistVersion'
|
|
5
|
+
|
|
6
|
+
type TState = { color: string; setColor: (color: string) => void }
|
|
7
|
+
|
|
8
|
+
const KEY = 'persist-version-test'
|
|
9
|
+
|
|
10
|
+
const createStore = (version: number, keepFrom: number[]) =>
|
|
11
|
+
create<TState>()(
|
|
12
|
+
persist(
|
|
13
|
+
(set) => ({ color: 'default', setColor: (color) => set({ color }) }),
|
|
14
|
+
{ name: KEY, ...persistVersion<TState>(version, { keepFrom }) },
|
|
15
|
+
),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const save = (state: object, version?: number) =>
|
|
19
|
+
localStorage.setItem(
|
|
20
|
+
KEY,
|
|
21
|
+
JSON.stringify(version === undefined ? { state } : { state, version }),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const stored = () => JSON.parse(localStorage.getItem(KEY) ?? 'null')
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
localStorage.clear()
|
|
28
|
+
vi.restoreAllMocks()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('persistVersion', () => {
|
|
32
|
+
it('mantém o que foi gravado numa versão de keepFrom e regrava na versão nova', () => {
|
|
33
|
+
save({ color: 'blue' }, 0)
|
|
34
|
+
|
|
35
|
+
const store = createStore(1, [0])
|
|
36
|
+
|
|
37
|
+
expect(store.getState().color).toBe('blue')
|
|
38
|
+
expect(stored()).toEqual({ state: { color: 'blue' }, version: 1 })
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('mesma versão: carrega sem migrar', () => {
|
|
42
|
+
save({ color: 'green' }, 1)
|
|
43
|
+
|
|
44
|
+
expect(createStore(1, [0]).getState().color).toBe('green')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('versão fora de keepFrom: descarta e começa do padrão', () => {
|
|
48
|
+
save({ color: 'blue' }, 1)
|
|
49
|
+
|
|
50
|
+
const store = createStore(2, [])
|
|
51
|
+
|
|
52
|
+
expect(store.getState().color).toBe('default')
|
|
53
|
+
expect(stored()).toEqual({ state: { color: 'default' }, version: 2 })
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('a nova versão volta a gravar normalmente depois de migrar', () => {
|
|
57
|
+
save({ color: 'blue' }, 0)
|
|
58
|
+
const store = createStore(1, [0])
|
|
59
|
+
|
|
60
|
+
store.getState().setColor('red')
|
|
61
|
+
|
|
62
|
+
expect(stored()).toEqual({ state: { color: 'red' }, version: 1 })
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('um client-core antigo (versão 0, sem migrate) ignora o estado da versão 1', () => {
|
|
66
|
+
vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
67
|
+
save({ color: 'blue' }, 1)
|
|
68
|
+
|
|
69
|
+
const oldStore = create<TState>()(
|
|
70
|
+
persist(
|
|
71
|
+
(set) => ({ color: 'default', setColor: (color) => set({ color }) }),
|
|
72
|
+
{ name: KEY },
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
// É o cenário dos microfrontends ainda não publicados com esta versão
|
|
77
|
+
expect(oldStore.getState().color).toBe('default')
|
|
78
|
+
expect(stored().version).toBe(1)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opções `version` e `migrate` para o `persist` do zustand.
|
|
3
|
+
*
|
|
4
|
+
* O zustand compara o `version` gravado no localStorage com o do store. Quando
|
|
5
|
+
* são diferentes, chama `migrate`; aqui, o estado gravado é mantido se veio de
|
|
6
|
+
* uma versão em `keepFrom` e descartado (o store começa do padrão) nos outros
|
|
7
|
+
* casos.
|
|
8
|
+
*
|
|
9
|
+
* Para uma mudança que quebra o formato gravado, suba `version` e deixe a
|
|
10
|
+
* versão antiga fora de `keepFrom`: na próxima carga, o dado antigo é
|
|
11
|
+
* descartado.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* persist(creator, { name: 'theme', ...persistVersion(1, { keepFrom: [0] }) })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Os microfrontends compartilham o localStorage e não são publicados ao mesmo
|
|
18
|
+
* tempo. Um microfrontend com um client-core mais antigo (versão menor, sem
|
|
19
|
+
* `migrate` para a nova) ignora o estado gravado na versão nova e usa o padrão
|
|
20
|
+
* até ser publicado de novo. Por isso, os stores de sessão ainda não têm versão.
|
|
21
|
+
*/
|
|
22
|
+
export function persistVersion<TState>(
|
|
23
|
+
version: number,
|
|
24
|
+
{ keepFrom = [] }: { keepFrom?: number[] } = {},
|
|
25
|
+
) {
|
|
26
|
+
return {
|
|
27
|
+
version,
|
|
28
|
+
migrate: (persistedState: unknown, persistedVersion: number) =>
|
|
29
|
+
(keepFrom.includes(persistedVersion)
|
|
30
|
+
? persistedState
|
|
31
|
+
: undefined) as TState,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default persistVersion
|
package/package.json
CHANGED