@trackunit/react-core-contexts 2.7.12 → 2.7.13
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/index.cjs.js +15 -7
- package/index.esm.js +16 -8
- package/migrations/entry.js.map +1 -0
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -422,23 +422,31 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
422
422
|
};
|
|
423
423
|
};
|
|
424
424
|
|
|
425
|
+
// `location.hostname` carries no port, serializes IPv6 loopback with brackets, and can be
|
|
426
|
+
// `0.0.0.0` when the Iris App dev server is started with `--host`. Mirrors the host-side check
|
|
427
|
+
// in iris-app-sdk/components IrisAppIframe.tsx.
|
|
428
|
+
const LOOPBACK_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]", "0.0.0.0"];
|
|
425
429
|
const useApolloClient = () => {
|
|
426
430
|
const { graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, environment, tracingHeaders } = reactCoreHooks.useEnvironment();
|
|
427
431
|
const { token: currentToken } = reactCoreHooks.useToken();
|
|
428
432
|
const errorHandler = reactCoreHooks.useErrorHandler();
|
|
429
433
|
const { addToast } = reactCoreHooks.useToast();
|
|
430
|
-
const { permissions } = reactCoreHooks.useCurrentUser();
|
|
431
434
|
const showErrorToast = react.useCallback((error) => {
|
|
432
435
|
// Only a developer running an Iris App locally can act on a missing scope, since only
|
|
433
436
|
// they can edit the manifest. The server throws the same message for real customer
|
|
434
437
|
// sessions and for token clients that have no manifest at all, so surfacing it outside
|
|
435
438
|
// local mode tells users to fix something they cannot reach.
|
|
436
439
|
//
|
|
437
|
-
//
|
|
438
|
-
//
|
|
439
|
-
//
|
|
440
|
-
|
|
441
|
-
|
|
440
|
+
// Every Iris App mounts this provider inside its own iframe via TrackunitProviders, so a
|
|
441
|
+
// loopback hostname means *this app* is being served by a local dev server — precisely the
|
|
442
|
+
// person who owns the manifest. useIrisAppsSDK().developerMode cannot be used instead:
|
|
443
|
+
// useDeveloperMode lives in core-contexts-host (visibility:host) and this library is
|
|
444
|
+
// visibility:shared, so nx blocks the import.
|
|
445
|
+
//
|
|
446
|
+
// Read inside the callback rather than at module scope so nothing touches `window` at
|
|
447
|
+
// import time and tests can stub the hostname per case.
|
|
448
|
+
const isServedLocally = LOOPBACK_HOSTNAMES.includes(window.location.hostname);
|
|
449
|
+
if (!isServedLocally) {
|
|
442
450
|
return;
|
|
443
451
|
}
|
|
444
452
|
void addToast({
|
|
@@ -453,7 +461,7 @@ const useApolloClient = () => {
|
|
|
453
461
|
behavior: "persistent",
|
|
454
462
|
description: `${error.message} - you must add the scope to your iris app manifest`,
|
|
455
463
|
});
|
|
456
|
-
}, [addToast
|
|
464
|
+
}, [addToast]);
|
|
457
465
|
const [client] = react.useState(() => {
|
|
458
466
|
return createApolloClient({
|
|
459
467
|
/* DON'T CHANGE THIS ! its there to ensure we don't recreate apollo client just because the token changes,
|
package/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { FeatureFlagRuntime, ToastRuntime, AnalyticsRuntime, registerHostChangeH
|
|
|
3
3
|
import { FeatureFlagContextProvider, ToastProvider, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, ExportDataContext, FilterBarProvider, GeolocationProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider, WidgetConfigProvider } from '@trackunit/react-core-contexts-api';
|
|
4
4
|
import { useState, useEffect, useCallback, useMemo, useReducer, Suspense } from 'react';
|
|
5
5
|
import { ApolloLink, Observable, createHttpLink, from, split, ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
|
|
6
|
-
import { useEnvironment, useToken, useErrorHandler, useToast
|
|
6
|
+
import { useEnvironment, useToken, useErrorHandler, useToast } from '@trackunit/react-core-hooks';
|
|
7
7
|
import { setContext } from '@apollo/client/link/context';
|
|
8
8
|
import { removeTypenameFromVariables } from '@apollo/client/link/remove-typename';
|
|
9
9
|
import { getMainDefinition, Observable as Observable$1 } from '@apollo/client/utilities';
|
|
@@ -420,23 +420,31 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
420
420
|
};
|
|
421
421
|
};
|
|
422
422
|
|
|
423
|
+
// `location.hostname` carries no port, serializes IPv6 loopback with brackets, and can be
|
|
424
|
+
// `0.0.0.0` when the Iris App dev server is started with `--host`. Mirrors the host-side check
|
|
425
|
+
// in iris-app-sdk/components IrisAppIframe.tsx.
|
|
426
|
+
const LOOPBACK_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]", "0.0.0.0"];
|
|
423
427
|
const useApolloClient = () => {
|
|
424
428
|
const { graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, environment, tracingHeaders } = useEnvironment();
|
|
425
429
|
const { token: currentToken } = useToken();
|
|
426
430
|
const errorHandler = useErrorHandler();
|
|
427
431
|
const { addToast } = useToast();
|
|
428
|
-
const { permissions } = useCurrentUser();
|
|
429
432
|
const showErrorToast = useCallback((error) => {
|
|
430
433
|
// Only a developer running an Iris App locally can act on a missing scope, since only
|
|
431
434
|
// they can edit the manifest. The server throws the same message for real customer
|
|
432
435
|
// sessions and for token clients that have no manifest at all, so surfacing it outside
|
|
433
436
|
// local mode tells users to fix something they cannot reach.
|
|
434
437
|
//
|
|
435
|
-
//
|
|
436
|
-
//
|
|
437
|
-
//
|
|
438
|
-
|
|
439
|
-
|
|
438
|
+
// Every Iris App mounts this provider inside its own iframe via TrackunitProviders, so a
|
|
439
|
+
// loopback hostname means *this app* is being served by a local dev server — precisely the
|
|
440
|
+
// person who owns the manifest. useIrisAppsSDK().developerMode cannot be used instead:
|
|
441
|
+
// useDeveloperMode lives in core-contexts-host (visibility:host) and this library is
|
|
442
|
+
// visibility:shared, so nx blocks the import.
|
|
443
|
+
//
|
|
444
|
+
// Read inside the callback rather than at module scope so nothing touches `window` at
|
|
445
|
+
// import time and tests can stub the hostname per case.
|
|
446
|
+
const isServedLocally = LOOPBACK_HOSTNAMES.includes(window.location.hostname);
|
|
447
|
+
if (!isServedLocally) {
|
|
440
448
|
return;
|
|
441
449
|
}
|
|
442
450
|
void addToast({
|
|
@@ -451,7 +459,7 @@ const useApolloClient = () => {
|
|
|
451
459
|
behavior: "persistent",
|
|
452
460
|
description: `${error.message} - you must add the scope to your iris app manifest`,
|
|
453
461
|
});
|
|
454
|
-
}, [addToast
|
|
462
|
+
}, [addToast]);
|
|
455
463
|
const [client] = useState(() => {
|
|
456
464
|
return createApolloClient({
|
|
457
465
|
/* DON'T CHANGE THIS ! its there to ensure we don't recreate apollo client just because the token changes,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/core-contexts/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
|