@asteby/metacore-runtime-react 23.9.2 → 23.10.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 +19 -0
- package/README.md +43 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +122 -0
- package/dist/dynamic-kanban.d.ts.map +1 -1
- package/dist/dynamic-kanban.js +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/license/index.d.ts +5 -0
- package/dist/license/index.d.ts.map +1 -0
- package/dist/license/index.js +4 -0
- package/dist/license/license-expiry-banner.d.ts +16 -0
- package/dist/license/license-expiry-banner.d.ts.map +1 -0
- package/dist/license/license-expiry-banner.js +85 -0
- package/dist/license/license-gate.d.ts +40 -0
- package/dist/license/license-gate.d.ts.map +1 -0
- package/dist/license/license-gate.js +108 -0
- package/dist/license/license-status-badge.d.ts +7 -0
- package/dist/license/license-status-badge.d.ts.map +1 -0
- package/dist/license/license-status-badge.js +57 -0
- package/dist/license/types.d.ts +63 -0
- package/dist/license/types.d.ts.map +1 -0
- package/dist/license/types.js +45 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/use-i18n-resource-version.d.ts +2 -0
- package/dist/use-i18n-resource-version.d.ts.map +1 -0
- package/dist/use-i18n-resource-version.js +42 -0
- package/package.json +3 -3
- package/src/__tests__/license-gate.test.tsx +242 -0
- package/src/__tests__/wizard-action-modal.test.tsx +121 -0
- package/src/action-modal-dispatcher.tsx +233 -0
- package/src/dynamic-kanban.tsx +6 -0
- package/src/index.ts +15 -0
- package/src/license/index.ts +21 -0
- package/src/license/license-expiry-banner.tsx +151 -0
- package/src/license/license-gate.tsx +277 -0
- package/src/license/license-status-badge.tsx +93 -0
- package/src/license/types.ts +90 -0
- package/src/types.ts +9 -0
- package/src/use-i18n-resource-version.ts +42 -0
- package/LICENSE +0 -201
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <LicenseGate> — el primitivo del blindaje. Un host lo monta en UNA línea
|
|
3
|
+
* envolviendo su app autenticada:
|
|
4
|
+
*
|
|
5
|
+
* <LicenseGate state={state} onActivate={activate}>
|
|
6
|
+
* <AppShell />
|
|
7
|
+
* </LicenseGate>
|
|
8
|
+
*
|
|
9
|
+
* Comportamiento según el estado (resuelto por el backend del host):
|
|
10
|
+
* - Sin enforcement, o estado operable (valid/stale/grace) → renderiza children.
|
|
11
|
+
* stale/grace además montan el <LicenseExpiryBanner> degradado por encima.
|
|
12
|
+
* - enforcement && missing/invalid/expired → modal BLOQUEANTE full-screen,
|
|
13
|
+
* no descartable, con el formulario de activación. Al activar con éxito el
|
|
14
|
+
* host refresca el estado y el gate se abre sin recargar.
|
|
15
|
+
*
|
|
16
|
+
* Es branding-aware si el host pasa `branding` (logo/nombre desde el
|
|
17
|
+
* PlatformConfig del SDK); si no, cae a un encabezado neutro.
|
|
18
|
+
*
|
|
19
|
+
* INDEPENDIENTE del kernel: no importa su cliente ni fija su versión. Solo
|
|
20
|
+
* consume `LicenseState` y una promesa `onActivate`.
|
|
21
|
+
*/
|
|
22
|
+
import { useState, type ReactNode } from 'react'
|
|
23
|
+
import { useTranslation } from 'react-i18next'
|
|
24
|
+
import { ShieldAlert, Clock, Loader2 } from 'lucide-react'
|
|
25
|
+
import { Button, Input } from '@asteby/metacore-ui'
|
|
26
|
+
import {
|
|
27
|
+
isLicenseBlocking,
|
|
28
|
+
isTrialExpired,
|
|
29
|
+
type LicenseState,
|
|
30
|
+
type LicenseBranding,
|
|
31
|
+
} from './types'
|
|
32
|
+
import { LicenseStatusBadge } from './license-status-badge'
|
|
33
|
+
import { LicenseExpiryBanner } from './license-expiry-banner'
|
|
34
|
+
|
|
35
|
+
function cx(...parts: Array<string | false | undefined>): string {
|
|
36
|
+
return parts.filter(Boolean).join(' ')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface LicenseGateProps {
|
|
40
|
+
/** Estado actual, resuelto por el backend del host. `undefined` mientras
|
|
41
|
+
* carga → fail-open (renderiza children, nunca destella el candado). */
|
|
42
|
+
state: LicenseState | undefined
|
|
43
|
+
/** Activa una licencia con el código/token pegado. Resuelve → el host
|
|
44
|
+
* refresca `state` y el gate se abre. Rechaza con un Error cuyo `message`
|
|
45
|
+
* se muestra al usuario. */
|
|
46
|
+
onActivate: (code: string) => Promise<void>
|
|
47
|
+
children: ReactNode
|
|
48
|
+
/** Branding opcional (logo/nombre) para el encabezado del modal. */
|
|
49
|
+
branding?: LicenseBranding
|
|
50
|
+
/** Acción "Gestionar licencia" del banner degradado (opcional). */
|
|
51
|
+
onManage?: () => void
|
|
52
|
+
className?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function LicenseGate({
|
|
56
|
+
state,
|
|
57
|
+
onActivate,
|
|
58
|
+
children,
|
|
59
|
+
branding,
|
|
60
|
+
onManage,
|
|
61
|
+
className,
|
|
62
|
+
}: LicenseGateProps) {
|
|
63
|
+
const blocking = isLicenseBlocking(state)
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
{/* stale/grace/upcoming degradan con banner; el propio banner
|
|
68
|
+
decide si mostrarse. Bloqueado → no hace falta, el modal manda. */}
|
|
69
|
+
{!blocking && (
|
|
70
|
+
<LicenseExpiryBanner state={state} onManage={onManage} />
|
|
71
|
+
)}
|
|
72
|
+
{children}
|
|
73
|
+
{blocking && state && (
|
|
74
|
+
<LicenseGateModal
|
|
75
|
+
state={state}
|
|
76
|
+
onActivate={onActivate}
|
|
77
|
+
branding={branding}
|
|
78
|
+
className={className}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface LicenseGateModalProps {
|
|
86
|
+
state: LicenseState
|
|
87
|
+
onActivate: (code: string) => Promise<void>
|
|
88
|
+
branding?: LicenseBranding
|
|
89
|
+
className?: string
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function LicenseGateModal({
|
|
93
|
+
state,
|
|
94
|
+
onActivate,
|
|
95
|
+
branding,
|
|
96
|
+
className,
|
|
97
|
+
}: LicenseGateModalProps) {
|
|
98
|
+
const { t } = useTranslation()
|
|
99
|
+
const [code, setCode] = useState('')
|
|
100
|
+
const [submitting, setSubmitting] = useState(false)
|
|
101
|
+
const [error, setError] = useState<string | null>(null)
|
|
102
|
+
|
|
103
|
+
const trialExpired = isTrialExpired(state)
|
|
104
|
+
|
|
105
|
+
const title = trialExpired
|
|
106
|
+
? t('license.gate.trial_title', {
|
|
107
|
+
defaultValue: 'Tu prueba gratuita terminó',
|
|
108
|
+
})
|
|
109
|
+
: t('license.gate.title', { defaultValue: 'Activa tu licencia' })
|
|
110
|
+
|
|
111
|
+
const description = trialExpired
|
|
112
|
+
? t('license.gate.trial_description', {
|
|
113
|
+
defaultValue:
|
|
114
|
+
'Tu prueba gratuita terminó. Activa una licencia para continuar. Pega tu clave (lic_…) o el token firmado que te entregaron.',
|
|
115
|
+
})
|
|
116
|
+
: state.status === 'expired'
|
|
117
|
+
? t('license.gate.expired_description', {
|
|
118
|
+
defaultValue:
|
|
119
|
+
'Tu licencia venció y el periodo de gracia terminó. Activa una licencia vigente para seguir operando. Pega tu clave (lic_…) o el token firmado.',
|
|
120
|
+
})
|
|
121
|
+
: state.status === 'invalid'
|
|
122
|
+
? t('license.gate.invalid_description', {
|
|
123
|
+
defaultValue:
|
|
124
|
+
'La licencia de esta instancia no es válida. Pega una clave (lic_…) o el token firmado que te entregó tu proveedor para reactivarla.',
|
|
125
|
+
})
|
|
126
|
+
: t('license.gate.missing_description', {
|
|
127
|
+
defaultValue:
|
|
128
|
+
'Esta instancia necesita una licencia activa para operar. Pega tu clave (lic_…) o el token firmado para activarla.',
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const canSubmit = code.trim().length > 0 && !submitting
|
|
132
|
+
|
|
133
|
+
const submit = async () => {
|
|
134
|
+
if (!canSubmit) return
|
|
135
|
+
setSubmitting(true)
|
|
136
|
+
setError(null)
|
|
137
|
+
try {
|
|
138
|
+
await onActivate(code.trim())
|
|
139
|
+
// Éxito → el host refresca `state`; el gate se re-renderiza y este
|
|
140
|
+
// modal se desmonta solo. No recargamos.
|
|
141
|
+
} catch (e) {
|
|
142
|
+
const message =
|
|
143
|
+
e instanceof Error && e.message
|
|
144
|
+
? e.message
|
|
145
|
+
: t('license.gate.activate_error', {
|
|
146
|
+
defaultValue: 'No se pudo activar la licencia.',
|
|
147
|
+
})
|
|
148
|
+
setError(message)
|
|
149
|
+
setSubmitting(false)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<div
|
|
155
|
+
role="dialog"
|
|
156
|
+
aria-modal="true"
|
|
157
|
+
aria-labelledby="license-gate-title"
|
|
158
|
+
data-license-status={state.status}
|
|
159
|
+
className={cx(
|
|
160
|
+
'fixed inset-0 z-[100] flex items-center justify-center bg-background/90 p-4 backdrop-blur-sm',
|
|
161
|
+
className,
|
|
162
|
+
)}
|
|
163
|
+
>
|
|
164
|
+
<div className="w-full max-w-lg overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-2xl">
|
|
165
|
+
<div className="flex flex-col gap-4 p-6">
|
|
166
|
+
<div className="flex items-start gap-3">
|
|
167
|
+
{branding?.logo ? (
|
|
168
|
+
<img
|
|
169
|
+
src={branding.logo}
|
|
170
|
+
alt={branding.name ?? ''}
|
|
171
|
+
className="h-10 w-10 shrink-0 rounded-xl object-contain"
|
|
172
|
+
/>
|
|
173
|
+
) : (
|
|
174
|
+
<div
|
|
175
|
+
className={cx(
|
|
176
|
+
'flex h-10 w-10 shrink-0 items-center justify-center rounded-xl',
|
|
177
|
+
trialExpired
|
|
178
|
+
? 'bg-primary/10 text-primary'
|
|
179
|
+
: 'bg-destructive/10 text-destructive',
|
|
180
|
+
)}
|
|
181
|
+
>
|
|
182
|
+
{trialExpired ? (
|
|
183
|
+
<Clock className="h-5 w-5" aria-hidden />
|
|
184
|
+
) : (
|
|
185
|
+
<ShieldAlert className="h-5 w-5" aria-hidden />
|
|
186
|
+
)}
|
|
187
|
+
</div>
|
|
188
|
+
)}
|
|
189
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
190
|
+
<h2
|
|
191
|
+
id="license-gate-title"
|
|
192
|
+
className="text-lg leading-tight font-semibold"
|
|
193
|
+
>
|
|
194
|
+
{title}
|
|
195
|
+
</h2>
|
|
196
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
197
|
+
<LicenseStatusBadge status={state.status} />
|
|
198
|
+
<span className="text-muted-foreground text-xs">
|
|
199
|
+
{branding?.name
|
|
200
|
+
? branding.name
|
|
201
|
+
: t('license.gate.instance', {
|
|
202
|
+
defaultValue: 'Esta instancia',
|
|
203
|
+
})}
|
|
204
|
+
</span>
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
<p className="text-muted-foreground text-sm">{description}</p>
|
|
210
|
+
|
|
211
|
+
{state.reason && (
|
|
212
|
+
<p className="bg-muted/50 text-muted-foreground rounded-md px-3 py-2 text-xs">
|
|
213
|
+
{state.reason}
|
|
214
|
+
</p>
|
|
215
|
+
)}
|
|
216
|
+
|
|
217
|
+
<form
|
|
218
|
+
className="flex flex-col gap-2"
|
|
219
|
+
onSubmit={(e) => {
|
|
220
|
+
e.preventDefault()
|
|
221
|
+
void submit()
|
|
222
|
+
}}
|
|
223
|
+
>
|
|
224
|
+
<label
|
|
225
|
+
htmlFor="license-gate-code"
|
|
226
|
+
className="text-sm font-medium"
|
|
227
|
+
>
|
|
228
|
+
{t('license.gate.code_label', {
|
|
229
|
+
defaultValue: 'Clave o token de licencia',
|
|
230
|
+
})}
|
|
231
|
+
</label>
|
|
232
|
+
<Input
|
|
233
|
+
id="license-gate-code"
|
|
234
|
+
autoFocus
|
|
235
|
+
autoComplete="off"
|
|
236
|
+
spellCheck={false}
|
|
237
|
+
placeholder={t('license.gate.code_placeholder', {
|
|
238
|
+
defaultValue: 'lic_… o pega el token firmado',
|
|
239
|
+
})}
|
|
240
|
+
value={code}
|
|
241
|
+
disabled={submitting}
|
|
242
|
+
aria-invalid={error ? true : undefined}
|
|
243
|
+
onChange={(e) => {
|
|
244
|
+
setCode(e.target.value)
|
|
245
|
+
if (error) setError(null)
|
|
246
|
+
}}
|
|
247
|
+
/>
|
|
248
|
+
{error && (
|
|
249
|
+
<p role="alert" className="text-destructive text-sm">
|
|
250
|
+
{error}
|
|
251
|
+
</p>
|
|
252
|
+
)}
|
|
253
|
+
<Button
|
|
254
|
+
type="submit"
|
|
255
|
+
className="mt-1 w-full"
|
|
256
|
+
disabled={!canSubmit}
|
|
257
|
+
>
|
|
258
|
+
{submitting && (
|
|
259
|
+
<Loader2
|
|
260
|
+
className="h-4 w-4 animate-spin"
|
|
261
|
+
aria-hidden
|
|
262
|
+
/>
|
|
263
|
+
)}
|
|
264
|
+
{submitting
|
|
265
|
+
? t('license.gate.activating', {
|
|
266
|
+
defaultValue: 'Activando…',
|
|
267
|
+
})
|
|
268
|
+
: t('license.gate.activate', {
|
|
269
|
+
defaultValue: 'Activar licencia',
|
|
270
|
+
})}
|
|
271
|
+
</Button>
|
|
272
|
+
</form>
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
</div>
|
|
276
|
+
)
|
|
277
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Insignia de estado de licencia — un chip que traduce el `LicenseStatus` a
|
|
3
|
+
* color + etiqueta legible. Reutilizable suelto (p. ej. en Ajustes de licencia)
|
|
4
|
+
* o embebido en el encabezado del <LicenseGate>.
|
|
5
|
+
*/
|
|
6
|
+
import { useTranslation } from 'react-i18next'
|
|
7
|
+
import {
|
|
8
|
+
ShieldCheck,
|
|
9
|
+
ShieldAlert,
|
|
10
|
+
ShieldQuestion,
|
|
11
|
+
Clock,
|
|
12
|
+
CloudOff,
|
|
13
|
+
} from 'lucide-react'
|
|
14
|
+
import { Badge } from '@asteby/metacore-ui'
|
|
15
|
+
import type { LicenseStatus } from './types'
|
|
16
|
+
|
|
17
|
+
type BadgeVariant = 'default' | 'secondary' | 'destructive' | 'outline'
|
|
18
|
+
|
|
19
|
+
interface StatusMeta {
|
|
20
|
+
variant: BadgeVariant
|
|
21
|
+
Icon: typeof ShieldCheck
|
|
22
|
+
key: string
|
|
23
|
+
defaultValue: string
|
|
24
|
+
/** Tinte amarillo para posturas degradadas (grace/stale) que `variant` no
|
|
25
|
+
* cubre — el sistema de badges no tiene "warning". */
|
|
26
|
+
warn?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const STATUS_META: Record<LicenseStatus, StatusMeta> = {
|
|
30
|
+
valid: {
|
|
31
|
+
variant: 'default',
|
|
32
|
+
Icon: ShieldCheck,
|
|
33
|
+
key: 'license.status.valid',
|
|
34
|
+
defaultValue: 'Activa',
|
|
35
|
+
},
|
|
36
|
+
stale: {
|
|
37
|
+
variant: 'outline',
|
|
38
|
+
Icon: CloudOff,
|
|
39
|
+
key: 'license.status.stale',
|
|
40
|
+
defaultValue: 'Sin verificar',
|
|
41
|
+
warn: true,
|
|
42
|
+
},
|
|
43
|
+
grace: {
|
|
44
|
+
variant: 'outline',
|
|
45
|
+
Icon: Clock,
|
|
46
|
+
key: 'license.status.grace',
|
|
47
|
+
defaultValue: 'En gracia',
|
|
48
|
+
warn: true,
|
|
49
|
+
},
|
|
50
|
+
expired: {
|
|
51
|
+
variant: 'destructive',
|
|
52
|
+
Icon: ShieldAlert,
|
|
53
|
+
key: 'license.status.expired',
|
|
54
|
+
defaultValue: 'Vencida',
|
|
55
|
+
},
|
|
56
|
+
missing: {
|
|
57
|
+
variant: 'secondary',
|
|
58
|
+
Icon: ShieldQuestion,
|
|
59
|
+
key: 'license.status.missing',
|
|
60
|
+
defaultValue: 'Sin licencia',
|
|
61
|
+
},
|
|
62
|
+
invalid: {
|
|
63
|
+
variant: 'destructive',
|
|
64
|
+
Icon: ShieldAlert,
|
|
65
|
+
key: 'license.status.invalid',
|
|
66
|
+
defaultValue: 'Inválida',
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface LicenseStatusBadgeProps {
|
|
71
|
+
status: LicenseStatus
|
|
72
|
+
className?: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function LicenseStatusBadge({ status, className }: LicenseStatusBadgeProps) {
|
|
76
|
+
const { t } = useTranslation()
|
|
77
|
+
const meta = STATUS_META[status] ?? STATUS_META.missing
|
|
78
|
+
const { Icon } = meta
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Badge
|
|
82
|
+
variant={meta.variant}
|
|
83
|
+
className={
|
|
84
|
+
(meta.warn
|
|
85
|
+
? 'border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400 '
|
|
86
|
+
: '') + (className ?? '')
|
|
87
|
+
}
|
|
88
|
+
>
|
|
89
|
+
<Icon aria-hidden />
|
|
90
|
+
{t(meta.key, { defaultValue: meta.defaultValue })}
|
|
91
|
+
</Badge>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licencia de instancia — el contrato de estado que el backend del host (ops
|
|
3
|
+
* vía kernel `LicenseService`) expone y que este módulo pinta. El SDK NO habla
|
|
4
|
+
* con el kernel ni impone su versión: el host resuelve el `LicenseState` con su
|
|
5
|
+
* propio transporte y se lo pasa a <LicenseGate>. Así el gate es un primitivo
|
|
6
|
+
* reutilizable e INDEPENDIENTE del release del kernel.
|
|
7
|
+
*
|
|
8
|
+
* División de responsabilidades del blindaje:
|
|
9
|
+
* - kernel → enforcement (qué está permitido; firma/verifica el estado).
|
|
10
|
+
* - SDK → UX (este módulo: gate, banner, badge).
|
|
11
|
+
* - hub → emisión (mintea el token Ed25519).
|
|
12
|
+
* - hosts → wiring (resuelven el estado y montan <LicenseGate> en 1 línea).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** El estado operativo de la licencia, tal como lo deriva el backend. */
|
|
16
|
+
export type LicenseStatus =
|
|
17
|
+
| 'valid'
|
|
18
|
+
| 'stale'
|
|
19
|
+
| 'grace'
|
|
20
|
+
| 'expired'
|
|
21
|
+
| 'missing'
|
|
22
|
+
| 'invalid'
|
|
23
|
+
|
|
24
|
+
export interface LicenseState {
|
|
25
|
+
/** Licensing activo en esta instancia (LICENSING_ENFORCE). Si es false el
|
|
26
|
+
* gate es transparente: nunca bloquea ni degrada. */
|
|
27
|
+
enforced: boolean
|
|
28
|
+
configured: boolean
|
|
29
|
+
valid: boolean
|
|
30
|
+
status: LicenseStatus
|
|
31
|
+
reason?: string
|
|
32
|
+
org_id?: string
|
|
33
|
+
plan?: string
|
|
34
|
+
preset?: string
|
|
35
|
+
entitlements: string[]
|
|
36
|
+
wildcard: boolean
|
|
37
|
+
/** Lease: la instancia falló su check-in obligatorio con el hub. */
|
|
38
|
+
stale: boolean
|
|
39
|
+
max_offline_hours?: number
|
|
40
|
+
issued_at?: string
|
|
41
|
+
expires_at?: string
|
|
42
|
+
in_grace: boolean
|
|
43
|
+
grace_until?: string
|
|
44
|
+
days_remaining: number
|
|
45
|
+
last_checked_at?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** La licencia es OPERABLE cuando permite operar (aunque sea degradada):
|
|
49
|
+
* valid, la postura `stale` del lease, o dentro de la ventana de gracia.
|
|
50
|
+
* missing/invalid/expired no son operables. Sin enforcement → siempre operable.
|
|
51
|
+
* Espeja `State.Operable()` del backend. */
|
|
52
|
+
export function isLicenseOperable(state: LicenseState | undefined): boolean {
|
|
53
|
+
if (!state || !state.enforced) return true
|
|
54
|
+
return state.valid || state.in_grace
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** La instancia debe BLOQUEARSE tras el modal de activación cuando hay
|
|
58
|
+
* enforcement y la licencia es missing/invalid/expired (pasada la gracia).
|
|
59
|
+
* grace/stale degradan con banner en vez de bloquear. Espeja `State.Blocking()`.
|
|
60
|
+
* Mientras el estado aún carga (undefined) NO bloquea: fail-open en la UI para
|
|
61
|
+
* que un check lento/fallido nunca destelle un candado sobre la app. */
|
|
62
|
+
export function isLicenseBlocking(state: LicenseState | undefined): boolean {
|
|
63
|
+
if (!state || !state.enforced) return false
|
|
64
|
+
return !isLicenseOperable(state)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Un preset/vertical está habilitado si la licencia otorga wildcard o lo lista
|
|
68
|
+
* explícitamente. Sin enforcement → todo habilitado. */
|
|
69
|
+
export function isPresetEntitled(
|
|
70
|
+
state: LicenseState | undefined,
|
|
71
|
+
presetKey: string,
|
|
72
|
+
): boolean {
|
|
73
|
+
if (!state || !state.enforced) return true
|
|
74
|
+
if (state.wildcard) return true
|
|
75
|
+
return state.entitlements?.includes(presetKey) ?? false
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Marca trial vencido: el copy del gate cambia a "tu prueba terminó". */
|
|
79
|
+
export function isTrialExpired(state: LicenseState | undefined): boolean {
|
|
80
|
+
return !!state && state.plan === 'trial' && state.status === 'expired'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Branding opcional para teñir el gate/banner. El host lo pasa desde su
|
|
84
|
+
* PlatformConfig del SDK (o cualquier fuente); sin él, fallback neutro. */
|
|
85
|
+
export interface LicenseBranding {
|
|
86
|
+
/** Nombre de la plataforma/tenant, para el encabezado del gate. */
|
|
87
|
+
name?: string
|
|
88
|
+
/** URL del logo (se embebe como <img>). */
|
|
89
|
+
logo?: string
|
|
90
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -554,6 +554,13 @@ export interface PaginationMeta {
|
|
|
554
554
|
// ActionMetadata re-exported from the sdk's action-registry. We mirror the
|
|
555
555
|
// subset needed for the dispatcher so consumers of runtime-react don't have to
|
|
556
556
|
// import the sdk directly for prop typings.
|
|
557
|
+
/** One page of a multi-step (wizard) action. Mirrors the sdk's ActionStep. */
|
|
558
|
+
export interface ActionStep {
|
|
559
|
+
title: string
|
|
560
|
+
description?: string
|
|
561
|
+
fields: ActionFieldDef[]
|
|
562
|
+
}
|
|
563
|
+
|
|
557
564
|
export interface ActionMetadata {
|
|
558
565
|
key: string
|
|
559
566
|
label: string
|
|
@@ -562,6 +569,8 @@ export interface ActionMetadata {
|
|
|
562
569
|
confirm?: boolean
|
|
563
570
|
confirmMessage?: string
|
|
564
571
|
fields?: ActionFieldDef[]
|
|
572
|
+
/** Multi-step wizard form; when present the dispatcher renders a wizard. */
|
|
573
|
+
steps?: ActionStep[]
|
|
565
574
|
requiresState?: string[]
|
|
566
575
|
executable?: boolean
|
|
567
576
|
placement?: 'row' | 'table' | 'create'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// A tiny hook that returns a version counter which bumps every time i18next's
|
|
2
|
+
// resource store changes (a bundle is `added`, a language `loaded`, or a key
|
|
3
|
+
// `removed`).
|
|
4
|
+
//
|
|
5
|
+
// Why this exists: addon i18n bundles are fetched and merged asynchronously
|
|
6
|
+
// (addResourceBundle) AFTER the board first paints. react-i18next only
|
|
7
|
+
// re-renders a `useTranslation()` consumer on a store mutation when the host
|
|
8
|
+
// configured `bindI18nStore` to include those events — a host-level setting the
|
|
9
|
+
// SDK cannot assume. Without it a lane whose label is a manifest i18n key
|
|
10
|
+
// (e.g. "integration_github.stage.in_progress") renders the RAW key until an
|
|
11
|
+
// unrelated re-render happens to re-run `t()`.
|
|
12
|
+
//
|
|
13
|
+
// Depending on this version inside a memo/render makes the component re-resolve
|
|
14
|
+
// its labels the moment the bundle lands, regardless of the host's
|
|
15
|
+
// react-i18next binding config. Self-contained and cheap: one listener per
|
|
16
|
+
// mounting component, torn down on unmount.
|
|
17
|
+
import { useEffect, useState } from 'react'
|
|
18
|
+
import { useTranslation } from 'react-i18next'
|
|
19
|
+
|
|
20
|
+
export function useI18nResourceVersion(): number {
|
|
21
|
+
const { i18n } = useTranslation()
|
|
22
|
+
const [version, setVersion] = useState(0)
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!i18n) return
|
|
25
|
+
const bump = () => setVersion((v) => v + 1)
|
|
26
|
+
// `added`/`removed` fire on the resource STORE (addResourceBundle);
|
|
27
|
+
// `loaded` fires when a backend finishes a language; `languageChanged`
|
|
28
|
+
// covers a runtime locale flip. Listening to all keeps a label correct
|
|
29
|
+
// through every path a translation can arrive.
|
|
30
|
+
i18n.store?.on?.('added', bump)
|
|
31
|
+
i18n.store?.on?.('removed', bump)
|
|
32
|
+
i18n.on?.('loaded', bump)
|
|
33
|
+
i18n.on?.('languageChanged', bump)
|
|
34
|
+
return () => {
|
|
35
|
+
i18n.store?.off?.('added', bump)
|
|
36
|
+
i18n.store?.off?.('removed', bump)
|
|
37
|
+
i18n.off?.('loaded', bump)
|
|
38
|
+
i18n.off?.('languageChanged', bump)
|
|
39
|
+
}
|
|
40
|
+
}, [i18n])
|
|
41
|
+
return version
|
|
42
|
+
}
|