@nubitio/core 0.5.11 → 0.5.14

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/index.d.cts CHANGED
@@ -38,6 +38,11 @@ interface CoreConfig {
38
38
  * formatters that need a currency fall back to plain fixed-point output.
39
39
  */
40
40
  currency?: string;
41
+ /**
42
+ * Escape hatch for Mercure collection topic URIs when autodiscovery from
43
+ * Hydra `@id` cannot infer the API origin (e.g. relative IRIs only).
44
+ */
45
+ mercureTopicOrigin?: string;
41
46
  }
42
47
  /**
43
48
  * Configure core runtime values (locale, timezone, apiBaseUrl).
@@ -54,12 +59,15 @@ declare function getCoreTimezone(): string;
54
59
  declare function getCoreApiBaseUrl(): string;
55
60
  /** App-wide default currency (ISO 4217), or undefined when not configured. */
56
61
  declare function getCoreCurrency(): string | undefined;
62
+ declare function getMercureTopicOrigin(): string | undefined;
57
63
  interface CoreConfigProviderProps {
58
64
  locale: string;
59
65
  timezone: string;
60
66
  apiBaseUrl: string;
61
67
  /** ISO 4217 app-wide default currency for money formatters (e.g. 'PEN', 'USD'). */
62
68
  currency?: string;
69
+ /** Mercure topic origin override — see {@link CoreConfig.mercureTopicOrigin}. */
70
+ mercureTopicOrigin?: string;
63
71
  children: React.ReactNode;
64
72
  }
