@asteby/metacore-runtime-react 53.14.0 → 53.16.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.
@@ -0,0 +1,468 @@
1
+ // AddonSlot — punto de montaje de contribuciones de addons en un host.
2
+ //
3
+ // <AddonSlot kind="invoice.footer" context={{ invoiceId }} />
4
+ //
5
+ // Qué pinta, en este orden (`order` ascendente y luego `priority` descendente,
6
+ // ver docs/slot-priority.md):
7
+ // 1. contribuciones declaradas en los manifests instalados
8
+ // (`contributions.slots[]`, ya filtradas por el servidor: permiso,
9
+ // `condition` y org), que se bajan como remoto federado (`slot.entry` es
10
+ // el `expose`);
11
+ // 2. contribuciones en proceso registradas en el slot store canónico
12
+ // (`Registry.registerSlot`, `slotRegistry.register`): una sola lista.
13
+ //
14
+ // Cada contribución vive aislada en su propio ErrorBoundary + Suspense con un
15
+ // timeout: si un remoto lanza, se cuelga o no es compatible, emite
16
+ // `addon_slot_failed{addon,kind,reason}` por el canal de errores del host y
17
+ // muestra su fallback; sus hermanos y el shell no se enteran.
18
+ //
19
+ // Contrato del remoto (C2): `export default function SlotComponent({ context,
20
+ // props, sdk })`. Sin provider ni manifests, solo se pintan las contribuciones
21
+ // en proceso (equivale al `<Slot>` histórico).
22
+ import React, {
23
+ createContext,
24
+ Suspense,
25
+ useContext,
26
+ useEffect,
27
+ useMemo,
28
+ useRef,
29
+ useState,
30
+ useSyncExternalStore,
31
+ type ComponentType,
32
+ type ReactNode,
33
+ } from 'react'
34
+ import { slotStore, type SlotEntry } from '@asteby/metacore-sdk'
35
+ import { loadFederatedModule } from '../addon-loader'
36
+ import { FederatedErrorBoundary } from '../federated-error-boundary'
37
+ import { useInstalledAddons } from '../installed-addons-context'
38
+ import { satisfiesSdkRange } from './sdk-range'
39
+
40
+ export const ADDON_SLOT_FAILED = 'addon_slot_failed'
41
+ export const DEFAULT_ADDON_SLOT_TIMEOUT_MS = 10_000
42
+ /** Rango permitido por el contrato C1 para `slot.timeout_ms` del manifest. */
43
+ export const MIN_SLOT_TIMEOUT_MS = 1_000
44
+ export const MAX_SLOT_TIMEOUT_MS = 30_000
45
+
46
+ /**
47
+ * `timeout_ms` del manifest acotado a 1000..30000. Un valor no numérico, NaN,
48
+ * 0 o negativo se ignora y manda el del host (nunca anula el timeout).
49
+ */
50
+ export function resolveSlotTimeout(slotValue: unknown, hostMs: number): number {
51
+ if (typeof slotValue !== 'number' || !Number.isFinite(slotValue) || slotValue <= 0) return hostMs
52
+ return Math.min(MAX_SLOT_TIMEOUT_MS, Math.max(MIN_SLOT_TIMEOUT_MS, slotValue))
53
+ }
54
+
55
+ export type AddonSlotFailureReason =
56
+ | 'timeout'
57
+ | 'load'
58
+ | 'render'
59
+ | 'missing_expose'
60
+ | 'integrity_required'
61
+ | 'sdk_incompatible'
62
+
63
+ export interface AddonSlotFailure {
64
+ addon: string
65
+ kind: string
66
+ reason: AddonSlotFailureReason
67
+ /** Mensaje del error, si lo hubo. */
68
+ message?: string
69
+ }
70
+
71
+ export type AddonSlotEventHandler = (event: typeof ADDON_SLOT_FAILED, data: AddonSlotFailure) => void
72
+
73
+ /** Subconjunto del manifest que AddonSlot necesita (cabe un `ManifestV3` completo). */
74
+ export interface AddonSlotManifest {
75
+ key: string
76
+ version?: string
77
+ frontend?: {
78
+ entry: string
79
+ container?: string
80
+ integrity?: string
81
+ /** Rango semver del SDK con el que se compiló el bundle. */
82
+ sdk?: string
83
+ }
84
+ contributions?: { slots?: AddonSlotContribution[] }
85
+ }
86
+
87
+ export interface AddonSlotContribution {
88
+ slot_kind: string
89
+ /** `expose` del remoto (p. ej. "./slots/invoice-footer"). */
90
+ entry: string
91
+ order?: number
92
+ props?: Record<string, unknown>
93
+ timeout_ms?: number
94
+ /**
95
+ * Qué se ve si esta contribución falla (manifest v3 `slots[].fallback`): `hide` (por omisión)
96
+ * usa el `fallback` del host (nada si no hay); `notice` pinta un aviso discreto en su lugar.
97
+ */
98
+ fallback?: 'hide' | 'notice'
99
+ }
100
+
101
+ /** Lo que recibe el componente del remoto además de `context` y `props`. */
102
+ export interface AddonSlotSDK {
103
+ addon: string
104
+ kind: string
105
+ /** Versión del SDK que el host expone a los remotos, si la declaró. */
106
+ sdkVersion?: string
107
+ }
108
+
109
+ export interface AddonSlotComponentProps {
110
+ context: Record<string, unknown>
111
+ props: Record<string, unknown>
112
+ sdk: AddonSlotSDK
113
+ }
114
+
115
+ interface Config {
116
+ manifests: readonly AddonSlotManifest[]
117
+ sdkVersion?: string
118
+ requireIntegrity: boolean
119
+ timeoutMs: number
120
+ onEvent?: AddonSlotEventHandler
121
+ }
122
+
123
+ const Ctx = createContext<Config | null>(null)
124
+
125
+ export interface AddonSlotProviderProps {
126
+ /** Manifests instalados, ya filtrados por el servidor. */
127
+ manifests: readonly AddonSlotManifest[]
128
+ /** Versión de `@asteby/metacore-sdk` que el host expone; habilita la comprobación de `frontend.sdk`. */
129
+ sdkVersion?: string
130
+ /** Rechaza remotos sin `frontend.integrity` (por omisión false = comportamiento histórico). */
131
+ requireIntegrity?: boolean
132
+ /** Timeout por omisión de carga de cada remoto (ms; 0 lo desactiva). */
133
+ timeoutMs?: number
134
+ /** Canal de errores del host (telemetría / incidentes). */
135
+ onEvent?: AddonSlotEventHandler
136
+ children?: ReactNode
137
+ }
138
+
139
+ export function AddonSlotProvider({
140
+ manifests,
141
+ sdkVersion,
142
+ requireIntegrity = false,
143
+ timeoutMs = DEFAULT_ADDON_SLOT_TIMEOUT_MS,
144
+ onEvent,
145
+ children,
146
+ }: AddonSlotProviderProps) {
147
+ const onEventRef = useRef(onEvent)
148
+ onEventRef.current = onEvent
149
+ const value = useMemo<Config>(
150
+ () => ({
151
+ manifests,
152
+ sdkVersion,
153
+ requireIntegrity,
154
+ timeoutMs,
155
+ onEvent: (e, d) => onEventRef.current?.(e, d),
156
+ }),
157
+ [manifests, sdkVersion, requireIntegrity, timeoutMs],
158
+ )
159
+ return <Ctx.Provider value={value}>{children}</Ctx.Provider>
160
+ }
161
+
162
+ export interface AddonSlotProps {
163
+ kind: string
164
+ context?: Record<string, unknown>
165
+ className?: string
166
+ /** Sustituye a la configuración del provider (timeout por omisión, ms). */
167
+ timeoutMs?: number
168
+ requireIntegrity?: boolean
169
+ onEvent?: AddonSlotEventHandler
170
+ /** Mientras un remoto baja. Por omisión nada. */
171
+ loading?: ReactNode
172
+ /** Qué se pinta en el lugar de una contribución que falló. Por omisión nada. */
173
+ fallback?: ReactNode | ((failure: AddonSlotFailure) => ReactNode)
174
+ /** Qué se pinta cuando el slot no tiene ninguna contribución (por omisión nada). */
175
+ empty?: ReactNode
176
+ }
177
+
178
+ type RemoteItem_ = {
179
+ type: 'remote'
180
+ id: string
181
+ addon: string
182
+ order: number
183
+ priority: number
184
+ manifest: AddonSlotManifest
185
+ slot: AddonSlotContribution
186
+ }
187
+ type LocalItem_ = { type: 'local'; id: string; addon: string; order: number; priority: number; entry: SlotEntry }
188
+ type Item = RemoteItem_ | LocalItem_
189
+
190
+ /** Aviso de `fallback: "notice"`: sin detalles internos del error. */
191
+ export function SlotFailureNotice({ failure }: { failure: AddonSlotFailure }) {
192
+ return (
193
+ <div role="status" data-addon-slot-notice={failure.addon} data-reason={failure.reason}>
194
+ No se pudo cargar este módulo ({failure.addon}).
195
+ </div>
196
+ )
197
+ }
198
+
199
+ const EMPTY_OBJ: Record<string, unknown> = Object.freeze({}) as Record<string, unknown>
200
+
201
+ /** Orden canónico: `order` ascendente, luego `priority` descendente, luego inserción. */
202
+ export function sortSlotItems<T extends { order: number; priority: number }>(items: readonly T[]): T[] {
203
+ return items
204
+ .map((it, i) => ({ it, i }))
205
+ .sort((a, b) => a.it.order - b.it.order || b.it.priority - a.it.priority || a.i - b.i)
206
+ .map((x) => x.it)
207
+ }
208
+
209
+ function withTimeout<T>(p: Promise<T>, ms: number, onTimeout: () => Error): Promise<T> {
210
+ if (!ms || ms <= 0) return p
211
+ return new Promise<T>((resolve, reject) => {
212
+ const t = setTimeout(() => reject(onTimeout()), ms)
213
+ p.then(
214
+ (v) => {
215
+ clearTimeout(t)
216
+ resolve(v)
217
+ },
218
+ (e) => {
219
+ clearTimeout(t)
220
+ reject(e)
221
+ },
222
+ )
223
+ })
224
+ }
225
+
226
+ class SlotLoadError extends Error {
227
+ readonly reason: AddonSlotFailureReason
228
+ constructor(reason: AddonSlotFailureReason, message: string) {
229
+ super(message)
230
+ this.name = 'SlotLoadError'
231
+ this.reason = reason
232
+ }
233
+ }
234
+
235
+ function containerScope(m: AddonSlotManifest): string {
236
+ return m.frontend?.container || `metacore_${m.key.replace(/[^a-zA-Z0-9]/g, '_')}`
237
+ }
238
+
239
+ function toComponent(mod: unknown): ComponentType<AddonSlotComponentProps> | null {
240
+ const candidate = (mod as { default?: unknown } | null)?.default ?? mod
241
+ if (typeof candidate === 'function') return candidate as ComponentType<AddonSlotComponentProps>
242
+ // React.lazy / React.memo / forwardRef son objetos con $$typeof.
243
+ if (candidate && typeof candidate === 'object' && '$$typeof' in (candidate as object)) {
244
+ return candidate as ComponentType<AddonSlotComponentProps>
245
+ }
246
+ return null
247
+ }
248
+
249
+ type RemoteState =
250
+ | { status: 'loading' }
251
+ | { status: 'ready'; C: ComponentType<AddonSlotComponentProps> }
252
+ | { status: 'failed'; failure: AddonSlotFailure }
253
+
254
+ function RemoteItem({
255
+ kind,
256
+ item,
257
+ context,
258
+ cfg,
259
+ requireIntegrity,
260
+ timeoutMs,
261
+ loading,
262
+ renderFallback,
263
+ report,
264
+ }: {
265
+ kind: string
266
+ item: RemoteItem_
267
+ context: Record<string, unknown>
268
+ cfg: Config | null
269
+ requireIntegrity: boolean
270
+ timeoutMs: number
271
+ loading: ReactNode
272
+ renderFallback: (f: AddonSlotFailure) => ReactNode
273
+ report: (f: AddonSlotFailure) => void
274
+ }) {
275
+ const { manifest, slot, addon } = item
276
+ const fe = manifest.frontend
277
+ const [state, setState] = useState<RemoteState>({ status: 'loading' })
278
+ const reportRef = useRef(report)
279
+ reportRef.current = report
280
+ const effectiveTimeout = resolveSlotTimeout(slot.timeout_ms, timeoutMs)
281
+ const hostSdk = cfg?.sdkVersion
282
+
283
+ useEffect(() => {
284
+ let cancelled = false
285
+ const fail = (reason: AddonSlotFailureReason, message: string) => {
286
+ if (cancelled) return
287
+ const failure: AddonSlotFailure = { addon, kind, reason, message }
288
+ setState({ status: 'failed', failure })
289
+ reportRef.current(failure)
290
+ }
291
+ setState({ status: 'loading' })
292
+ if (!fe?.entry) {
293
+ fail('load', `addon ${addon} declares a slot but has no frontend.entry`)
294
+ return
295
+ }
296
+ if (requireIntegrity && !fe.integrity) {
297
+ fail('integrity_required', `addon ${addon} has no frontend.integrity and the host requires it`)
298
+ return
299
+ }
300
+ if (satisfiesSdkRange(hostSdk, fe.sdk) === false) {
301
+ fail('sdk_incompatible', `addon ${addon} needs SDK ${fe.sdk}, host provides ${hostSdk}`)
302
+ return
303
+ }
304
+ let loadPromise: Promise<unknown>
305
+ try {
306
+ loadPromise = Promise.resolve(loadFederatedModule(containerScope(manifest), fe.entry, slot.entry, fe.integrity))
307
+ } catch (e) {
308
+ loadPromise = Promise.reject(e)
309
+ }
310
+ withTimeout(
311
+ loadPromise,
312
+ effectiveTimeout,
313
+ () => new SlotLoadError('timeout', `slot "${slot.entry}" of ${addon} did not load within ${effectiveTimeout} ms`),
314
+ )
315
+ .then((mod) => {
316
+ if (cancelled) return
317
+ const C = toComponent(mod)
318
+ if (!C) throw new SlotLoadError('missing_expose', `expose "${slot.entry}" of ${addon} has no default component`)
319
+ setState({ status: 'ready', C })
320
+ })
321
+ .catch((e: unknown) => {
322
+ const err = e instanceof Error ? e : new Error(String(e))
323
+ fail(e instanceof SlotLoadError ? e.reason : 'load', err.message)
324
+ })
325
+ return () => {
326
+ cancelled = true
327
+ }
328
+ // eslint-disable-next-line react-hooks/exhaustive-deps
329
+ }, [addon, kind, fe?.entry, fe?.integrity, fe?.sdk, slot.entry, requireIntegrity, effectiveTimeout, hostSdk])
330
+
331
+ if (state.status === 'loading') return <>{loading}</>
332
+ if (state.status === 'failed') return <>{renderFallback(state.failure)}</>
333
+ const { C } = state
334
+ const sdk: AddonSlotSDK = { addon, kind, sdkVersion: hostSdk }
335
+ return (
336
+ <RenderGuard addon={addon} kind={kind} renderFallback={renderFallback} report={report} resetKey={fe?.entry}>
337
+ <C context={context} props={slot.props ?? EMPTY_OBJ} sdk={sdk} />
338
+ </RenderGuard>
339
+ )
340
+ }
341
+
342
+ function RenderGuard({
343
+ addon,
344
+ kind,
345
+ resetKey,
346
+ renderFallback,
347
+ report,
348
+ children,
349
+ }: {
350
+ addon: string
351
+ kind: string
352
+ resetKey?: unknown
353
+ renderFallback: (f: AddonSlotFailure) => ReactNode
354
+ report: (f: AddonSlotFailure) => void
355
+ children: ReactNode
356
+ }) {
357
+ return (
358
+ <FederatedErrorBoundary
359
+ addonKey={addon}
360
+ resetKeys={[resetKey]}
361
+ onError={(error) => report({ addon, kind, reason: 'render', message: error.message })}
362
+ fallback={({ error }) => <>{renderFallback({ addon, kind, reason: 'render', message: error.message })}</>}
363
+ >
364
+ <Suspense fallback={null}>{children}</Suspense>
365
+ </FederatedErrorBoundary>
366
+ )
367
+ }
368
+
369
+ export function AddonSlot({
370
+ kind,
371
+ context,
372
+ className,
373
+ timeoutMs,
374
+ requireIntegrity,
375
+ onEvent,
376
+ loading = null,
377
+ fallback = null,
378
+ empty = null,
379
+ }: AddonSlotProps) {
380
+ const cfg = useContext(Ctx)
381
+ const installed = useInstalledAddons()
382
+ const ctx = context ?? EMPTY_OBJ
383
+ const local = useSyncExternalStore(
384
+ (cb) => slotStore.subscribe(cb),
385
+ () => slotStore.get(kind),
386
+ () => slotStore.get(kind),
387
+ )
388
+
389
+ const items = useMemo(() => {
390
+ const out: Item[] = []
391
+ for (const m of cfg?.manifests ?? []) {
392
+ if (installed && !installed.addons.has(m.key)) continue
393
+ ;(m.contributions?.slots ?? []).forEach((slot, i) => {
394
+ if (slot.slot_kind !== kind) return
395
+ out.push({
396
+ type: 'remote',
397
+ id: `${m.key}:${slot.entry}:${i}`,
398
+ addon: m.key,
399
+ order: slot.order ?? 0,
400
+ priority: 0,
401
+ manifest: m,
402
+ slot,
403
+ })
404
+ })
405
+ }
406
+ local.forEach((entry, i) => {
407
+ if (entry.owner && installed && !installed.addons.has(entry.owner)) return
408
+ out.push({
409
+ type: 'local',
410
+ id: `local:${entry.source ?? 'anon'}:${i}`,
411
+ addon: entry.owner ?? entry.source ?? 'host',
412
+ order: 0,
413
+ priority: entry.priority ?? 0,
414
+ entry,
415
+ })
416
+ })
417
+ return sortSlotItems(out)
418
+ }, [cfg?.manifests, installed, local, kind])
419
+
420
+ const effTimeout = timeoutMs ?? cfg?.timeoutMs ?? DEFAULT_ADDON_SLOT_TIMEOUT_MS
421
+ const effRequire = requireIntegrity ?? cfg?.requireIntegrity ?? false
422
+ const handlerRef = useRef(onEvent ?? cfg?.onEvent)
423
+ handlerRef.current = onEvent ?? cfg?.onEvent
424
+
425
+ const report = useRef((f: AddonSlotFailure) => {
426
+ try {
427
+ handlerRef.current?.(ADDON_SLOT_FAILED, f)
428
+ } catch {
429
+ /* un reporter roto no tumba el shell */
430
+ }
431
+ }).current
432
+ const renderFallback = (f: AddonSlotFailure): ReactNode =>
433
+ typeof fallback === 'function' ? (fallback as (f: AddonSlotFailure) => ReactNode)(f) : fallback
434
+
435
+ if (items.length === 0) return <>{empty}</>
436
+ return (
437
+ <div data-addon-slot={kind} className={className} style={className ? undefined : { display: 'contents' }}>
438
+ {items.map((item) => (
439
+ <div key={item.id} data-addon-slot-item={item.addon} style={{ display: 'contents' }}>
440
+ {item.type === 'remote' ? (
441
+ <RemoteItem
442
+ kind={kind}
443
+ item={item}
444
+ context={ctx}
445
+ cfg={cfg}
446
+ requireIntegrity={effRequire}
447
+ timeoutMs={effTimeout}
448
+ loading={loading}
449
+ renderFallback={
450
+ item.slot.fallback === 'notice' ? (f) => <SlotFailureNotice failure={f} /> : renderFallback
451
+ }
452
+ report={report}
453
+ />
454
+ ) : (
455
+ <RenderGuard addon={item.addon} kind={kind} renderFallback={renderFallback} report={report}>
456
+ <item.entry.component
457
+ {...ctx}
458
+ context={ctx}
459
+ props={EMPTY_OBJ}
460
+ sdk={{ addon: item.addon, kind, sdkVersion: cfg?.sdkVersion } satisfies AddonSlotSDK}
461
+ />
462
+ </RenderGuard>
463
+ )}
464
+ </div>
465
+ ))}
466
+ </div>
467
+ )
468
+ }
@@ -0,0 +1,18 @@
1
+ export {
2
+ AddonSlot,
3
+ AddonSlotProvider,
4
+ sortSlotItems,
5
+ ADDON_SLOT_FAILED,
6
+ DEFAULT_ADDON_SLOT_TIMEOUT_MS,
7
+ resolveSlotTimeout,
8
+ type AddonSlotProps,
9
+ type AddonSlotProviderProps,
10
+ type AddonSlotManifest,
11
+ type AddonSlotContribution,
12
+ type AddonSlotSDK,
13
+ type AddonSlotComponentProps,
14
+ type AddonSlotFailure,
15
+ type AddonSlotFailureReason,
16
+ type AddonSlotEventHandler,
17
+ } from './addon-slot'
18
+ export { satisfiesSdkRange } from './sdk-range'
@@ -0,0 +1,86 @@
1
+ // Comprobación mínima de rangos semver para `manifest.frontend.sdk`
2
+ // (p. ej. "^4.0.0", ">=3.2 <5", "~3.18", "3.x", "^3 || ^4"). Sin dependencias.
3
+ // Un rango que no se entiende devuelve `null` (desconocido): el llamador NO lo
4
+ // trata como incompatible, para no romper addons por un rango exótico.
5
+
6
+ type V = [number, number, number]
7
+
8
+ function parseVersion(s: string): V | null {
9
+ const m = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/.exec(s.trim())
10
+ if (!m) return null
11
+ return [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)]
12
+ }
13
+
14
+ function cmp(a: V, b: V): number {
15
+ for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1
16
+ return 0
17
+ }
18
+
19
+ /** Un comparador simple (`^1.2.3`, `>=1`, `1.x`, `=1.2.3`) contra `v`. null = no se entiende. */
20
+ function matchComparator(token: string, v: V): boolean | null {
21
+ const m = /^(\^|~|>=|<=|>|<|=)?\s*v?([\dxX*]+(?:\.[\dxX*]+){0,2}(?:[-+][\w.-]+)?)$/.exec(token)
22
+ if (!m) return null
23
+ const op = m[1] ?? ''
24
+ const raw = m[2]
25
+ const parts = raw.split(/[-+]/)[0].split('.')
26
+ const isWild = (p: string | undefined) => p === undefined || /^[xX*]$/.test(p)
27
+ const nums = parts.map((p) => (isWild(p) ? null : Number(p)))
28
+ if (nums[0] === null) return op === '<' ? false : true // "*" / "x"
29
+ const lo: V = [nums[0], nums[1] ?? 0, nums[2] ?? 0]
30
+ const specified = nums.filter((n) => n !== null).length // 1..3
31
+ // Límite superior exclusivo para comodín / parcial ("1.2" => <1.3.0).
32
+ const bump = (n: number): V => (n === 1 ? [lo[0] + 1, 0, 0] : n === 2 ? [lo[0], lo[1] + 1, 0] : [lo[0], lo[1], lo[2] + 1])
33
+ switch (op) {
34
+ case '':
35
+ case '=':
36
+ return cmp(v, lo) >= 0 && cmp(v, bump(specified)) < 0
37
+ case '>=':
38
+ return cmp(v, lo) >= 0
39
+ case '>':
40
+ return cmp(v, bump(specified)) >= 0
41
+ case '<':
42
+ return cmp(v, lo) < 0
43
+ case '<=':
44
+ return cmp(v, bump(specified)) < 0
45
+ case '~':
46
+ return cmp(v, lo) >= 0 && cmp(v, bump(specified === 1 ? 1 : 2)) < 0
47
+ case '^': {
48
+ let hi: V
49
+ if (lo[0] > 0 || specified === 1) hi = [lo[0] + 1, 0, 0]
50
+ else if (lo[1] > 0 || specified === 2) hi = [0, lo[1] + 1, 0]
51
+ else hi = [0, 0, lo[2] + 1]
52
+ return cmp(v, lo) >= 0 && cmp(v, hi) < 0
53
+ }
54
+ }
55
+ return null
56
+ }
57
+
58
+ /**
59
+ * ¿`version` cumple `range`? `true`/`false` si ambos se entienden, `null` si
60
+ * alguno no (rango vacío o versión ilegible = sin restricción conocida).
61
+ */
62
+ export function satisfiesSdkRange(version: string | undefined, range: string | undefined): boolean | null {
63
+ if (!version || !range || !range.trim()) return null
64
+ const v = parseVersion(version)
65
+ if (!v) return null
66
+ let unknown = false
67
+ for (const alt of range.split('||')) {
68
+ // "1.2.3 - 2.0.0" no se soporta: cae en `unknown`.
69
+ const tokens = alt.trim().split(/\s+/).filter(Boolean)
70
+ if (tokens.length === 0) {
71
+ return true
72
+ }
73
+ let ok = true
74
+ for (const t of tokens) {
75
+ const r = matchComparator(t, v)
76
+ if (r === null) {
77
+ unknown = true
78
+ ok = false
79
+ break
80
+ }
81
+ if (!r) ok = false
82
+ }
83
+ if (ok) return true
84
+ }
85
+ return unknown ? null : false
86
+ }