@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.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/license/index.d.ts +3 -1
  6. package/dist/license/index.d.ts.map +1 -1
  7. package/dist/license/index.js +3 -1
  8. package/dist/license/license-expiry-banner.d.ts +8 -1
  9. package/dist/license/license-expiry-banner.d.ts.map +1 -1
  10. package/dist/license/license-expiry-banner.js +96 -54
  11. package/dist/license/license-gate.d.ts +14 -4
  12. package/dist/license/license-gate.d.ts.map +1 -1
  13. package/dist/license/license-gate.js +75 -63
  14. package/dist/license/license-status-badge.d.ts.map +1 -1
  15. package/dist/license/license-status-badge.js +8 -9
  16. package/dist/license/messages.d.ts +29 -0
  17. package/dist/license/messages.d.ts.map +1 -0
  18. package/dist/license/messages.js +159 -0
  19. package/dist/license/types.d.ts +30 -7
  20. package/dist/license/types.d.ts.map +1 -1
  21. package/dist/license/types.js +20 -6
  22. package/dist/license/use-license-t.d.ts +11 -0
  23. package/dist/license/use-license-t.d.ts.map +1 -0
  24. package/dist/license/use-license-t.js +18 -0
  25. package/dist/license/view.d.ts +40 -0
  26. package/dist/license/view.d.ts.map +1 -0
  27. package/dist/license/view.js +62 -0
  28. package/package.json +1 -1
  29. package/src/__tests__/license-states.test.tsx +381 -0
  30. package/src/index.ts +13 -0
  31. package/src/license/index.ts +19 -0
  32. package/src/license/license-expiry-banner.tsx +155 -94
  33. package/src/license/license-gate.tsx +210 -147
  34. package/src/license/license-status-badge.tsx +8 -10
  35. package/src/license/messages.ts +185 -0
  36. package/src/license/types.ts +38 -6
  37. package/src/license/use-license-t.ts +23 -0
  38. package/src/license/view.ts +93 -0
@@ -4,54 +4,53 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  * color + etiqueta legible. Reutilizable suelto (p. ej. en Ajustes de licencia)
5
5
  * o embebido en el encabezado del <LicenseGate>.
6
6
  */
7
- import { useTranslation } from 'react-i18next';
8
7
  import { ShieldCheck, ShieldAlert, ShieldQuestion, Clock, CloudOff, } from 'lucide-react';
9
8
  import { Badge } from '@asteby/metacore-ui';
9
+ import { useLicenseT } from './use-license-t';
10
10
  const STATUS_META = {
11
11
  valid: {
12
12
  variant: 'default',
13
13
  Icon: ShieldCheck,
14
14
  key: 'license.status.valid',
15
- defaultValue: 'Activa',
16
15
  },
17
16
  stale: {
18
17
  variant: 'outline',
19
18
  Icon: CloudOff,
20
19
  key: 'license.status.stale',
21
- defaultValue: 'Sin verificar',
22
20
  warn: true,
23
21
  },
24
22
  grace: {
25
23
  variant: 'outline',
26
24
  Icon: Clock,
27
25
  key: 'license.status.grace',
28
- defaultValue: 'En gracia',
29
26
  warn: true,
30
27
  },
31
28
  expired: {
32
29
  variant: 'destructive',
33
30
  Icon: ShieldAlert,
34
31
  key: 'license.status.expired',
35
- defaultValue: 'Vencida',
36
32
  },
37
33
  missing: {
38
34
  variant: 'secondary',
39
35
  Icon: ShieldQuestion,
40
36
  key: 'license.status.missing',
41
- defaultValue: 'Sin licencia',
42
37
  },
43
38
  invalid: {
44
39
  variant: 'destructive',
45
40
  Icon: ShieldAlert,
46
41
  key: 'license.status.invalid',
47
- defaultValue: 'Inválida',
42
+ },
43
+ revoked: {
44
+ variant: 'destructive',
45
+ Icon: ShieldAlert,
46
+ key: 'license.status.revoked',
48
47
  },
49
48
  };