65
73
  declare const CoreConfigProvider: ({
@@ -67,6 +75,7 @@ declare const CoreConfigProvider: ({
67
75
  timezone,
68
76
  apiBaseUrl,
69
77
  currency,
78
+ mercureTopicOrigin,
70
79
  children
71
80
  }: CoreConfigProviderProps) => React.JSX.Element;
72
81
  declare function useCoreConfig(): CoreConfig;
@@ -435,8 +444,11 @@ declare function CoreProvider({
435
444
  //#endregion
436
445
  //#region packages/core/mercure/MercureProvider.d.ts
437
446
  interface MercureProviderProps {
438
- /** Hub URL discovered from the `Link` header, or null if unavailable. */
439
- hubUrl: string | null;
447
+ /**
448
+ * Hub URL override. When omitted, the provider listens to autodiscovery
449
+ * from API `Link` headers via `MercureManager`.
450
+ */
451
+ hubUrl?: string | null;
440
452
  children: ReactNode;
441
453
  }
442
454
  /**
@@ -444,7 +456,7 @@ interface MercureProviderProps {
444
456
  * in sync whenever the URL changes.
445
457
  */
446
458
  declare function MercureProvider({
447
- hubUrl,
459
+ hubUrl: hubUrlOverride,
448
460
  children
449
461
  }: MercureProviderProps): React.JSX.Element;
450
462
  //#endregion
@@ -458,7 +470,8 @@ declare function MercureProvider({
458
470
  * - Mercure is not configured in the backend.
459
471
  *
460
472
  * This hook does NOT perform any fetch or side effect — it only reads from context.
461
- * Hub discovery (usually from a `Link` header) must be done by the host application.
473
+ * Hub discovery happens automatically via `CoreHttpClient` (`Link` header parsing).
474
+ * Use `<MercureProvider>` without a `hubUrl` prop to expose the discovered URL.
462
475
  *
463
476
  * ## Usage
464
477
  *
@@ -482,6 +495,9 @@ declare function useMercureHub(): string | null;
482
495
  * - If `hubUrl` is null (Mercure not configured) or `enabled` is false → no-op.
483
496
  * - Subscribes to the wildcard topic `<origin>/<apiUrl>/{id}` (URI Template RFC 6570),
484
497
  * which captures any item-level event (create / update / delete) for the collection.
498
+ * - `<origin>` comes from `CoreConfig.mercureTopicOrigin`, autodiscovered Hydra
499
+ * `@id`, an absolute `apiBaseUrl`, or `window.location.origin`
500
+ * (see `buildMercureCollectionTopic`).
485
501
  * - Cleanup: unsubscribes on unmount or when dependencies change (no memory leaks).
486
502
  *
487
503
  * ## Usage
@@ -501,6 +517,58 @@ declare function useMercureHub(): string | null;
501
517
  */
502
518
  declare function useMercureSubscription(apiUrl: string | undefined, onUpdate: () => void, enabled?: boolean): void;
503
519
  //#endregion
520
+ //#region packages/core/mercure/mercureTopics.d.ts
521
+ /**
522
+ * Resolves the origin used to build Mercure collection topic URIs.
523
+ *
524
+ * API Platform publishes item updates to IRIs such as
525
+ * `http://localhost:8000/api/products/42`. The SPA may run on another origin
526
+ * in dev (Vite on :5173, API on :8000). The origin is normally autodiscovered
527
+ * from absolute Hydra `@id` values on API responses. Set `mercureTopicOrigin`
528
+ * on CoreConfig only when autodiscovery cannot infer the correct origin.
529
+ */
530
+ declare function resolveMercureTopicOrigin(apiBaseUrl?: string, configuredOrigin?: string, discoveredOrigin?: string | undefined): string;
531
+ /**
532
+ * Wildcard collection topic (RFC 6570 URI Template) for a resource API path.
533
+ * e.g. `/api/products` → `http://localhost:8000/api/products/{id}`
534
+ */
535
+ declare function buildMercureCollectionTopic(apiUrl: string, configuredOrigin?: string, apiBaseUrl?: string): string | null;
536
+ //#endregion
537
+ //#region packages/core/mercure/mercureDiscovery.d.ts
538
+ /** Parsed RFC 8288 Link header entry. */
539
+ interface ParsedLink {
540
+ url: string;
541
+ rel: string;
542
+ }
543
+ /**
544
+ * Parse a `Link` response header value into `{ url, rel }` pairs.
545
+ * Handles API Platform's `</.well-known/mercure>; rel="mercure"` format.
546
+ */
547
+ declare function parseLinkHeader(header: string): ParsedLink[];
548
+ /**
549
+ * Extract the Mercure hub URL from response headers, if present.
550
+ * Relative URLs are resolved against the request URL.
551
+ */
552
+ declare function extractMercureHubUrl(headers: Headers, responseUrl: string): string | null;
553
+ /**
554
+ * Infer the API origin from Hydra `@id` values (entrypoint or collection items).
555
+ * API Platform publishes absolute IRIs when `DEFAULT_URI` is configured.
556
+ */
557
+ declare function extractTopicOriginFromPayload(data: unknown): string | null;
558
+ declare function getDiscoveredMercureTopicOrigin(): string | undefined;
559
+ /**
560
+ * Inspect an API response and update Mercure hub URL / topic origin when found.
561
+ * Called from `CoreHttpClient` on every successful response.
562
+ */
563
+ declare function discoverMercureFromResponse(response: Response, data: unknown): void;
564
+ //#endregion
565
+ //#region packages/core/mercure/useDiscoveredMercureTopicOrigin.d.ts
566
+ /**
567
+ * Returns the Mercure topic origin autodiscovered from Hydra `@id` IRIs.
568
+ * Re-renders when a new origin is discovered from a subsequent API response.
569
+ */
570
+ declare function useDiscoveredMercureTopicOrigin(): string | undefined;
571
+ //#endregion
504
572
  //#region packages/core/mercure/MercureManager.d.ts
505
573
  /**
506
574
  * MercureManager — Singleton that manages the lifecycle of EventSource connections.
@@ -564,4 +632,4 @@ declare class MercureManager {
564
632
  /** Singleton instance — shared across the entire application. */
565
633
  declare const mercureManager: MercureManager;
566
634
  //#endregion
567
- export { type CoreConfig, CoreConfigProvider, type CoreConfigProviderProps, CoreHttpClient, type CoreHttpClientConfig, type CoreHttpError, type CoreHttpErrorData, CoreHttpProvider, type CoreHttpProviderProps, type CoreHttpResponse, type CoreNotificationType, CoreProvider, type CoreProviderProps, type CoreRequestConfig, type CoreResponseType, type CoreRuntime, CoreRuntimeProvider, type CoreRuntimeProviderProps, type CoreTranslationKeys, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FormEventNames, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type ScopedFormEventNames, type ToolbarButtonItem, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, dispatch, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, initCoreI18n, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useEvents, useMercureHub, useMercureSubscription };
635
+ export { type CoreConfig, CoreConfigProvider, type CoreConfigProviderProps, CoreHttpClient, type CoreHttpClientConfig, type CoreHttpError, type CoreHttpErrorData, CoreHttpProvider, type CoreHttpProviderProps, type CoreHttpResponse, type CoreNotificationType, CoreProvider, type CoreProviderProps, type CoreRequestConfig, type CoreResponseType, type CoreRuntime, CoreRuntimeProvider, type CoreRuntimeProviderProps, type CoreTranslationKeys, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FormEventNames, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type ScopedFormEventNames, type ToolbarButtonItem, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, parseLinkHeader, resolveMercureTopicOrigin, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useMercureHub, useMercureSubscription };
package/dist/index.d.mts CHANGED
@@ -38,6 +38,11 @@ interface CoreConfig {
38
38
  * formatters that need a currency fall back to plain fixed-point output.
39
39
  */
40
40
  currency?: string;
41
+ /**
42
+ * Escape hatch for Mercure collection topic URIs when autodiscovery from
43
+ * Hydra `@id` cannot infer the API origin (e.g. relative IRIs only).
44
+ */
45
+ mercureTopicOrigin?: string;
41
46
  }
42
47
  /**
43
48
  * Configure core runtime values (locale, timezone, apiBaseUrl).
@@ -54,12 +59,15 @@ declare function getCoreTimezone(): string;
54
59
  declare function getCoreApiBaseUrl(): string;
55
60
  /** App-wide default currency (ISO 4217), or undefined when not configured. */
56
61
  declare function getCoreCurrency(): string | undefined;
62
+ declare function getMercureTopicOrigin(): string | undefined;
57
63
  interface CoreConfigProviderProps {
58
64
  locale: string;
59
65
  timezone: string;
60
66
  apiBaseUrl: string;
61
67
  /** ISO 4217 app-wide default currency for money formatters (e.g. 'PEN', 'USD'). */
62
68
  currency?: string;
69
+ /** Mercure topic origin override — see {@link CoreConfig.mercureTopicOrigin}. */
70
+ mercureTopicOrigin?: string;
63
71
  children: React.ReactNode;
64
72
  }
65
73
  declare const CoreConfigProvider: ({
@@ -67,6 +75,7 @@ declare const CoreConfigProvider: ({
67
75
  timezone,
68
76
  apiBaseUrl,
69
77
  currency,
78
+ mercureTopicOrigin,
70
79
  children
71
80
  }: CoreConfigProviderProps) => React.JSX.Element;
72
81
  declare function useCoreConfig(): CoreConfig;
@@ -435,8 +444,11 @@ declare function CoreProvider({
435
444
  //#endregion
436
445
  //#region packages/core/mercure/MercureProvider.d.ts
437
446
  interface MercureProviderProps {
438
- /** Hub URL discovered from the `Link` header, or null if unavailable. */
439
- hubUrl: string | null;
447
+ /**
448
+ * Hub URL override. When omitted, the provider listens to autodiscovery
449
+ * from API `Link` headers via `MercureManager`.
450
+ */
451
+ hubUrl?: string | null;
440
452
  children: ReactNode;
441
453
  }
442
454
  /**
@@ -444,7 +456,7 @@ interface MercureProviderProps {
444
456
  * in sync whenever the URL changes.
445
457
  */
446
458
  declare function MercureProvider({
447
- hubUrl,
459
+ hubUrl: hubUrlOverride,
448
460
  children
449
461
  }: MercureProviderProps): React.JSX.Element;
450
462
  //#endregion
@@ -458,7 +470,8 @@ declare function MercureProvider({
458
470
  * - Mercure is not configured in the backend.
459
471
  *
460
472
  * This hook does NOT perform any fetch or side effect — it only reads from context.
461
- * Hub discovery (usually from a `Link` header) must be done by the host application.
473
+ * Hub discovery happens automatically via `CoreHttpClient` (`Link` header parsing).
474
+ * Use `<MercureProvider>` without a `hubUrl` prop to expose the discovered URL.
462
475
  *
463
476
  * ## Usage
464
477
  *
@@ -482,6 +495,9 @@ declare function useMercureHub(): string | null;
482
495
  * - If `hubUrl` is null (Mercure not configured) or `enabled` is false → no-op.
483
496
  * - Subscribes to the wildcard topic `<origin>/<apiUrl>/{id}` (URI Template RFC 6570),
484
497
  * which captures any item-level event (create / update / delete) for the collection.
498
+ * - `<origin>` comes from `CoreConfig.mercureTopicOrigin`, autodiscovered Hydra
499
+ * `@id`, an absolute `apiBaseUrl`, or `window.location.origin`
500
+ * (see `buildMercureCollectionTopic`).
485
501
  * - Cleanup: unsubscribes on unmount or when dependencies change (no memory leaks).
486
502
  *
487
503
  * ## Usage
@@ -501,6 +517,58 @@ declare function useMercureHub(): string | null;
501
517
  */
502
518
  declare function useMercureSubscription(apiUrl: string | undefined, onUpdate: () => void, enabled?: boolean): void;
503
519
  //#endregion
520
+ //#region packages/core/mercure/mercureTopics.d.ts
521
+ /**
522
+ * Resolves the origin used to build Mercure collection topic URIs.
523
+ *
524
+ * API Platform publishes item updates to IRIs such as
525
+ * `http://localhost:8000/api/products/42`. The SPA may run on another origin
526
+ * in dev (Vite on :5173, API on :8000). The origin is normally autodiscovered
527
+ * from absolute Hydra `@id` values on API responses. Set `mercureTopicOrigin`
528
+ * on CoreConfig only when autodiscovery cannot infer the correct origin.
529
+ */
530
+ declare function resolveMercureTopicOrigin(apiBaseUrl?: string, configuredOrigin?: string, discoveredOrigin?: string | undefined): string;
531
+ /**
532
+ * Wildcard collection topic (RFC 6570 URI Template) for a resource API path.
533
+ * e.g. `/api/products` → `http://localhost:8000/api/products/{id}`
534
+ */
535
+ declare function buildMercureCollectionTopic(apiUrl: string, configuredOrigin?: string, apiBaseUrl?: string): string | null;
536
+ //#endregion
537
+ //#region packages/core/mercure/mercureDiscovery.d.ts
538
+ /** Parsed RFC 8288 Link header entry. */
539
+ interface ParsedLink {
540
+ url: string;
541
+ rel: string;
542
+ }
543
+ /**
544
+ * Parse a `Link` response header value into `{ url, rel }` pairs.
545
+ * Handles API Platform's `</.well-known/mercure>; rel="mercure"` format.
546
+ */
547
+ declare function parseLinkHeader(header: string): ParsedLink[];
548
+ /**
549
+ * Extract the Mercure hub URL from response headers, if present.
550
+ * Relative URLs are resolved against the request URL.
551
+ */
552
+ declare function extractMercureHubUrl(headers: Headers, responseUrl: string): string | null;
553
+ /**
554
+ * Infer the API origin from Hydra `@id` values (entrypoint or collection items).
555
+ * API Platform publishes absolute IRIs when `DEFAULT_URI` is configured.
556
+ */
557
+ declare function extractTopicOriginFromPayload(data: unknown): string | null;
558
+ declare function getDiscoveredMercureTopicOrigin(): string | undefined;
559
+ /**
560
+ * Inspect an API response and update Mercure hub URL / topic origin when found.
561
+ * Called from `CoreHttpClient` on every successful response.
562
+ */
563
+ declare function discoverMercureFromResponse(response: Response, data: unknown): void;
564
+ //#endregion
565
+ //#region packages/core/mercure/useDiscoveredMercureTopicOrigin.d.ts
566
+ /**
567
+ * Returns the Mercure topic origin autodiscovered from Hydra `@id` IRIs.
568
+ * Re-renders when a new origin is discovered from a subsequent API response.
569
+ */
570
+ declare function useDiscoveredMercureTopicOrigin(): string | undefined;
571
+ //#endregion
504
572
  //#region packages/core/mercure/MercureManager.d.ts
505
573
  /**
506
574
  * MercureManager — Singleton that manages the lifecycle of EventSource connections.
@@ -564,4 +632,4 @@ declare class MercureManager {
564
632
  /** Singleton instance — shared across the entire application. */
565
633
  declare const mercureManager: MercureManager;
566
634
  //#endregion
567
- export { type CoreConfig, CoreConfigProvider, type CoreConfigProviderProps, CoreHttpClient, type CoreHttpClientConfig, type CoreHttpError, type CoreHttpErrorData, CoreHttpProvider, type CoreHttpProviderProps, type CoreHttpResponse, type CoreNotificationType, CoreProvider, type CoreProviderProps, type CoreRequestConfig, type CoreResponseType, type CoreRuntime, CoreRuntimeProvider, type CoreRuntimeProviderProps, type CoreTranslationKeys, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FormEventNames, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type ScopedFormEventNames, type ToolbarButtonItem, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, dispatch, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, initCoreI18n, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useEvents, useMercureHub, useMercureSubscription };
635
+ export { type CoreConfig, CoreConfigProvider, type CoreConfigProviderProps, CoreHttpClient, type CoreHttpClientConfig, type CoreHttpError, type CoreHttpErrorData, CoreHttpProvider, type CoreHttpProviderProps, type CoreHttpResponse, type CoreNotificationType, CoreProvider, type CoreProviderProps, type CoreRequestConfig, type CoreResponseType, type CoreRuntime, CoreRuntimeProvider, type CoreRuntimeProviderProps, type CoreTranslationKeys, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FormEventNames, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type ScopedFormEventNames, type ToolbarButtonItem, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, parseLinkHeader, resolveMercureTopicOrigin, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useMercureHub, useMercureSubscription };