@asteby/metacore-runtime-react 53.2.0 → 53.3.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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/license/index.d.ts +3 -1
- package/dist/license/index.d.ts.map +1 -1
- package/dist/license/index.js +3 -1
- package/dist/license/license-expiry-banner.d.ts +8 -1
- package/dist/license/license-expiry-banner.d.ts.map +1 -1
- package/dist/license/license-expiry-banner.js +96 -54
- package/dist/license/license-gate.d.ts +14 -4
- package/dist/license/license-gate.d.ts.map +1 -1
- package/dist/license/license-gate.js +75 -63
- package/dist/license/license-status-badge.d.ts.map +1 -1
- package/dist/license/license-status-badge.js +8 -9
- package/dist/license/messages.d.ts +29 -0
- package/dist/license/messages.d.ts.map +1 -0
- package/dist/license/messages.js +159 -0
- package/dist/license/types.d.ts +30 -7
- package/dist/license/types.d.ts.map +1 -1
- package/dist/license/types.js +20 -6
- package/dist/license/use-license-t.d.ts +11 -0
- package/dist/license/use-license-t.d.ts.map +1 -0
- package/dist/license/use-license-t.js +18 -0
- package/dist/license/view.d.ts +40 -0
- package/dist/license/view.d.ts.map +1 -0
- package/dist/license/view.js +62 -0
- package/package.json +1 -1
- package/src/__tests__/license-states.test.tsx +381 -0
- package/src/index.ts +13 -0
- package/src/license/index.ts +19 -0
- package/src/license/license-expiry-banner.tsx +155 -94
- package/src/license/license-gate.tsx +210 -147
- package/src/license/license-status-badge.tsx +8 -10
- package/src/license/messages.ts +185 -0
- package/src/license/types.ts +38 -6
- package/src/license/use-license-t.ts +23 -0
- package/src/license/view.ts +93 -0
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Banner de
|
|
3
|
-
*
|
|
4
|
-
* -
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
2
|
+
* Banner de licencia — la señal que acompaña a los estados que NO bloquean la
|
|
3
|
+
* app pero piden atención (ver `deriveLicenseView`):
|
|
4
|
+
* - por vencer aviso de renovación próxima
|
|
5
|
+
* - en gracia vencida, todavía se puede operar
|
|
6
|
+
* - vencida (solo lectura) / desactivada con plazo: se consulta y se exporta
|
|
7
|
+
* - hub caído sin contacto con el hub pero opera con su lease (solo dueño)
|
|
8
|
+
* - clonada licencia vista en otro servidor (solo dueño)
|
|
8
9
|
*
|
|
9
10
|
* Silencioso sin enforcement o si el estado aún no cargó — nunca rompe el shell.
|
|
11
|
+
* Descartable con TTL en localStorage, MENOS los estados de solo lectura, que se
|
|
12
|
+
* quedan fijos porque el backend ya rechaza escrituras nuevas.
|
|
10
13
|
*
|
|
11
|
-
*
|
|
12
|
-
* (re-aparecen pasado el TTL) MENOS `expired`, que se queda fijo como recordatorio
|
|
13
|
-
* porque el backend ya bloquea escrituras nuevas.
|
|
14
|
+
* Cuando la licencia trae el contacto del vendedor, se muestra en el propio aviso.
|
|
14
15
|
*/
|
|
15
16
|
import { useState } from 'react'
|
|
16
|
-
import {
|
|
17
|
-
import { AlertTriangle, Clock, CloudOff, X } from 'lucide-react'
|
|
17
|
+
import { AlertTriangle, Clock, CloudOff, Copy, X } from 'lucide-react'
|
|
18
18
|
import { Button } from '@asteby/metacore-ui'
|
|
19
|
+
import { formatLicenseDate } from './messages'
|
|
20
|
+
import { deriveLicenseView, sellerContactLine } from './view'
|
|
21
|
+
import { useLicenseT } from './use-license-t'
|
|
19
22
|
import type { LicenseState } from './types'
|
|
20
23
|
|
|
21
24
|
const DISMISS_KEY = 'license_banner_dismissed_at'
|
|
@@ -26,6 +29,17 @@ function cx(...parts: Array<string | false | undefined>): string {
|
|
|
26
29
|
return parts.filter(Boolean).join(' ')
|
|
27
30
|
}
|
|
28
31
|
|
|
32
|
+
function readDismissed(key: string): boolean {
|
|
33
|
+
try {
|
|
34
|
+
if (typeof window === 'undefined') return false
|
|
35
|
+
const raw = window.localStorage.getItem(key)
|
|
36
|
+
if (!raw) return false
|
|
37
|
+
return Date.now() - Number(raw) < DISMISS_TTL_MS
|
|
38
|
+
} catch {
|
|
39
|
+
return false // sin storage (modo privado, SSR): el aviso se muestra
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
export interface LicenseExpiryBannerProps {
|
|
30
44
|
state: LicenseState | undefined
|
|
31
45
|
/** Días de anticipación para el aviso de renovación. Default 15. */
|
|
@@ -37,6 +51,13 @@ export interface LicenseExpiryBannerProps {
|
|
|
37
51
|
onManage?: () => void
|
|
38
52
|
/** Etiqueta del botón de gestión (default localizado). */
|
|
39
53
|
manageLabel?: string
|
|
54
|
+
/** Exportar los datos (solo lectura): el host abre su flujo de exportación.
|
|
55
|
+
* Sin él, no se muestra el botón. */
|
|
56
|
+
onExport?: () => void
|
|
57
|
+
/** El usuario actual es el dueño/superadmin de la instancia. Los avisos de
|
|
58
|
+
* hub caído y de clonado son solo para él. Default false: un host que no
|
|
59
|
+
* informa el rol nunca los muestra a usuarios que no son dueños. */
|
|
60
|
+
isOwner?: boolean
|
|
40
61
|
className?: string
|
|
41
62
|
}
|
|
42
63
|
|
|
@@ -46,27 +67,30 @@ export function LicenseExpiryBanner({
|
|
|
46
67
|
dismissStorageKey = DISMISS_KEY,
|
|
47
68
|
onManage,
|
|
48
69
|
manageLabel,
|
|
70
|
+
onExport,
|
|
71
|
+
isOwner = false,
|
|
49
72
|
className,
|
|
50
73
|
}: LicenseExpiryBannerProps) {
|
|
51
|
-
const { t } =
|
|
52
|
-
const [dismissed, setDismissed] = useState(() =>
|
|
53
|
-
if (typeof window === 'undefined') return false
|
|
54
|
-
const raw = window.localStorage.getItem(dismissStorageKey)
|
|
55
|
-
if (!raw) return false
|
|
56
|
-
return Date.now() - Number(raw) < DISMISS_TTL_MS
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
if (!state || !state.enforced) return null
|
|
74
|
+
const { t, lang } = useLicenseT()
|
|
75
|
+
const [dismissed, setDismissed] = useState(() => readDismissed(dismissStorageKey))
|
|
60
76
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const isStale = state.status === 'stale'
|
|
64
|
-
const isGrace = state.status === 'grace'
|
|
65
|
-
const isExpired = state.status === 'expired'
|
|
66
|
-
if (!isUpcoming && !isStale && !isGrace && !isExpired) return null
|
|
77
|
+
const view = deriveLicenseView(state, { upcomingThresholdDays })
|
|
78
|
+
if (!state || !view) return null
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
const showMain =
|
|
81
|
+
view.condition === 'expiring' ||
|
|
82
|
+
view.condition === 'grace' ||
|
|
83
|
+
view.condition === 'hub_unreachable' ||
|
|
84
|
+
(view.condition === 'expired' && view.readOnly) ||
|
|
85
|
+
(view.condition === 'revoked' && view.readOnly) ||
|
|
86
|
+
// expired en modo bloqueo se pinta aquí solo si el host no monta el gate.
|
|
87
|
+
(view.condition === 'expired' && !view.readOnly)
|
|
88
|
+
const showClone = view.cloned && isOwner
|
|
89
|
+
const sticky = view.readOnly || view.condition === 'expired'
|
|
90
|
+
// El descarte solo oculta la fila principal no fija; la fila de clonado
|
|
91
|
+
// nunca se descarta con ella (un aviso menor no puede apagar el de clonado).
|
|
92
|
+
const mainVisible = showMain && !(view.ownerOnly && !isOwner) && !(dismissed && !sticky)
|
|
93
|
+
if (!mainVisible && !showClone) return null
|
|
70
94
|
|
|
71
95
|
const dismiss = () => {
|
|
72
96
|
setDismissed(true)
|
|
@@ -77,75 +101,112 @@ export function LicenseExpiryBanner({
|
|
|
77
101
|
}
|
|
78
102
|
}
|
|
79
103
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
defaultValue:
|
|
88
|
-
'Esta instancia no ha podido verificar su licencia con el hub. Reconéctala para completar el check-in.',
|
|
89
|
-
})
|
|
90
|
-
: isGrace
|
|
91
|
-
? t('license.banner.grace', {
|
|
92
|
-
defaultValue:
|
|
93
|
-
'Tu licencia venció y está en periodo de gracia hasta {{date}} ({{days}} días restantes).',
|
|
94
|
-
date: state.grace_until
|
|
95
|
-
? new Date(state.grace_until).toLocaleDateString()
|
|
96
|
-
: '—',
|
|
97
|
-
days: state.days_remaining,
|
|
98
|
-
})
|
|
99
|
-
: t('license.banner.upcoming', {
|
|
100
|
-
defaultValue: 'Tu licencia vence en {{days}} días.',
|
|
101
|
-
days: state.days_remaining,
|
|
102
|
-
})
|
|
104
|
+
const provider = t('license.banner.provider')
|
|
105
|
+
const who = state.seller?.name?.trim() || provider
|
|
106
|
+
const whoCap = state.seller?.name?.trim() || t('license.gate.provider')
|
|
107
|
+
const contact = sellerContactLine(state)
|
|
108
|
+
const expiredOn = formatLicenseDate(state.expires_at, lang)
|
|
109
|
+
const graceUntil = formatLicenseDate(state.grace_until, lang)
|
|
110
|
+
const lastSeen = formatLicenseDate(state.last_checked_at, lang)
|
|
103
111
|
|
|
104
|
-
const
|
|
112
|
+
const mainMessage = ((): string => {
|
|
113
|
+
switch (view.condition) {
|
|
114
|
+
case 'expiring':
|
|
115
|
+
return state.days_remaining <= 0
|
|
116
|
+
? t('license.banner.upcoming_today')
|
|
117
|
+
: state.days_remaining === 1
|
|
118
|
+
? t('license.banner.upcoming_one')
|
|
119
|
+
: t('license.banner.upcoming', { days: state.days_remaining })
|
|
120
|
+
case 'grace':
|
|
121
|
+
return expiredOn
|
|
122
|
+
? t('license.banner.grace', { date: expiredOn, days: state.days_remaining })
|
|
123
|
+
: t('license.banner.grace_nodate', { days: state.days_remaining })
|
|
124
|
+
case 'expired':
|
|
125
|
+
if (!view.readOnly) return t('license.banner.expired')
|
|
126
|
+
return expiredOn
|
|
127
|
+
? t('license.banner.expired_read_only', { date: expiredOn })
|
|
128
|
+
: t('license.banner.expired_read_only_nodate')
|
|
129
|
+
case 'revoked':
|
|
130
|
+
return graceUntil
|
|
131
|
+
? t('license.banner.revoked', { who: whoCap, date: graceUntil })
|
|
132
|
+
: t('license.banner.revoked_nodate', { who: whoCap })
|
|
133
|
+
default: // hub_unreachable
|
|
134
|
+
return lastSeen
|
|
135
|
+
? t('license.banner.stale', { date: lastSeen })
|
|
136
|
+
: t('license.banner.stale_nodate')
|
|
137
|
+
}
|
|
138
|
+
})()
|
|
139
|
+
|
|
140
|
+
const critical = view.severity === 'critical'
|
|
141
|
+
const rows: Array<{ id: string; message: string; Icon: typeof Clock; critical: boolean }> = []
|
|
142
|
+
if (mainVisible) {
|
|
143
|
+
rows.push({
|
|
144
|
+
id: 'main',
|
|
145
|
+
message: mainMessage,
|
|
146
|
+
Icon: critical ? AlertTriangle : view.condition === 'hub_unreachable' ? CloudOff : Clock,
|
|
147
|
+
critical,
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
if (showClone) {
|
|
151
|
+
rows.push({
|
|
152
|
+
id: 'clone',
|
|
153
|
+
message: t('license.banner.cloned', { who }),
|
|
154
|
+
Icon: Copy,
|
|
155
|
+
critical: false,
|
|
156
|
+
})
|
|
157
|
+
}
|
|
105
158
|
|
|
106
159
|
return (
|
|
107
|
-
<div
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
<div data-license-status={state.status} data-license-condition={view.condition} className={className}>
|
|
161
|
+
{rows.map((row, i) => (
|
|
162
|
+
<div
|
|
163
|
+
key={row.id}
|
|
164
|
+
role="alert"
|
|
165
|
+
data-license-row={row.id}
|
|
166
|
+
className={cx(
|
|
167
|
+
'flex items-center justify-between gap-3 border-b px-4 py-2.5 text-sm',
|
|
168
|
+
row.critical
|
|
169
|
+
? 'border-destructive/30 bg-destructive text-white'
|
|
170
|
+
: 'border-amber-500/30 bg-amber-500/10 text-foreground',
|
|
171
|
+
)}
|
|
172
|
+
>
|
|
173
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
174
|
+
<row.Icon className="h-4 w-4 shrink-0" aria-hidden />
|
|
175
|
+
<span className="min-w-0">
|
|
176
|
+
{row.message}
|
|
177
|
+
{row.id === 'main' && contact && (view.condition === 'expired' || view.condition === 'revoked' || view.condition === 'grace') && (
|
|
178
|
+
<span className="ml-1 opacity-90">
|
|
179
|
+
{t('license.banner.contact', { contact: `${state.seller?.name ? `${state.seller.name} · ` : ''}${contact}` })}
|
|
180
|
+
</span>
|
|
181
|
+
)}
|
|
182
|
+
</span>
|
|
183
|
+
</div>
|
|
184
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
185
|
+
{i === 0 && onExport && view.readOnly && (
|
|
186
|
+
<Button size="sm" variant="secondary" onClick={onExport}>
|
|
187
|
+
{t('license.banner.export')}
|
|
188
|
+
</Button>
|
|
189
|
+
)}
|
|
190
|
+
{i === 0 && onManage && (
|
|
191
|
+
<Button size="sm" variant={row.critical ? 'secondary' : 'outline'} onClick={onManage}>
|
|
192
|
+
{manageLabel ?? t('license.banner.manage')}
|
|
193
|
+
</Button>
|
|
194
|
+
)}
|
|
195
|
+
{row.id === 'main' && !sticky && (
|
|
196
|
+
<Button
|
|
197
|
+
size="icon"
|
|
198
|
+
variant="ghost"
|
|
199
|
+
className="h-7 w-7"
|
|
200
|
+
onClick={dismiss}
|
|
201
|
+
title={t('license.banner.dismiss')}
|
|
202
|
+
>
|
|
203
|
+
<X className="h-4 w-4" />
|
|
204
|
+
</Button>
|
|
205
|
+
)}
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
))}
|
|
149
209
|
</div>
|
|
150
210
|
)
|
|
151
211
|
}
|
|
212
|
+
|