@nubitio/core 1.1.0 → 1.1.2

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.cjs CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
@@ -169,7 +169,7 @@ var DateUtils = class {
169
169
  const dateStart = new Date(startDate);
170
170
  const dateEnd = new Date(endDate);
171
171
  const timeDiff = Math.abs(dateEnd.getTime() - dateStart.getTime());
172
- return Math.ceil(timeDiff / (1e3 * 3600 * 24));
172
+ return Math.ceil(timeDiff / 864e5);
173
173
  }
174
174
  static monthDiff(startDate, endDate) {
175
175
  const dateStart = new Date(startDate);
@@ -411,8 +411,9 @@ const createCrudEvents = (prefix) => ({
411
411
  */
412
412
  function createScopedEventBus(resourceId) {
413
413
  const scopeId = Math.random().toString(36).slice(2, 10);
414
+ const prefix = `${resourceId}:${scopeId}`;
414
415
  return {
415
- ...createCrudEvents(`${resourceId}:${scopeId}`),
416
+ ...createCrudEvents(prefix),
416
417
  _scopeId: scopeId
417
418
  };
418
419
  }
@@ -812,7 +813,7 @@ var MercureManager = class {
812
813
  /**
813
814
  * Subscribe to a Mercure topic.
814
815
  *
815
- * @param topic Full topic URI or URI Template, e.g. `https://host/api/products/{id}`.
816
+ * @param topic A WHATWG URL Pattern, e.g. `https://host/api/products/*`.
816
817
  * @param callback Called with the parsed JSON payload on each SSE message.
817
818
  *
818
819
  * If `hubUrl` is null (hub not configured), this is a no-op (graceful degradation).
@@ -835,7 +836,7 @@ var MercureManager = class {
835
836
  return;
836
837
  }
837
838
  const url = new URL(this.hubUrl);
838
- url.searchParams.append("topic", topic);
839
+ url.searchParams.append("match_urlpattern", topic);
839
840
  const eventSource = new EventSource(url.toString(), { withCredentials: true });
840
841
  const listener = (e) => {
841
842
  try {
@@ -1026,7 +1027,7 @@ const DEFAULT_CORRELATION_ID_HEADER_NAME = "X-Request-Id";
1026
1027
  * "safe methods don't need CSRF protection" rule (GET/HEAD never mutate
1027
1028
  * state), so read requests never pay the cost of a token lookup.
1028
1029
  */
1029
- const CSRF_PROTECTED_METHODS = new Set([
1030
+ const CSRF_PROTECTED_METHODS = /* @__PURE__ */ new Set([
1030
1031
  "POST",
1031
1032
  "PUT",
1032
1033
  "PATCH",
@@ -1231,7 +1232,8 @@ function createCoreHttpClient(config) {
1231
1232
  }
1232
1233
  //#endregion
1233
1234
  //#region packages/core/http/CoreHttpContext.tsx
1234
- const CoreHttpContext = (0, react.createContext)(createCoreHttpClient());
1235
+ const defaultHttpClient = createCoreHttpClient();
1236
+ const CoreHttpContext = (0, react.createContext)(defaultHttpClient);
1235
1237
  function CoreHttpProvider({ children, client, config }) {
1236
1238
  const value = (0, react.useMemo)(() => {
1237
1239
  if (client) return client;
@@ -1249,6 +1251,33 @@ function useCoreHttpClient() {
1249
1251
  return (0, react.useContext)(CoreHttpContext);
1250
1252
  }
1251
1253
  //#endregion
1254
+ //#region packages/core/http/csrf.ts
1255
+ /** Name of the cookie the Nubit backend sets for the double-submit CSRF policy. */
1256
+ const CSRF_COOKIE_NAME = "CSRF_TOKEN";
1257
+ /**
1258
+ * Reads the double-submit CSRF token from `document.cookie`.
1259
+ *
1260
+ * The backend sets the cookie readable by JavaScript on purpose: a cross-site
1261
+ * page can make the browser attach it but cannot read it, so it cannot echo it
1262
+ * back in the `X-CSRF-Token` header. Returns `undefined` outside a browser or
1263
+ * before login has issued the cookie.
1264
+ */
1265
+ function readCsrfToken(cookieName = CSRF_COOKIE_NAME) {
1266
+ if (typeof document === "undefined") return void 0;
1267
+ for (const part of document.cookie.split(";")) {
1268
+ const separator = part.indexOf("=");
1269
+ if (separator === -1) continue;
1270
+ if (part.slice(0, separator).trim() !== cookieName) continue;
1271
+ const value = part.slice(separator + 1).trim();
1272
+ if (value === "") return void 0;
1273
+ try {
1274
+ return decodeURIComponent(value);
1275
+ } catch {
1276
+ return value;
1277
+ }
1278
+ }
1279
+ }
1280
+ //#endregion
1252
1281
  //#region packages/core/runtime/CoreRuntimeContext.tsx
1253
1282
  const defaultRuntime = {
1254
1283
  notify: () => void 0,
@@ -1309,7 +1338,8 @@ var StaticFeatureFlagClient = class {
1309
1338
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : defaultValue;
1310
1339
  }
1311
1340
  };
1312
- const FeatureFlagsContext = (0, react.createContext)(new StaticFeatureFlagClient());
1341
+ const defaultClient = new StaticFeatureFlagClient();
1342
+ const FeatureFlagsContext = (0, react.createContext)(defaultClient);
1313
1343
  function FeatureFlagsProvider({ children, client, flags = {}, context = {} }) {
1314
1344
  const value = (0, react.useMemo)(() => client ?? new StaticFeatureFlagClient(flags, context), [
1315
1345
  client,
@@ -1437,8 +1467,8 @@ function resolveMercureTopicOrigin(apiBaseUrl = getCoreApiBaseUrl(), configuredO
1437
1467
  return "";
1438
1468
  }
1439
1469
  /**
1440
- * Wildcard collection topic (RFC 6570 URI Template) for a resource API path.
1441
- * e.g. `/api/products` → `http://localhost:8000/api/products/{id}`
1470
+ * Wildcard collection topic (WHATWG URL Pattern) for a resource API path.
1471
+ * e.g. `/api/products` → `http://localhost:8000/api/products/*`
1442
1472
  */
1443
1473
  function buildMercureCollectionTopic(apiUrl, configuredOrigin, apiBaseUrl = getCoreApiBaseUrl()) {
1444
1474
  if (!apiUrl) return null;
@@ -1447,8 +1477,8 @@ function buildMercureCollectionTopic(apiUrl, configuredOrigin, apiBaseUrl = getC
1447
1477
  const normalizedPath = apiUrl.replace(/^\//, "").replace(/\/+$/, "");
1448
1478
  if (!normalizedPath) return null;
1449
1479
  const tenantId = getMercureTenantId();
1450
- if (tenantId !== void 0 && tenantId !== null && `${tenantId}` !== "") return `${origin}/api/tenants/${tenantId}/${normalizedPath.replace(/^api\//, "")}/{id}`;
1451
- return `${origin}/${normalizedPath}/{id}`;
1480
+ if (tenantId !== void 0 && tenantId !== null && `${tenantId}` !== "") return `${origin}/api/tenants/${tenantId}/${normalizedPath.replace(/^api\//, "")}/*`;
1481
+ return `${origin}/${normalizedPath}/*`;
1452
1482
  }
1453
1483
  //#endregion
1454
1484
  //#region packages/core/mercure/useDiscoveredMercureTopicOrigin.ts
@@ -1516,6 +1546,7 @@ function useMercureSubscription(apiUrl, onUpdate, enabled = true) {
1516
1546
  ]);
1517
1547
  }
1518
1548
  //#endregion
1549
+ exports.CSRF_COOKIE_NAME = CSRF_COOKIE_NAME;
1519
1550
  exports.CoreConfigProvider = CoreConfigProvider;
1520
1551
  exports.CoreHttpClient = CoreHttpClient;
1521
1552
  exports.CoreHttpProvider = CoreHttpProvider;
@@ -1556,6 +1587,7 @@ exports.isMoneyValue = isMoneyValue;
1556
1587
  exports.parseLinkHeader = parseLinkHeader;
1557
1588
  exports.parseMoney = parseMoney;
1558
1589
  exports.parseMoneyInput = parseMoneyInput;
1590
+ exports.readCsrfToken = readCsrfToken;
1559
1591
  exports.resolveMercureTopicOrigin = resolveMercureTopicOrigin;
1560
1592
  exports.sumMoney = sumMoney;
1561
1593
  exports.toMinorUnits = toMinorUnits;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import React, { ReactNode } from "react";
2
-
3
2
  //#region packages/core/data/DataRecord.d.ts
4
3
  type DataRecord = Record<string, unknown>;
5
4
  //#endregion
@@ -163,15 +162,7 @@ interface CoreConfigProviderProps {
163
162
  mercureTenantId?: number | string;
164
163
  children: React.ReactNode;
165
164
  }
166
- declare const CoreConfigProvider: ({
167
- locale,
168
- timezone,
169
- apiBaseUrl,
170
- currency,
171
- mercureTopicOrigin,
172
- mercureTenantId,
173
- children
174
- }: CoreConfigProviderProps) => React.JSX.Element;
165
+ declare const CoreConfigProvider: ({ locale, timezone, apiBaseUrl, currency, mercureTopicOrigin, mercureTenantId, children }: CoreConfigProviderProps) => React.JSX.Element;
175
166
  declare function useCoreConfig(): CoreConfig;
176
167
  //#endregion
177
168
  //#region packages/core/event/EventHook.d.ts
@@ -643,11 +634,7 @@ interface CoreHttpProviderProps {
643
634
  client?: CoreHttpClient;
644
635
  config?: CoreHttpClientConfig;
645
636
  }
646
- declare function CoreHttpProvider({
647
- children,
648
- client,
649
- config
650
- }: CoreHttpProviderProps): React.JSX.Element;
637
+ declare function CoreHttpProvider({ children, client, config }: CoreHttpProviderProps): React.JSX.Element;
651
638
  declare function useCoreHttpClient(): CoreHttpClient;
652
639
  //#endregion
653
640
  //#region packages/core/http/correlationId.d.ts
@@ -667,6 +654,19 @@ declare function useCoreHttpClient(): CoreHttpClient;
667
654
  */
668
655
  declare function generateCorrelationId(): string;
669
656
  //#endregion
657
+ //#region packages/core/http/csrf.d.ts
658
+ /** Name of the cookie the Nubit backend sets for the double-submit CSRF policy. */
659
+ declare const CSRF_COOKIE_NAME = "CSRF_TOKEN";
660
+ /**
661
+ * Reads the double-submit CSRF token from `document.cookie`.
662
+ *
663
+ * The backend sets the cookie readable by JavaScript on purpose: a cross-site
664
+ * page can make the browser attach it but cannot read it, so it cannot echo it
665
+ * back in the `X-CSRF-Token` header. Returns `undefined` outside a browser or
666
+ * before login has issued the cookie.
667
+ */
668
+ declare function readCsrfToken(cookieName?: string): string | undefined;
669
+ //#endregion
670
670
  //#region packages/core/runtime/CoreRuntimeContext.d.ts
671
671
  type CoreNotificationType = 'success' | 'error' | 'warning' | 'info';
672
672
  interface CoreRuntime {
@@ -677,10 +677,7 @@ interface CoreRuntimeProviderProps {
677
677
  children: React.ReactNode;
678
678
  runtime?: Partial<CoreRuntime>;
679
679
  }
680
- declare function CoreRuntimeProvider({
681
- children,
682
- runtime
683
- }: CoreRuntimeProviderProps): React.JSX.Element;
680
+ declare function CoreRuntimeProvider({ children, runtime }: CoreRuntimeProviderProps): React.JSX.Element;
684
681
  declare function useCoreRuntime(): CoreRuntime;
685
682
  //#endregion
686
683
  //#region packages/core/provider/CoreProvider.d.ts
@@ -690,12 +687,7 @@ interface CoreProviderProps {
690
687
  httpClient?: CoreHttpClient;
691
688
  runtime?: Partial<CoreRuntime>;
692
689
  }
693
- declare function CoreProvider({
694
- children,
695
- http,
696
- httpClient,
697
- runtime
698
- }: CoreProviderProps): React.JSX.Element;
690
+ declare function CoreProvider({ children, http, httpClient, runtime }: CoreProviderProps): React.JSX.Element;
699
691
  //#endregion
700
692
  //#region packages/core/featureFlags/FeatureFlags.d.ts
701
693
  interface FeatureFlagEvaluationContext {
@@ -726,12 +718,7 @@ interface FeatureFlagsProviderProps {
726
718
  flags?: FeatureFlagValues;
727
719
  context?: FeatureFlagEvaluationContext;
728
720
  }
729
- declare function FeatureFlagsProvider({
730
- children,
731
- client,
732
- flags,
733
- context
734
- }: FeatureFlagsProviderProps): React.JSX.Element;
721
+ declare function FeatureFlagsProvider({ children, client, flags, context }: FeatureFlagsProviderProps): React.JSX.Element;
735
722
  declare function useFeatureFlags(): FeatureFlagClient;
736
723
  declare function useBooleanFlag(key: string, defaultValue?: boolean): boolean;
737
724
  declare function useStringFlag(key: string, defaultValue?: string): string;
@@ -751,10 +738,7 @@ interface MercureProviderProps {
751
738
  * Provides the Mercure hub URL to the React tree and keeps `MercureManager`
752
739
  * in sync whenever the URL changes.
753
740
  */
754
- declare function MercureProvider({
755
- hubUrl: hubUrlOverride,
756
- children
757
- }: MercureProviderProps): React.JSX.Element;
741
+ declare function MercureProvider({ hubUrl: hubUrlOverride, children }: MercureProviderProps): React.JSX.Element;
758
742
  //#endregion
759
743
  //#region packages/core/mercure/useMercureHub.d.ts
760
744
  /**
@@ -825,8 +809,8 @@ declare function useMercureSubscription(apiUrl: string | undefined, onUpdate: ()
825
809
  */
826
810
  declare function resolveMercureTopicOrigin(apiBaseUrl?: string, configuredOrigin?: string, discoveredOrigin?: string | undefined): string;
827
811
  /**
828
- * Wildcard collection topic (RFC 6570 URI Template) for a resource API path.
829
- * e.g. `/api/products` → `http://localhost:8000/api/products/{id}`
812
+ * Wildcard collection topic (WHATWG URL Pattern) for a resource API path.
813
+ * e.g. `/api/products` → `http://localhost:8000/api/products/*`
830
814
  */
831
815
  declare function buildMercureCollectionTopic(apiUrl: string, configuredOrigin?: string, apiBaseUrl?: string): string | null;
832
816
  //#endregion
@@ -872,8 +856,9 @@ declare function useDiscoveredMercureTopicOrigin(): string | undefined;
872
856
  * Inspired by the `manager.ts` pattern from `api-platform/admin`, adapted for this project:
873
857
  * - Ref-counting per topic: multiple subscribers to the same topic share one EventSource.
874
858
  * - Graceful degradation: if hubUrl is null, subscribe() is a no-op.
875
- * - Topic format: full URI or URI Template (RFC 6570), e.g. `https://host/api/products/{id}`.
876
- * The hub receives it as a query param: `?topic=<encoded-topic>`.
859
+ * - Topic format: a WHATWG URL Pattern, e.g. `https://host/api/products/*`.
860
+ * The hub receives it as a query param: `?match_urlpattern=<encoded-pattern>`
861
+ * (Mercure.rocks v1+ — the old `?topic=` RFC 6570 URI Template scheme is gone).
877
862
  */
878
863
  declare class MercureManager {
879
864
  private hubUrl;
@@ -903,7 +888,7 @@ declare class MercureManager {
903
888
  /**
904
889
  * Subscribe to a Mercure topic.
905
890
  *
906
- * @param topic Full topic URI or URI Template, e.g. `https://host/api/products/{id}`.
891
+ * @param topic A WHATWG URL Pattern, e.g. `https://host/api/products/*`.
907
892
  * @param callback Called with the parsed JSON payload on each SSE message.
908
893
  *
909
894
  * If `hubUrl` is null (hub not configured), this is a no-op (graceful degradation).
@@ -928,4 +913,4 @@ declare class MercureManager {
928
913
  /** Singleton instance — shared across the entire application. */
929
914
  declare const mercureManager: MercureManager;
930
915
  //#endregion
931
- 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_CORRELATION_ID_HEADER_NAME, DEFAULT_CSRF_HEADER_NAME, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FeatureFlagClient, type FeatureFlagEvaluationContext, type FeatureFlagValues, FeatureFlagsProvider, type FeatureFlagsProviderProps, type FormEventNames, type FormatMoneyOptions, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type MoneyValue, type ScopedFormEventNames, StaticFeatureFlagClient, type ToolbarButtonItem, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, formatMinorUnits, formatMoney, fromMinorUnits, generateCorrelationId, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, isMoneyValue, parseLinkHeader, parseMoney, parseMoneyInput, resolveMercureTopicOrigin, sumMoney, toMinorUnits, useBooleanFlag, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useFeatureFlags, useMercureHub, useMercureSubscription, useNumberFlag, useObjectFlag, useStringFlag };
916
+ export { CSRF_COOKIE_NAME, 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_CORRELATION_ID_HEADER_NAME, DEFAULT_CSRF_HEADER_NAME, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FeatureFlagClient, type FeatureFlagEvaluationContext, type FeatureFlagValues, FeatureFlagsProvider, type FeatureFlagsProviderProps, type FormEventNames, type FormatMoneyOptions, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type MoneyValue, type ScopedFormEventNames, StaticFeatureFlagClient, type ToolbarButtonItem, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, formatMinorUnits, formatMoney, fromMinorUnits, generateCorrelationId, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, isMoneyValue, parseLinkHeader, parseMoney, parseMoneyInput, readCsrfToken, resolveMercureTopicOrigin, sumMoney, toMinorUnits, useBooleanFlag, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useFeatureFlags, useMercureHub, useMercureSubscription, useNumberFlag, useObjectFlag, useStringFlag };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import React, { ReactNode } from "react";
2
-
3
2
  //#region packages/core/data/DataRecord.d.ts
4
3
  type DataRecord = Record<string, unknown>;
5
4
  //#endregion
@@ -163,15 +162,7 @@ interface CoreConfigProviderProps {
163
162
  mercureTenantId?: number | string;
164
163
  children: React.ReactNode;
165
164
  }
166
- declare const CoreConfigProvider: ({
167
- locale,
168
- timezone,
169
- apiBaseUrl,
170
- currency,
171
- mercureTopicOrigin,
172
- mercureTenantId,
173
- children
174
- }: CoreConfigProviderProps) => React.JSX.Element;
165
+ declare const CoreConfigProvider: ({ locale, timezone, apiBaseUrl, currency, mercureTopicOrigin, mercureTenantId, children }: CoreConfigProviderProps) => React.JSX.Element;
175
166
  declare function useCoreConfig(): CoreConfig;
176
167
  //#endregion
177
168
  //#region packages/core/event/EventHook.d.ts
@@ -643,11 +634,7 @@ interface CoreHttpProviderProps {
643
634
  client?: CoreHttpClient;
644
635
  config?: CoreHttpClientConfig;
645
636
  }
646
- declare function CoreHttpProvider({
647
- children,
648
- client,
649
- config
650
- }: CoreHttpProviderProps): React.JSX.Element;
637
+ declare function CoreHttpProvider({ children, client, config }: CoreHttpProviderProps): React.JSX.Element;
651
638
  declare function useCoreHttpClient(): CoreHttpClient;
652
639
  //#endregion
653
640
  //#region packages/core/http/correlationId.d.ts
@@ -667,6 +654,19 @@ declare function useCoreHttpClient(): CoreHttpClient;
667
654
  */
668
655
  declare function generateCorrelationId(): string;
669
656
  //#endregion
657
+ //#region packages/core/http/csrf.d.ts
658
+ /** Name of the cookie the Nubit backend sets for the double-submit CSRF policy. */
659
+ declare const CSRF_COOKIE_NAME = "CSRF_TOKEN";
660
+ /**
661
+ * Reads the double-submit CSRF token from `document.cookie`.
662
+ *
663
+ * The backend sets the cookie readable by JavaScript on purpose: a cross-site
664
+ * page can make the browser attach it but cannot read it, so it cannot echo it
665
+ * back in the `X-CSRF-Token` header. Returns `undefined` outside a browser or
666
+ * before login has issued the cookie.
667
+ */
668
+ declare function readCsrfToken(cookieName?: string): string | undefined;
669
+ //#endregion
670
670
  //#region packages/core/runtime/CoreRuntimeContext.d.ts
671
671
  type CoreNotificationType = 'success' | 'error' | 'warning' | 'info';
672
672
  interface CoreRuntime {
@@ -677,10 +677,7 @@ interface CoreRuntimeProviderProps {
677
677
  children: React.ReactNode;
678
678
  runtime?: Partial<CoreRuntime>;
679
679
  }
680
- declare function CoreRuntimeProvider({
681
- children,
682
- runtime
683
- }: CoreRuntimeProviderProps): React.JSX.Element;
680
+ declare function CoreRuntimeProvider({ children, runtime }: CoreRuntimeProviderProps): React.JSX.Element;
684
681
  declare function useCoreRuntime(): CoreRuntime;
685
682
  //#endregion
686
683
  //#region packages/core/provider/CoreProvider.d.ts
@@ -690,12 +687,7 @@ interface CoreProviderProps {
690
687
  httpClient?: CoreHttpClient;
691
688
  runtime?: Partial<CoreRuntime>;
692
689
  }
693
- declare function CoreProvider({
694
- children,
695
- http,
696
- httpClient,
697
- runtime
698
- }: CoreProviderProps): React.JSX.Element;
690
+ declare function CoreProvider({ children, http, httpClient, runtime }: CoreProviderProps): React.JSX.Element;
699
691
  //#endregion
700
692
  //#region packages/core/featureFlags/FeatureFlags.d.ts
701
693
  interface FeatureFlagEvaluationContext {
@@ -726,12 +718,7 @@ interface FeatureFlagsProviderProps {
726
718
  flags?: FeatureFlagValues;
727
719
  context?: FeatureFlagEvaluationContext;
728
720
  }
729
- declare function FeatureFlagsProvider({
730
- children,
731
- client,
732
- flags,
733
- context
734
- }: FeatureFlagsProviderProps): React.JSX.Element;
721
+ declare function FeatureFlagsProvider({ children, client, flags, context }: FeatureFlagsProviderProps): React.JSX.Element;
735
722
  declare function useFeatureFlags(): FeatureFlagClient;
736
723
  declare function useBooleanFlag(key: string, defaultValue?: boolean): boolean;
737
724
  declare function useStringFlag(key: string, defaultValue?: string): string;
@@ -751,10 +738,7 @@ interface MercureProviderProps {
751
738
  * Provides the Mercure hub URL to the React tree and keeps `MercureManager`
752
739
  * in sync whenever the URL changes.
753
740
  */
754
- declare function MercureProvider({
755
- hubUrl: hubUrlOverride,
756
- children
757
- }: MercureProviderProps): React.JSX.Element;
741
+ declare function MercureProvider({ hubUrl: hubUrlOverride, children }: MercureProviderProps): React.JSX.Element;
758
742
  //#endregion
759
743
  //#region packages/core/mercure/useMercureHub.d.ts
760
744
  /**
@@ -825,8 +809,8 @@ declare function useMercureSubscription(apiUrl: string | undefined, onUpdate: ()
825
809
  */
826
810
  declare function resolveMercureTopicOrigin(apiBaseUrl?: string, configuredOrigin?: string, discoveredOrigin?: string | undefined): string;
827
811
  /**
828
- * Wildcard collection topic (RFC 6570 URI Template) for a resource API path.
829
- * e.g. `/api/products` → `http://localhost:8000/api/products/{id}`
812
+ * Wildcard collection topic (WHATWG URL Pattern) for a resource API path.
813
+ * e.g. `/api/products` → `http://localhost:8000/api/products/*`
830
814
  */
831
815
  declare function buildMercureCollectionTopic(apiUrl: string, configuredOrigin?: string, apiBaseUrl?: string): string | null;
832
816
  //#endregion
@@ -872,8 +856,9 @@ declare function useDiscoveredMercureTopicOrigin(): string | undefined;
872
856
  * Inspired by the `manager.ts` pattern from `api-platform/admin`, adapted for this project:
873
857
  * - Ref-counting per topic: multiple subscribers to the same topic share one EventSource.
874
858
  * - Graceful degradation: if hubUrl is null, subscribe() is a no-op.
875
- * - Topic format: full URI or URI Template (RFC 6570), e.g. `https://host/api/products/{id}`.
876
- * The hub receives it as a query param: `?topic=<encoded-topic>`.
859
+ * - Topic format: a WHATWG URL Pattern, e.g. `https://host/api/products/*`.
860
+ * The hub receives it as a query param: `?match_urlpattern=<encoded-pattern>`
861
+ * (Mercure.rocks v1+ — the old `?topic=` RFC 6570 URI Template scheme is gone).
877
862
  */
878
863
  declare class MercureManager {
879
864
  private hubUrl;
@@ -903,7 +888,7 @@ declare class MercureManager {
903
888
  /**
904
889
  * Subscribe to a Mercure topic.
905
890
  *
906
- * @param topic Full topic URI or URI Template, e.g. `https://host/api/products/{id}`.
891
+ * @param topic A WHATWG URL Pattern, e.g. `https://host/api/products/*`.
907
892
  * @param callback Called with the parsed JSON payload on each SSE message.
908
893
  *
909
894
  * If `hubUrl` is null (hub not configured), this is a no-op (graceful degradation).
@@ -928,4 +913,4 @@ declare class MercureManager {
928
913
  /** Singleton instance — shared across the entire application. */
929
914
  declare const mercureManager: MercureManager;
930
915
  //#endregion
931
- 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_CORRELATION_ID_HEADER_NAME, DEFAULT_CSRF_HEADER_NAME, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FeatureFlagClient, type FeatureFlagEvaluationContext, type FeatureFlagValues, FeatureFlagsProvider, type FeatureFlagsProviderProps, type FormEventNames, type FormatMoneyOptions, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type MoneyValue, type ScopedFormEventNames, StaticFeatureFlagClient, type ToolbarButtonItem, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, formatMinorUnits, formatMoney, fromMinorUnits, generateCorrelationId, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, isMoneyValue, parseLinkHeader, parseMoney, parseMoneyInput, resolveMercureTopicOrigin, sumMoney, toMinorUnits, useBooleanFlag, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useFeatureFlags, useMercureHub, useMercureSubscription, useNumberFlag, useObjectFlag, useStringFlag };
916
+ export { CSRF_COOKIE_NAME, 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_CORRELATION_ID_HEADER_NAME, DEFAULT_CSRF_HEADER_NAME, DEFAULT_TIMEZONE, type DataGridEventNames, type DataRecord, DateUtils, type DialogEventNames, type EventSubscription, type FeatureFlagClient, type FeatureFlagEvaluationContext, type FeatureFlagValues, FeatureFlagsProvider, type FeatureFlagsProviderProps, type FormEventNames, type FormatMoneyOptions, type GridData, mercureManager as MercureManager, type MercureManager as MercureManagerType, MercureProvider, type MercureProviderProps, type MoneyValue, type ScopedFormEventNames, StaticFeatureFlagClient, type ToolbarButtonItem, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, formatMinorUnits, formatMoney, fromMinorUnits, generateCorrelationId, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, isMoneyValue, parseLinkHeader, parseMoney, parseMoneyInput, readCsrfToken, resolveMercureTopicOrigin, sumMoney, toMinorUnits, useBooleanFlag, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useFeatureFlags, useMercureHub, useMercureSubscription, useNumberFlag, useObjectFlag, useStringFlag };
package/dist/index.mjs CHANGED
@@ -144,7 +144,7 @@ var DateUtils = class {
144
144
  const dateStart = new Date(startDate);
145
145
  const dateEnd = new Date(endDate);
146
146
  const timeDiff = Math.abs(dateEnd.getTime() - dateStart.getTime());
147
- return Math.ceil(timeDiff / (1e3 * 3600 * 24));
147
+ return Math.ceil(timeDiff / 864e5);
148
148
  }
149
149
  static monthDiff(startDate, endDate) {
150
150
  const dateStart = new Date(startDate);
@@ -386,8 +386,9 @@ const createCrudEvents = (prefix) => ({
386
386
  */
387
387
  function createScopedEventBus(resourceId) {
388
388
  const scopeId = Math.random().toString(36).slice(2, 10);
389
+ const prefix = `${resourceId}:${scopeId}`;
389
390
  return {
390
- ...createCrudEvents(`${resourceId}:${scopeId}`),
391
+ ...createCrudEvents(prefix),
391
392
  _scopeId: scopeId
392
393
  };
393
394
  }
@@ -787,7 +788,7 @@ var MercureManager = class {
787
788
  /**
788
789
  * Subscribe to a Mercure topic.
789
790
  *
790
- * @param topic Full topic URI or URI Template, e.g. `https://host/api/products/{id}`.
791
+ * @param topic A WHATWG URL Pattern, e.g. `https://host/api/products/*`.
791
792
  * @param callback Called with the parsed JSON payload on each SSE message.
792
793
  *
793
794
  * If `hubUrl` is null (hub not configured), this is a no-op (graceful degradation).
@@ -810,7 +811,7 @@ var MercureManager = class {
810
811
  return;
811
812
  }
812
813
  const url = new URL(this.hubUrl);
813
- url.searchParams.append("topic", topic);
814
+ url.searchParams.append("match_urlpattern", topic);
814
815
  const eventSource = new EventSource(url.toString(), { withCredentials: true });
815
816
  const listener = (e) => {
816
817
  try {
@@ -1001,7 +1002,7 @@ const DEFAULT_CORRELATION_ID_HEADER_NAME = "X-Request-Id";
1001
1002
  * "safe methods don't need CSRF protection" rule (GET/HEAD never mutate
1002
1003
  * state), so read requests never pay the cost of a token lookup.
1003
1004
  */
1004
- const CSRF_PROTECTED_METHODS = new Set([
1005
+ const CSRF_PROTECTED_METHODS = /* @__PURE__ */ new Set([
1005
1006
  "POST",
1006
1007
  "PUT",
1007
1008
  "PATCH",
@@ -1206,7 +1207,8 @@ function createCoreHttpClient(config) {
1206
1207
  }
1207
1208
  //#endregion
1208
1209
  //#region packages/core/http/CoreHttpContext.tsx
1209
- const CoreHttpContext = createContext(createCoreHttpClient());
1210
+ const defaultHttpClient = createCoreHttpClient();
1211
+ const CoreHttpContext = createContext(defaultHttpClient);
1210
1212
  function CoreHttpProvider({ children, client, config }) {
1211
1213
  const value = useMemo(() => {
1212
1214
  if (client) return client;
@@ -1224,6 +1226,33 @@ function useCoreHttpClient() {
1224
1226
  return useContext(CoreHttpContext);
1225
1227
  }
1226
1228
  //#endregion
1229
+ //#region packages/core/http/csrf.ts
1230
+ /** Name of the cookie the Nubit backend sets for the double-submit CSRF policy. */
1231
+ const CSRF_COOKIE_NAME = "CSRF_TOKEN";
1232
+ /**
1233
+ * Reads the double-submit CSRF token from `document.cookie`.
1234
+ *
1235
+ * The backend sets the cookie readable by JavaScript on purpose: a cross-site
1236
+ * page can make the browser attach it but cannot read it, so it cannot echo it
1237
+ * back in the `X-CSRF-Token` header. Returns `undefined` outside a browser or
1238
+ * before login has issued the cookie.
1239
+ */
1240
+ function readCsrfToken(cookieName = CSRF_COOKIE_NAME) {
1241
+ if (typeof document === "undefined") return void 0;
1242
+ for (const part of document.cookie.split(";")) {
1243
+ const separator = part.indexOf("=");
1244
+ if (separator === -1) continue;
1245
+ if (part.slice(0, separator).trim() !== cookieName) continue;
1246
+ const value = part.slice(separator + 1).trim();
1247
+ if (value === "") return void 0;
1248
+ try {
1249
+ return decodeURIComponent(value);
1250
+ } catch {
1251
+ return value;
1252
+ }
1253
+ }
1254
+ }
1255
+ //#endregion
1227
1256
  //#region packages/core/runtime/CoreRuntimeContext.tsx
1228
1257
  const defaultRuntime = {
1229
1258
  notify: () => void 0,
@@ -1284,7 +1313,8 @@ var StaticFeatureFlagClient = class {
1284
1313
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : defaultValue;
1285
1314
  }
1286
1315
  };
1287
- const FeatureFlagsContext = createContext(new StaticFeatureFlagClient());
1316
+ const defaultClient = new StaticFeatureFlagClient();
1317
+ const FeatureFlagsContext = createContext(defaultClient);
1288
1318
  function FeatureFlagsProvider({ children, client, flags = {}, context = {} }) {
1289
1319
  const value = useMemo(() => client ?? new StaticFeatureFlagClient(flags, context), [
1290
1320
  client,
@@ -1412,8 +1442,8 @@ function resolveMercureTopicOrigin(apiBaseUrl = getCoreApiBaseUrl(), configuredO
1412
1442
  return "";
1413
1443
  }
1414
1444
  /**
1415
- * Wildcard collection topic (RFC 6570 URI Template) for a resource API path.
1416
- * e.g. `/api/products` → `http://localhost:8000/api/products/{id}`
1445
+ * Wildcard collection topic (WHATWG URL Pattern) for a resource API path.
1446
+ * e.g. `/api/products` → `http://localhost:8000/api/products/*`
1417
1447
  */
1418
1448
  function buildMercureCollectionTopic(apiUrl, configuredOrigin, apiBaseUrl = getCoreApiBaseUrl()) {
1419
1449
  if (!apiUrl) return null;
@@ -1422,8 +1452,8 @@ function buildMercureCollectionTopic(apiUrl, configuredOrigin, apiBaseUrl = getC
1422
1452
  const normalizedPath = apiUrl.replace(/^\//, "").replace(/\/+$/, "");
1423
1453
  if (!normalizedPath) return null;
1424
1454
  const tenantId = getMercureTenantId();
1425
- if (tenantId !== void 0 && tenantId !== null && `${tenantId}` !== "") return `${origin}/api/tenants/${tenantId}/${normalizedPath.replace(/^api\//, "")}/{id}`;
1426
- return `${origin}/${normalizedPath}/{id}`;
1455
+ if (tenantId !== void 0 && tenantId !== null && `${tenantId}` !== "") return `${origin}/api/tenants/${tenantId}/${normalizedPath.replace(/^api\//, "")}/*`;
1456
+ return `${origin}/${normalizedPath}/*`;
1427
1457
  }
1428
1458
  //#endregion
1429
1459
  //#region packages/core/mercure/useDiscoveredMercureTopicOrigin.ts
@@ -1491,4 +1521,4 @@ function useMercureSubscription(apiUrl, onUpdate, enabled = true) {
1491
1521
  ]);
1492
1522
  }
1493
1523
  //#endregion
1494
- export { CoreConfigProvider, CoreHttpClient, CoreHttpProvider, CoreProvider, CoreRuntimeProvider, DEFAULT_CORRELATION_ID_HEADER_NAME, DEFAULT_CSRF_HEADER_NAME, DEFAULT_TIMEZONE, DateUtils, FeatureFlagsProvider, mercureManager as MercureManager, MercureProvider, StaticFeatureFlagClient, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, formatMinorUnits, formatMoney, fromMinorUnits, generateCorrelationId, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, isMoneyValue, parseLinkHeader, parseMoney, parseMoneyInput, resolveMercureTopicOrigin, sumMoney, toMinorUnits, useBooleanFlag, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useFeatureFlags, useMercureHub, useMercureSubscription, useNumberFlag, useObjectFlag, useStringFlag };
1524
+ export { CSRF_COOKIE_NAME, CoreConfigProvider, CoreHttpClient, CoreHttpProvider, CoreProvider, CoreRuntimeProvider, DEFAULT_CORRELATION_ID_HEADER_NAME, DEFAULT_CSRF_HEADER_NAME, DEFAULT_TIMEZONE, DateUtils, FeatureFlagsProvider, mercureManager as MercureManager, MercureProvider, StaticFeatureFlagClient, buildMercureCollectionTopic, configureCore, configureCoreDate, coreTranslationsEn, coreTranslationsEs, createCoreHttpClient, createCrudEvents, createScopedEventBus, discoverMercureFromResponse, dispatch, extractMercureHubUrl, extractTopicOriginFromPayload, formatMinorUnits, formatMoney, fromMinorUnits, generateCorrelationId, getCoreApiBaseUrl, getCoreCurrency, getCoreLocale, getCoreTimezone, getDiscoveredMercureTopicOrigin, getMercureTopicOrigin, initCoreI18n, isMoneyValue, parseLinkHeader, parseMoney, parseMoneyInput, readCsrfToken, resolveMercureTopicOrigin, sumMoney, toMinorUnits, useBooleanFlag, useCoreConfig, useCoreHttpClient, useCoreRuntime, useCoreTranslation, useDiscoveredMercureTopicOrigin, useEvents, useFeatureFlags, useMercureHub, useMercureSubscription, useNumberFlag, useObjectFlag, useStringFlag };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubitio/core",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "description": "Runtime foundation for Nubit: HTTP, events, i18n, Mercure, feature flags, providers, and date utilities.",
6
6
  "license": "MIT",