50
49
  export function LicenseStatusBadge({ status, className }) {
51
- const { t } = useTranslation();
50
+ const { t } = useLicenseT();
52
51
  const meta = STATUS_META[status] ?? STATUS_META.missing;
53
52
  const { Icon } = meta;
54
53
  return (_jsxs(Badge, { variant: meta.variant, className: (meta.warn
55
54
  ? 'border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400 '
56
- : '') + (className ?? ''), children: [_jsx(Icon, { "aria-hidden": true }), t(meta.key, { defaultValue: meta.defaultValue })] }));
55
+ : '') + (className ?? ''), children: [_jsx(Icon, { "aria-hidden": true }), t(meta.key)] }));
57
56
  }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Textos del blindaje de licencia, en español e inglés. Son el copy exacto de
3
+ * cada estado: dicen QUÉ pasó y QUÉ sigue, sin repetir lo que ya dicen las
4
+ * etiquetas y botones de la pantalla (nada de "pega tu clave" junto a un campo
5
+ * que ya se llama "Clave…").
6
+ *
7
+ * Cada componente los pide con `t(key, { defaultValue })`: un host con i18n
8
+ * puede sobrescribir cualquier clave en su bundle; sin i18n sale este texto.
9
+ * `registerLicenseMessages(i18n)` los siembra en un i18next sin pisar lo del host.
10
+ *
11
+ * El SDK es genérico: aquí no hay marca, vertical ni vendedor concreto. El
12
+ * contacto del vendedor llega en el propio estado de la licencia.
13
+ */
14
+ export type LicenseLang = 'es' | 'en';
15
+ export declare function licenseLang(language?: string): LicenseLang;
16
+ export declare const LICENSE_MESSAGES: Record<LicenseLang, Record<string, string>>;
17
+ /** Fecha corta y estable (UTC) para los textos de licencia. */
18
+ export declare function formatLicenseDate(iso: string | undefined, lang: LicenseLang): string | undefined;
19
+ /** Minimal i18next surface needed to seed the bundles. */
20
+ interface I18nLike {
21
+ addResourceBundle?: (lng: string, ns: string, res: object, deep?: boolean, overwrite?: boolean) => unknown;
22
+ }
23
+ /**
24
+ * Siembra es/en en el i18next del host SIN pisar lo que ya tenga (overwrite=false):
25
+ * el host manda, el SDK solo rellena lo que falta.
26
+ */
27
+ export declare function registerLicenseMessages(i18n: I18nLike | undefined, ns?: string): void;
28
+ export {};
29
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/license/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,IAAI,CAAA;AAErC,wBAAgB,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,CAE1D;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA+HxE,CAAA;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAUhG;AAED,0DAA0D;AAC1D,UAAU,QAAQ;IACd,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,KAAK,OAAO,CAAA;CAC7G;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE,EAAE,SAAgB,GAAG,IAAI,CAc5F"}
@@ -0,0 +1,159 @@
1
+ export function licenseLang(language) {
2
+ return (language ?? '').toLowerCase().startsWith('en') ? 'en' : 'es';
3
+ }
4
+ export const LICENSE_MESSAGES = {
5
+ es: {
6
+ // Insignias
7
+ 'license.status.valid': 'Activa',
8
+ 'license.status.stale': 'Sin verificar',
9
+ 'license.status.grace': 'En gracia',
10
+ 'license.status.expired': 'Vencida',
11
+ 'license.status.missing': 'Sin licencia',
12
+ 'license.status.invalid': 'Inválida',
13
+ 'license.status.revoked': 'Desactivada',
14
+ // Modal bloqueante
15
+ 'license.gate.instance': 'Esta instancia',
16
+ 'license.gate.title': 'Activa tu licencia',
17
+ 'license.gate.missing_description': 'Esta instancia todavía no tiene una licencia activa.',
18
+ 'license.gate.invalid_description': 'No pudimos validar la licencia de esta instancia.',
19
+ 'license.gate.expired_title': 'Tu licencia venció',
20
+ 'license.gate.expired_description': 'Tu licencia venció el {{date}} y el periodo de gracia terminó.',
21
+ 'license.gate.expired_description_nodate': 'Tu licencia venció y el periodo de gracia terminó.',
22
+ 'license.gate.trial_title': 'Tu prueba gratuita terminó',
23
+ 'license.gate.trial_description': 'La prueba gratuita de esta instancia terminó.',
24
+ 'license.gate.revoked_title': 'Licencia desactivada',
25
+ 'license.gate.revoked_description': '{{who}} desactivó la licencia de esta instancia.',
26
+ 'license.gate.read_only': 'Contacta al administrador de la plataforma para activar la licencia.',
27
+ 'license.gate.code_label': 'Clave o token de licencia',
28
+ 'license.gate.code_label_link': 'Enlace, código o clave de licencia',
29
+ 'license.gate.code_placeholder': 'lic_… o pega el token firmado',
30
+ 'license.gate.code_placeholder_link': 'https://…/a/acs_…, acs_… o lic_…',
31
+ 'license.gate.activate': 'Activar licencia',
32
+ 'license.gate.activating': 'Activando…',
33
+ 'license.gate.activate_error': 'No se pudo activar la licencia.',
34
+ 'license.gate.export': 'Exportar mis datos',
35
+ 'license.gate.provider': 'Tu proveedor',
36
+ 'license.gate.contact_label': 'Contacto',
37
+ // Errores de un enlace o código de activación (código estable del hub)
38
+ 'license.link.activation_not_found': 'No reconocemos ese enlace o código. Revisa que esté completo o pide uno nuevo a tu proveedor.',
39
+ 'license.link.activation_used': 'Este enlace ya se usó en otro servidor. Pide uno nuevo a tu proveedor.',
40
+ 'license.link.activation_conflict': 'Esta licencia ya funciona en otro servidor. Si lo reinstalaste, pide a tu proveedor que la libere.',
41
+ 'license.link.activation_expired': 'El enlace venció. Tu proveedor puede generarte otro en un minuto.',
42
+ 'license.link.activation_revoked': 'Tu proveedor revocó este enlace. Contáctalo para recibir uno nuevo.',
43
+ 'license.link.license_revoked': 'Tu proveedor desactivó esta licencia. Contáctalo para reactivarla.',
44
+ 'license.link.license_expired': 'La licencia de este enlace ya venció. Tu proveedor puede renovarla.',
45
+ 'license.link.rate_limited': 'Demasiados intentos. Espera unos minutos y vuelve a probar.',
46
+ // Banner
47
+ 'license.banner.upcoming': 'Tu licencia vence en {{days}} días.',
48
+ 'license.banner.upcoming_one': 'Tu licencia vence mañana.',
49
+ 'license.banner.upcoming_today': 'Tu licencia vence hoy.',
50
+ 'license.banner.grace': 'Tu licencia venció el {{date}}. Tienes {{days}} días para renovarla antes de que se bloqueen los cambios.',
51
+ 'license.banner.grace_nodate': 'Tu licencia venció. Tienes {{days}} días para renovarla antes de que se bloqueen los cambios.',
52
+ 'license.banner.expired_read_only': 'Tu licencia venció el {{date}}. Tu información sigue disponible para consultar y exportar; renueva para volver a registrar cambios.',
53
+ 'license.banner.expired_read_only_nodate': 'Tu licencia venció. Tu información sigue disponible para consultar y exportar; renueva para volver a registrar cambios.',
54
+ 'license.banner.expired': 'Tu licencia venció. Algunas acciones están bloqueadas.',
55
+ 'license.banner.revoked': '{{who}} desactivó esta licencia. Tu información sigue disponible para consultar y exportar hasta el {{date}}.',
56
+ 'license.banner.revoked_nodate': '{{who}} desactivó esta licencia. Tu información sigue disponible para consultar y exportar.',
57
+ 'license.banner.stale': 'No pudimos contactar al servidor de licencias desde el {{date}}. Seguimos funcionando.',
58
+ 'license.banner.stale_nodate': 'No pudimos contactar al servidor de licencias. Seguimos funcionando.',
59
+ 'license.banner.cloned': 'Detectamos esta licencia activa en otro servidor. Si no fue a propósito, avisa a {{who}}.',
60
+ 'license.banner.manage': 'Gestionar licencia',
61
+ 'license.banner.renew': 'Renovar',
62
+ 'license.banner.export': 'Exportar mis datos',
63
+ 'license.banner.dismiss': 'Descartar',
64
+ 'license.banner.contact': 'Contacto: {{contact}}',
65
+ 'license.banner.provider': 'tu proveedor',
66
+ },
67
+ en: {
68
+ 'license.status.valid': 'Active',
69
+ 'license.status.stale': 'Not verified',
70
+ 'license.status.grace': 'In grace period',
71
+ 'license.status.expired': 'Expired',
72
+ 'license.status.missing': 'No license',
73
+ 'license.status.invalid': 'Invalid',
74
+ 'license.status.revoked': 'Deactivated',
75
+ 'license.gate.instance': 'This instance',
76
+ 'license.gate.title': 'Activate your license',
77
+ 'license.gate.missing_description': "This instance doesn't have an active license yet.",
78
+ 'license.gate.invalid_description': "We couldn't validate this instance's license.",
79
+ 'license.gate.expired_title': 'Your license has expired',
80
+ 'license.gate.expired_description': 'Your license expired on {{date}} and the grace period has ended.',
81
+ 'license.gate.expired_description_nodate': 'Your license expired and the grace period has ended.',
82
+ 'license.gate.trial_title': 'Your free trial has ended',
83
+ 'license.gate.trial_description': "This instance's free trial has ended.",
84
+ 'license.gate.revoked_title': 'License deactivated',
85
+ 'license.gate.revoked_description': '{{who}} deactivated this instance\'s license.',
86
+ 'license.gate.read_only': 'Contact the platform administrator to activate the license.',
87
+ 'license.gate.code_label': 'License key or token',
88
+ 'license.gate.code_label_link': 'Activation link, code or license key',
89
+ 'license.gate.code_placeholder': 'lic_… or the signed token',
90
+ 'license.gate.code_placeholder_link': 'https://…/a/acs_…, acs_… or lic_…',
91
+ 'license.gate.activate': 'Activate license',
92
+ 'license.gate.activating': 'Activating…',
93
+ 'license.gate.activate_error': "The license couldn't be activated.",
94
+ 'license.gate.export': 'Export my data',
95
+ 'license.gate.provider': 'Your provider',
96
+ 'license.gate.contact_label': 'Contact',
97
+ 'license.link.activation_not_found': "We don't recognize that link or code. Check that it's complete, or ask your provider for a new one.",
98
+ 'license.link.activation_used': 'This link was already used on another server. Ask your provider for a new one.',
99
+ 'license.link.activation_conflict': 'This license already runs on another server. If you reinstalled, ask your provider to release it.',
100
+ 'license.link.activation_expired': 'The link has expired. Your provider can generate another in a minute.',
101
+ 'license.link.activation_revoked': 'Your provider revoked this link. Contact them to get a new one.',
102
+ 'license.link.license_revoked': 'Your provider deactivated this license. Contact them to reactivate it.',
103
+ 'license.link.license_expired': "This link's license has already expired. Your provider can renew it.",
104
+ 'license.link.rate_limited': 'Too many attempts. Wait a few minutes and try again.',
105
+ 'license.banner.upcoming': 'Your license expires in {{days}} days.',
106
+ 'license.banner.upcoming_one': 'Your license expires tomorrow.',
107
+ 'license.banner.upcoming_today': 'Your license expires today.',
108
+ 'license.banner.grace': 'Your license expired on {{date}}. You have {{days}} days to renew it before changes are blocked.',
109
+ 'license.banner.grace_nodate': 'Your license expired. You have {{days}} days to renew it before changes are blocked.',
110
+ 'license.banner.expired_read_only': 'Your license expired on {{date}}. Your data is still available to view and export; renew to record changes again.',
111
+ 'license.banner.expired_read_only_nodate': 'Your license expired. Your data is still available to view and export; renew to record changes again.',
112
+ 'license.banner.expired': 'Your license expired. Some actions are blocked.',
113
+ 'license.banner.revoked': '{{who}} deactivated this license. Your data stays available to view and export until {{date}}.',
114
+ 'license.banner.revoked_nodate': '{{who}} deactivated this license. Your data stays available to view and export.',
115
+ 'license.banner.stale': "We couldn't reach the license server since {{date}}. Everything keeps working.",
116
+ 'license.banner.stale_nodate': "We couldn't reach the license server. Everything keeps working.",
117
+ 'license.banner.cloned': "We detected this license active on another server. If that wasn't intended, let {{who}} know.",
118
+ 'license.banner.manage': 'Manage license',
119
+ 'license.banner.renew': 'Renew',
120
+ 'license.banner.export': 'Export my data',
121
+ 'license.banner.dismiss': 'Dismiss',
122
+ 'license.banner.contact': 'Contact: {{contact}}',
123
+ 'license.banner.provider': 'your provider',
124
+ },
125
+ };
126
+ /** Fecha corta y estable (UTC) para los textos de licencia. */
127
+ export function formatLicenseDate(iso, lang) {
128
+ if (!iso)
129
+ return undefined;
130
+ const d = new Date(iso);
131
+ if (Number.isNaN(d.getTime()))
132
+ return undefined;
133
+ return d.toLocaleDateString(lang === 'en' ? 'en-US' : 'es-MX', {
134
+ day: 'numeric',
135
+ month: 'long',
136
+ year: 'numeric',
137
+ timeZone: 'UTC',
138
+ });
139
+ }
140
+ /**
141
+ * Siembra es/en en el i18next del host SIN pisar lo que ya tenga (overwrite=false):
142
+ * el host manda, el SDK solo rellena lo que falta.
143
+ */
144
+ export function registerLicenseMessages(i18n, ns = 'translation') {
145
+ if (!i18n?.addResourceBundle)
146
+ return;
147
+ for (const lang of ['es', 'en']) {
148
+ const nested = {};
149
+ for (const [key, value] of Object.entries(LICENSE_MESSAGES[lang])) {
150
+ const parts = key.split('.');
151
+ let cur = nested;
152
+ parts.slice(0, -1).forEach((p) => {
153
+ cur = (cur[p] ??= {});
154
+ });
155
+ cur[parts[parts.length - 1]] = value;
156
+ }
157
+ i18n.addResourceBundle(lang, ns, nested, true, false);
158
+ }
159
+ }
@@ -12,7 +12,19 @@
12
12
  * - hosts → wiring (resuelven el estado y montan <LicenseGate> en 1 línea).
