@nubitio/core 1.1.1 → 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 +38 -6
- package/dist/index.d.cts +20 -36
- package/dist/index.d.mts +20 -36
- package/dist/index.mjs +36 -6
- package/package.json +1 -1
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 /
|
|
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(
|
|
416
|
+
...createCrudEvents(prefix),
|
|
416
417
|
_scopeId: scopeId
|
|
417
418
|
};
|
|
418
419
|
}
|
|
@@ -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
|
|
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
|
|
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,
|
|
@@ -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
|
/**
|
|
@@ -929,4 +913,4 @@ declare class MercureManager {
|
|
|
929
913
|
/** Singleton instance — shared across the entire application. */
|
|
930
914
|
declare const mercureManager: MercureManager;
|
|
931
915
|
//#endregion
|
|
932
|
-
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
|
/**
|
|
@@ -929,4 +913,4 @@ declare class MercureManager {
|
|
|
929
913
|
/** Singleton instance — shared across the entire application. */
|
|
930
914
|
declare const mercureManager: MercureManager;
|
|
931
915
|
//#endregion
|
|
932
|
-
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 /
|
|
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(
|
|
391
|
+
...createCrudEvents(prefix),
|
|
391
392
|
_scopeId: scopeId
|
|
392
393
|
};
|
|
393
394
|
}
|
|
@@ -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
|
|
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
|
|
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,
|
|
@@ -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 };
|