13
13
  */
14
14
  /** El estado operativo de la licencia, tal como lo deriva el backend. */
15
- export type LicenseStatus = 'valid' | 'stale' | 'grace' | 'expired' | 'missing' | 'invalid';
15
+ export type LicenseStatus = 'valid' | 'stale' | 'grace' | 'expired' | 'missing' | 'invalid'
16
+ /** El emisor desactivó la licencia (el hub respondió `license_revoked`). */
17
+ | 'revoked';
18
+ /** Contacto de quien vendió la licencia. Solo se muestra si la licencia lo trae. */
19
+ export interface LicenseSeller {
20
+ name?: string;
21
+ email?: string;
22
+ phone?: string;
23
+ url?: string;
24
+ }
25
+ /** Qué hace la instancia cuando la licencia termina: `read_only` deja consultar y
26
+ * exportar sin registrar cambios; `block` es el comportamiento clásico (modal). */
27
+ export type LicenseOnExpiry = 'read_only' | 'block';
16
28
  export interface LicenseState {
17
29
  /** Licensing activo en esta instancia (LICENSING_ENFORCE). Si es false el
18
30
  * gate es transparente: nunca bloquea ni degrada. */
@@ -35,17 +47,28 @@ export interface LicenseState {
35
47
  grace_until?: string;
36
48
  days_remaining: number;
37
49
  last_checked_at?: string;
50
+ /** Quien vendió la licencia, si el hub lo informó. */
51
+ seller?: LicenseSeller;
52
+ /** Política al vencer. Ausente = `block` (instancias sin enlace de activación). */
53
+ on_expiry?: LicenseOnExpiry;
54
+ /** Avisos para el dueño, p. ej. `clone_suspected` (licencia activa en otro servidor). */
55
+ notices?: string[];
38
56
  }
39
57
  /** La licencia es OPERABLE cuando permite operar (aunque sea degradada):
40
58
  * valid, la postura `stale` del lease, o dentro de la ventana de gracia.
41
- * missing/invalid/expired no son operables. Sin enforcement → siempre operable.
42
- * Espeja `State.Operable()` del backend. */
59
+ * missing/invalid/expired/revoked no son operables. Sin enforcement → siempre
60
+ * operable. Espeja `State.Operable()` del backend. */
43
61
  export declare function isLicenseOperable(state: LicenseState | undefined): boolean;
62
+ /** Vencida con política de solo lectura: la app sigue abierta para consultar y
63
+ * exportar, y el backend rechaza las escrituras. Solo aplica si el hub informó
64
+ * `on_expiry: 'read_only'`; sin él, vencida = bloqueo (comportamiento clásico). */
65
+ export declare function isLicenseReadOnly(state: LicenseState | undefined): boolean;
44
66
  /** La instancia debe BLOQUEARSE tras el modal de activación cuando hay
45
- * enforcement y la licencia es missing/invalid/expired (pasada la gracia).
46
- * grace/stale degradan con banner en vez de bloquear. Espeja `State.Blocking()`.
47
- * Mientras el estado aún carga (undefined) NO bloquea: fail-open en la UI para
48
- * que un check lento/fallido nunca destelle un candado sobre la app. */
67
+ * enforcement y la licencia es missing/invalid/revoked/expired (pasada la
68
+ * gracia), salvo que la política sea de solo lectura. grace/stale degradan con
69
+ * banner en vez de bloquear. Espeja `State.Blocking()`. Mientras el estado aún
70
+ * carga (undefined) NO bloquea: fail-open en la UI para que un check lento o
71
+ * fallido nunca destelle un candado sobre la app. */
49
72
  export declare function isLicenseBlocking(state: LicenseState | undefined): boolean;
50
73
  /** Un preset/vertical está habilitado si la licencia otorga wildcard o lo lista
51
74
  * explícitamente. Sin enforcement → todo habilitado. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/license/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,yEAAyE;AACzE,MAAM,MAAM,aAAa,GACnB,OAAO,GACP,OAAO,GACP,OAAO,GACP,SAAS,GACT,SAAS,GACT,SAAS,CAAA;AAEf,MAAM,WAAW,YAAY;IACzB;yDACqD;IACrD,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,M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AAO,CAK1E;AAED;;;;;qDAKqD;AACrD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAI1E;AAED;wDACwD;AACxD,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,YAAY,GAAG,SAAS,EAC/B,SAAS,EAAE,MAAM,GAClB,OAAO,CAIT;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAEvE;AAED;2EAC2E;AAC3E,MAAM,WAAW,eAAe;IAC5B,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB"}
@@ -13,21 +13,35 @@
13
13
  */
14
14
  /** La licencia es OPERABLE cuando permite operar (aunque sea degradada):
15
15
  * valid, la postura `stale` del lease, o dentro de la ventana de gracia.
16
- * missing/invalid/expired no son operables. Sin enforcement → siempre operable.
17
- * Espeja `State.Operable()` del backend. */
16
+ * missing/invalid/expired/revoked no son operables. Sin enforcement → siempre
17
+ * operable. Espeja `State.Operable()` del backend. */
18
18
  export function isLicenseOperable(state) {
19
19
  if (!state || !state.enforced)
20
20
  return true;
21
21
  return state.valid || state.in_grace;
22
22
  }
23
+ /** Vencida con política de solo lectura: la app sigue abierta para consultar y
24
+ * exportar, y el backend rechaza las escrituras. Solo aplica si el hub informó
25
+ * `on_expiry: 'read_only'`; sin él, vencida = bloqueo (comportamiento clásico). */
26
+ export function isLicenseReadOnly(state) {
27
+ if (!state || !state.enforced)
28
+ return false;
29
+ if (state.on_expiry === 'read_only' && state.status === 'expired')
30
+ return true;
31
+ // Revocada dentro de su plazo corto de aviso: se puede consultar y exportar.
32
+ return state.status === 'revoked' && state.in_grace;
33
+ }
23
34
  /** La instancia debe BLOQUEARSE tras el modal de activación cuando hay
24
- * enforcement y la licencia es missing/invalid/expired (pasada la gracia).
25
- * grace/stale degradan con banner en vez de bloquear. Espeja `State.Blocking()`.
26
- * Mientras el estado aún carga (undefined) NO bloquea: fail-open en la UI para
27
- * que un check lento/fallido nunca destelle un candado sobre la app. */
35
+ * enforcement y la licencia es missing/invalid/revoked/expired (pasada la
36
+ * gracia), salvo que la política sea de solo lectura. grace/stale degradan con
37
+ * banner en vez de bloquear. Espeja `State.Blocking()`. Mientras el estado aún
38
+ * carga (undefined) NO bloquea: fail-open en la UI para que un check lento o
39
+ * fallido nunca destelle un candado sobre la app. */
28
40
  export function isLicenseBlocking(state) {
29
41
  if (!state || !state.enforced)
30
42
  return false;
43
+ if (isLicenseReadOnly(state))
44
+ return false;
31
45
  return !isLicenseOperable(state);
32
46
  }
33
47
  /** Un preset/vertical está habilitado si la licencia otorga wildcard o lo lista
@@ -0,0 +1,11 @@
1
+ import { type LicenseLang } from './messages';
2
+ /**
3
+ * `t` de licencia: pide la clave a i18next y, si el host no la define, cae al
4
+ * texto es/en del SDK según el idioma activo (español por omisión). Un host con
5
+ * su propio bundle gana siempre.
6
+ */
7
+ export declare function useLicenseT(): {
8
+ t: (key: string, vars?: Record<string, unknown>) => string;
9
+ lang: LicenseLang;
10
+ };
11
+ //# sourceMappingURL=use-license-t.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-license-t.d.ts","sourceRoot":"","sources":["../../src/license/use-license-t.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AAE5E;;;;GAIG;AACH,wBAAgB,WAAW,IAAI;IAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAA;IAC1D,IAAI,EAAE,WAAW,CAAA;CACpB,CAWA"}
@@ -0,0 +1,18 @@
1
+ import { useTranslation } from 'react-i18next';
2
+ import { LICENSE_MESSAGES, licenseLang } from './messages';
3
+ /**
4
+ * `t` de licencia: pide la clave a i18next y, si el host no la define, cae al
5
+ * texto es/en del SDK según el idioma activo (español por omisión). Un host con
6
+ * su propio bundle gana siempre.
7
+ */
8
+ export function useLicenseT() {
9
+ const { t, i18n } = useTranslation();
10
+ const lang = licenseLang(i18n?.language);
11
+ return {
12
+ lang,
13
+ t: (key, vars) => t(key, {
14
+ defaultValue: LICENSE_MESSAGES[lang][key] ?? LICENSE_MESSAGES.es[key] ?? key,
15
+ ...vars,
16
+ }),
17
+ };
18
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Una sola derivación del estado de licencia a "qué muestra la UI". Gate, banner
3
+ * y pantallas del host la comparten, así que todos cuentan lo mismo.
4
+ *
5
+ * Estados (solo con enforcement; sin él no hay vista):
6
+ * valid vigente
7
+ * expiring vigente, por vencer (≤ umbral de días)
8
+ * grace vencida, dentro de la gracia (se puede operar)
9
+ * expired vencida: solo lectura con exportación (`on_expiry: read_only`)
10
+ * o bloqueo con modal (política clásica)
11
+ * revoked desactivada por el emisor: solo lectura un tiempo corto y luego modal
12
+ * hub_unreachable sin contacto con el hub pero con lease vigente: opera; avisa solo al dueño
13
+ * missing/invalid sin licencia o no válida: modal de activación
14
+ * Además, `cloned` (licencia vista en otro servidor) es un aviso al dueño que se
15
+ * suma a cualquiera de los anteriores.
16
+ */
17
+ import { type LicenseState } from './types';
18
+ export type LicenseCondition = 'valid' | 'expiring' | 'grace' | 'expired' | 'revoked' | 'hub_unreachable' | 'missing' | 'invalid';
19
+ export type LicenseSeverity = 'ok' | 'notice' | 'warning' | 'critical';
20
+ export interface LicenseView {
21
+ condition: LicenseCondition;
22
+ severity: LicenseSeverity;
23
+ /** Modal bloqueante de pantalla completa. */
24
+ blocking: boolean;
25
+ /** La app sigue abierta pero el backend rechaza escrituras (consultar y exportar). */
26
+ readOnly: boolean;
27
+ /** El aviso es solo para el dueño/superadmin; el resto de usuarios no lo ve. */
28
+ ownerOnly: boolean;
29
+ /** Licencia vista activa en otro servidor (aviso al dueño, no bloquea). */
30
+ cloned: boolean;
31
+ trialExpired: boolean;
32
+ }
33
+ export declare const CLONE_NOTICE = "clone_suspected";
34
+ export declare function isLicenseCloned(state: LicenseState | undefined): boolean;
35
+ export declare function deriveLicenseView(state: LicenseState | undefined, opts?: {
36
+ upcomingThresholdDays?: number;
37
+ }): LicenseView | undefined;
38
+ /** Texto de contacto de una línea ("Ana · ana@x.mx · +52…") o undefined. */
39
+ export declare function sellerContactLine(state: LicenseState | undefined): string | undefined;
40
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/license/view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAwD,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAEjG,MAAM,MAAM,gBAAgB,GACtB,OAAO,GACP,UAAU,GACV,OAAO,GACP,SAAS,GACT,SAAS,GACT,iBAAiB,GACjB,SAAS,GACT,SAAS,CAAA;AAEf,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAA;AAEtE,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,QAAQ,EAAE,eAAe,CAAA;IACzB,6CAA6C;IAC7C,QAAQ,EAAE,OAAO,CAAA;IACjB,sFAAsF;IACtF,QAAQ,EAAE,OAAO,CAAA;IACjB,gFAAgF;IAChF,SAAS,EAAE,OAAO,CAAA;IAClB,2EAA2E;IAC3E,MAAM,EAAE,OAAO,CAAA;IACf,YAAY,EAAE,OAAO,CAAA;CACxB;AAED,eAAO,MAAM,YAAY,oBAAoB,CAAA;AAE7C,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAExE;AAED,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,YAAY,GAAG,SAAS,EAC/B,IAAI,GAAE;IAAE,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9C,WAAW,GAAG,SAAS,CA+BzB;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKrF"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Una sola derivación del estado de licencia a "qué muestra la UI". Gate, banner
3
+ * y pantallas del host la comparten, así que todos cuentan lo mismo.
4
+ *
5
+ * Estados (solo con enforcement; sin él no hay vista):
6
+ * valid vigente
7
+ * expiring vigente, por vencer (≤ umbral de días)
8
+ * grace vencida, dentro de la gracia (se puede operar)
9
+ * expired vencida: solo lectura con exportación (`on_expiry: read_only`)
10
+ * o bloqueo con modal (política clásica)
11
+ * revoked desactivada por el emisor: solo lectura un tiempo corto y luego modal
12
+ * hub_unreachable sin contacto con el hub pero con lease vigente: opera; avisa solo al dueño
13
+ * missing/invalid sin licencia o no válida: modal de activación
14
+ * Además, `cloned` (licencia vista en otro servidor) es un aviso al dueño que se
15
+ * suma a cualquiera de los anteriores.
16
+ */
17
+ import { isLicenseBlocking, isLicenseReadOnly, isTrialExpired } from './types';
18
+ export const CLONE_NOTICE = 'clone_suspected';
19
+ export function isLicenseCloned(state) {
20
+ return !!state?.enforced && !!state.notices?.includes(CLONE_NOTICE);
21
+ }
22
+ export function deriveLicenseView(state, opts = {}) {
23
+ if (!state || !state.enforced)
24
+ return undefined;
25
+ const threshold = opts.upcomingThresholdDays ?? 15;
26
+ const blocking = isLicenseBlocking(state);
27
+ const readOnly = isLicenseReadOnly(state);
28
+ const base = {
29
+ blocking,
30
+ readOnly,
31
+ ownerOnly: false,
32
+ cloned: isLicenseCloned(state),
33
+ trialExpired: isTrialExpired(state),
34
+ };
35
+ switch (state.status) {
36
+ case 'missing':
37
+ return { ...base, condition: 'missing', severity: 'critical' };
38
+ case 'invalid':
39
+ return { ...base, condition: 'invalid', severity: 'critical' };
40
+ case 'revoked':
41
+ return { ...base, condition: 'revoked', severity: 'critical' };
42
+ case 'expired':
43
+ return { ...base, condition: 'expired', severity: 'critical' };
44
+ case 'grace':
45
+ return { ...base, condition: 'grace', severity: 'warning' };
46
+ case 'stale':
47
+ return { ...base, condition: 'hub_unreachable', severity: 'notice', ownerOnly: true };
48
+ default:
49
+ if (state.days_remaining <= threshold) {
50
+ return { ...base, condition: 'expiring', severity: 'warning' };
51
+ }
52
+ return { ...base, condition: 'valid', severity: 'ok' };
53
+ }
54
+ }
55
+ /** Texto de contacto de una línea ("Ana · ana@x.mx · +52…") o undefined. */
56
+ export function sellerContactLine(state) {
57
+ const s = state?.seller;
58
+ if (!s)
59
+ return undefined;
60
+ const parts = [s.email, s.phone, s.url].map((p) => p?.trim()).filter(Boolean);
61
+ return parts.length ? parts.join(' · ') : undefined;
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-runtime-react",
3
- "version": "53.2.0",
3
+ "version": "53.3.0",
4
4
  "description": "React runtime for metacore hosts — renders addon contributions dynamically",
5
5
  "repository": {
6
6
  "type": "git",